Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gomatrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Jankowski
gomatrix
Commits
afad393d
Commit
afad393d
authored
6 years ago
by
Daniel Jankowski
Browse files
Options
Downloads
Patches
Plain Diff
Added: CheckGaussian for partial gaussian checks
parent
2ec25e5c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#4340
passed
6 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gaussian.go
+55
-1
55 additions, 1 deletion
gaussian.go
gaussian_test.go
+70
-0
70 additions, 0 deletions
gaussian_test.go
with
125 additions
and
1 deletion
gaussian.go
+
55
−
1
View file @
afad393d
package
gomatrix
import
(
"math/big"
)
// GaussianElimination converts the matrix to an echelon form
//
// This function applies the gaussian el
e
mination to the matrix in order to
// This function applies the gaussian el
i
mination to the matrix in order to
// create an echelon form.
func
(
f
*
F2
)
GaussianElimination
()
{
// iterate through all possible pivot bits
...
...
@@ -125,3 +129,53 @@ func (f *F2) partialDiagonalize(startRow, startCol, stopRow, stopCol int) {
}
}
}
// CheckGaussian checks if the given range in the matrix is the identity matrix
//
// @param int startRow The row where the check starts
// @param int startCol The column where the check starts
// @param int n The size of the submatrix to check
//
// @return bool
func
(
f
*
F2
)
CheckGaussian
(
startRow
,
startCol
,
n
int
)
bool
{
counter
:=
0
// iterate through the rows
for
_
,
row
:=
range
f
.
Rows
[
startRow
:
]
{
// if the counter is reached...
if
counter
==
n
{
// ...break
break
}
// create the bitmask for the row
bitmask
:=
big
.
NewInt
(
0
)
.
SetBit
(
big
.
NewInt
(
0
),
startCol
+
counter
,
1
,
)
// get the bits to check
bitsToCheck
:=
big
.
NewInt
(
0
)
.
And
(
row
,
bitmask
,
)
// xor the bits to check with the bitmask
shouldBeZero
:=
big
.
NewInt
(
0
)
.
Xor
(
bitsToCheck
,
bitmask
,
)
// if the xor'ed result is not zero...
if
shouldBeZero
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
// ...the check failed
return
false
}
// increase the counter
counter
++
}
return
true
}
This diff is collapsed.
Click to expand it.
gaussian_test.go
+
70
−
0
View file @
afad393d
...
...
@@ -90,3 +90,73 @@ func TestPartialGaussianElimination(t *testing.T) {
assert
.
True
(
t
,
test
.
matrixA
.
IsEqual
(
test
.
expectedMatrix
))
}
}
func
TestCheckGaussian
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
description
string
matrix
*
F2
startRow
int
startCol
int
n
int
expectedResult
bool
}{
{
description
:
"3x3 identity matrix"
,
matrix
:
NewF2
(
3
,
3
)
.
Set
([]
*
big
.
Int
{
big
.
NewInt
(
1
),
big
.
NewInt
(
2
),
big
.
NewInt
(
4
),
}),
startRow
:
0
,
startCol
:
0
,
n
:
3
,
expectedResult
:
true
,
},
{
description
:
"3x3 matrix"
,
matrix
:
NewF2
(
3
,
3
)
.
Set
([]
*
big
.
Int
{
big
.
NewInt
(
2
),
big
.
NewInt
(
1
),
big
.
NewInt
(
4
),
}),
startRow
:
0
,
startCol
:
0
,
n
:
3
,
expectedResult
:
false
,
},
{
description
:
"3x3 matrix with lower right identity matrix"
,
matrix
:
NewF2
(
3
,
3
)
.
Set
([]
*
big
.
Int
{
big
.
NewInt
(
2
),
big
.
NewInt
(
2
),
big
.
NewInt
(
4
),
}),
startRow
:
1
,
startCol
:
1
,
n
:
3
,
expectedResult
:
true
,
},
{
description
:
"3x3 matrix with upper left identity matrix"
,
matrix
:
NewF2
(
3
,
3
)
.
Set
([]
*
big
.
Int
{
big
.
NewInt
(
1
),
big
.
NewInt
(
2
),
big
.
NewInt
(
7
),
}),
startRow
:
0
,
startCol
:
0
,
n
:
2
,
expectedResult
:
true
,
},
}
for
_
,
test
:=
range
tests
{
result
:=
test
.
matrix
.
CheckGaussian
(
test
.
startRow
,
test
.
startCol
,
test
.
n
,
)
assert
.
Equalf
(
t
,
test
.
expectedResult
,
result
,
test
.
description
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment