Skip to content
Snippets Groups Projects
Commit a3a7aedd authored by Daniel Jankowski's avatar Daniel Jankowski
Browse files

Added: gaussian elimination

parent 0795fc6d
No related branches found
No related tags found
No related merge requests found
Pipeline #4255 passed
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
import (
......
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
// GaussianElimination converts the matrix to an echelon form
//
// This function applies the gaussian elemination to the matrix in order to
// create an echelon form.
func (f *F2) GaussianElimination() {
// iterate through all possible pivot bits
for pivotBit := 0; pivotBit < f.M; pivotBit++ {
// iterate through the rows
for rowCounter := 0; rowCounter < f.N; rowCounter++ {
// if the pivotbit of this row is 0...
if f.Rows[rowCounter].Bit(pivotBit) == uint(0) {
// ...check the next row
continue
}
// if the row with a valid pivot bit is not the first row...
if pivotBit != rowCounter {
// ...swap it with first one
f.SwapRows(pivotBit, rowCounter)
}
// iterate through all other rows except the first one
for rr := pivotBit + 1; rr < f.N; rr++ {
// substract the 1 from all other rows with the pivotBit
f.Rows[rr].Xor(f.Rows[rr], f.Rows[pivotBit])
}
}
}
}
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGaussianElimination(t *testing.T) {
tests := []struct {
description string
matrixA *F2
expectedMatrix *F2
}{
{
matrixA: NewF2(2, 2).Set([]*big.Int{big.NewInt(2), big.NewInt(1)}),
expectedMatrix: NewF2(2, 2).Set([]*big.Int{big.NewInt(1), big.NewInt(3)}),
},
}
for _, test := range tests {
test.matrixA.GaussianElimination()
assert.True(t, test.matrixA.IsEqual(test.expectedMatrix))
}
}
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
import (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment