func TestSubMatrixGob(t *testing.T) { var B, As cmat.FloatMatrix var network bytes.Buffer N := 32 A := cmat.NewMatrix(N, N) zeromean := cmat.NewFloatNormSource() A.SetFrom(zeromean) As.SubMatrix(A, 3, 3, N-6, N-6) enc := gob.NewEncoder(&network) dec := gob.NewDecoder(&network) // encode to network err := enc.Encode(&As) if err != nil { t.Logf("encode error: %v\n", err) t.FailNow() } // decode from network err = dec.Decode(&B) if err != nil { t.Logf("decode error: %v\n", err) t.FailNow() } ar, ac := As.Size() br, bc := B.Size() t.Logf("As[%d,%d] == B[%d,%d]: %v\n", ar, ac, br, bc, B.AllClose(&As)) }
func TestJSON(t *testing.T) { var B cmat.FloatMatrix var network bytes.Buffer N := 26 A := cmat.NewMatrix(N, N) zeromean := cmat.NewFloatNormSource() A.SetFrom(zeromean) enc := json.NewEncoder(&network) dec := json.NewDecoder(&network) // encode to network err := enc.Encode(A) //t.Logf("bytes: %v\n", string(network.Bytes())) if err != nil { t.Logf("encode error: %v\n", err) t.FailNow() } // decode from network err = dec.Decode(&B) if err != nil { t.Logf("decode error: %v\n", err) t.FailNow() } t.Logf("A == B: %v\n", B.AllClose(A)) }
func errorLoc(D, C *cmat.FloatMatrix) (r, c int) { var dmat, cmat cmat.FloatMatrix dr, dc := D.Size() for i := 0; i < dr; i++ { dmat.SubMatrix(D, i, 0, 1, dc) cmat.SubMatrix(C, i, 0, 1, dc) if !dmat.AllClose(&cmat) { r = i break } } for i := 0; i < dc; i++ { dmat.SubMatrix(D, 0, i, dr, 1) cmat.SubMatrix(C, 0, i, dr, 1) if !dmat.AllClose(&cmat) { c = i break } } return }
func TestSubMatrixCopy(t *testing.T) { var subA, subB cmat.FloatMatrix M := 9 N := 9 A := cmat.NewMatrix(M, N) B := cmat.NewMatrix(M, N) twos := cmat.NewFloatConstSource(2.0) B.SetFrom(twos) subA.SubMatrix(A, 1, 1, M-2, N-2) subB.SubMatrix(B, 1, 1, M-2, N-2) subA.Copy(&subB) ok := subA.AllClose(&subB) if !ok { t.Logf("copy status: %v\n", ok) if N < 9 { t.Logf("subA\n%v\n", subA) } } if N < 10 { t.Logf("A\n%v\n", A) } }