Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func ParseMatlab(txt string) (A *DenseMatrix, err error) {
}()

isNotNumber := func(c byte) bool {
return c != '[' || c != ']' || c == ';'
return c == '[' || c == ']' || c == ';'
}

if len(spaceSep) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (A *SparseMatrix) GetMatrix(i, j, rows, cols int) (subMatrix *SparseMatrix)
i = maxInt(0, i)
j = maxInt(0, j)
rows = minInt(A.rows-i, rows)
rows = minInt(A.cols-j, cols)
cols = minInt(A.cols-j, cols)
}

subMatrix = new(SparseMatrix)
Expand Down
31 changes: 20 additions & 11 deletions sparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package matrix

import (
"fmt"
"math/rand"
"testing"
)

Expand Down Expand Up @@ -64,22 +63,32 @@ func TestElementMult_Sparse(t *testing.T) {
}

func TestGetMatrix_Sparse(t *testing.T) {
A := ZerosSparse(6, 6)
for i := 0; i < 36; i++ {
x := rand.Intn(6)
y := rand.Intn(6)
A.Set(y, x, 1)
numRows := 20
numColumns := 20
A := ZerosSparse(numRows, numColumns)
for i := 0; i < numRows; i++ {
for j := 0; j < numColumns; j++ {
A.Set(i, j, float64(10*i+j))
}
}
B := A.GetMatrix(1, 1, 4, 4)
B := A.GetMatrix(0, numColumns/2, numRows/2, numColumns)

for i := 0; i < 4; i++ {
for j := 0; j < 4; j++ {
if B.Get(i, j) != A.Get(i+1, j+1) {
if B.Rows() != numRows/2 {
t.Log(fmt.Sprintf("wrong number of rows, expected %d, got %d", numRows/2, B.Rows()))
t.Fail()
}
if B.Cols() != numColumns/2 {
t.Log(fmt.Sprintf("wrong number of columns, expected %d, got %d", numColumns/2, B.Cols()))
t.Fail()
}
for i := 0; i < numRows/2; i++ {
for j := 0; j < numColumns/2; j++ {
if B.Get(i, j) != A.Get(i, j+numColumns/2) {
t.Log(fmt.Sprintf("wrong value in (%d,%d), expected %f, got %f", i, j, A.Get(i, j+numColumns/2), B.Get(i, j)))
t.Fail()
}
}
}

}

func TestAugment_Sparse(t *testing.T) {
Expand Down