From fc7a2d86b969cf0b86f6d68e8a414535ff92a2a0 Mon Sep 17 00:00:00 2001 From: Yashwant Date: Wed, 27 May 2020 20:09:43 +0530 Subject: [PATCH] Forgot this part. --- .../bindings/go/tests/go_binding_test.go | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/mlpack/bindings/go/tests/go_binding_test.go b/src/mlpack/bindings/go/tests/go_binding_test.go index c71fae94ca..f4fa1862fd 100644 --- a/src/mlpack/bindings/go/tests/go_binding_test.go +++ b/src/mlpack/bindings/go/tests/go_binding_test.go @@ -3,6 +3,7 @@ package main import ( "mlpack/bindings/go/mlpack" "testing" + "os" "gonum.org/v1/gonum/mat" ) @@ -594,3 +595,82 @@ func TestModel(t *testing.T) { t.Errorf("Error. Wrong model.") } } + +func TestLoadSaveMatrix(t *testing.T) { + t.Log("Test that the matrix should be save and load properly.") + x := mat.NewDense(3, 5, []float64{ + 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, + }) + mlpack.Save("test_matrix.csv", x) + y, _ := mlpack.Load("test_matrix.csv") + + rows, cols := y.Dims() + if rows != 3 || cols != 5 { + panic("error shape") + } + + var z mat.Dense + z.Sub(y, x) + for i := 0; i < rows; i++ { + for j := 0; j < cols; j++ { + if val := z.At(i, j); val != 0 { + t.Errorf("Error. Value at [i,j] : %v", val) + } + } + } + os.Remove("test_matrix.csv") +} + +func TestLoadSaveColumn(t *testing.T) { + t.Log("Test that the column should be save and load properly.") + x := mat.NewDense(1, 9, []float64{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, + }) + + mlpack.Save("test_column.csv", x) + y, _ := mlpack.Load("test_column.csv") + + rows, cols := y.Dims() + if rows != 1 || cols != 9 { + panic("error shape") + } + + var z mat.Dense + z.Sub(y, x) + for i := 0; i < rows; i++ { + for j := 0; j < cols; j++ { + if val := z.At(i, j); val != 0 { + t.Errorf("Error. Value at [i,j] : %v", val) + } + } + } + os.Remove("test_column.csv") +} + +func TestLoadSaveRow(t *testing.T) { + t.Log("Test that the row should be save and load properly.") + x := mat.NewDense(9, 1, []float64{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, + }) + + mlpack.Save("test_row.csv", x) + y, _ := mlpack.Load("test_row.csv") + + rows, cols := y.Dims() + if rows != 9 || cols != 1 { + panic("error shape") + } + + var z mat.Dense + z.Sub(y, x) + for i := 0; i < rows; i++ { + for j := 0; j < cols; j++ { + if val := z.At(i, j); val != 0 { + t.Errorf("Error. Value at [i,j] : %v", val) + } + } + } + os.Remove("test_row.csv") +}