diff --git a/api_matop.go b/api_matop.go index 0667ce4..4d98479 100644 --- a/api_matop.go +++ b/api_matop.go @@ -45,10 +45,9 @@ func T(t Tensor, axes ...int) (retVal Tensor, err error) { case DenseView: var ret *Dense if ret, err = tt.SafeT(axes...); err != nil { - return nil, errors.Wrap(err, ".T() off a DenseView") + return nil, errors.Wrap(err, "T() off a DenseView") } return DenseView{ret}, nil - default: return nil, nyierr(typeNYI, t) } diff --git a/example_matop_test.go b/example_matop_test.go new file mode 100644 index 0000000..4c0d4da --- /dev/null +++ b/example_matop_test.go @@ -0,0 +1,59 @@ +package tensor_test + +import ( + "fmt" + + "gorgonia.org/tensor" +) + +func ExampleTranspose() { + t := tensor.New(tensor.WithShape(2, 3), tensor.WithBacking([]int{1, 2, 3, 4, 5, 6})) + t2, err := tensor.Transpose(t) + if err != nil { + fmt.Printf("ERR: %v\n", err) + } + fmt.Printf("Transpose is a safe operation.\nT:\n%v\nT':\n%v\n", t, t2) + fmt.Printf("The data is changed:\nT : %v\nT': %v", t.Data(), t2.Data()) + + // Output: + // Transpose is a safe operation. + // T: + // ⎡1 2 3⎤ + // ⎣4 5 6⎦ + // + // T': + // ⎡1 4⎤ + // ⎢2 5⎥ + // ⎣3 6⎦ + // + // The data is changed: + // T : [1 2 3 4 5 6] + // T': [1 4 2 5 3 6] + +} + +func ExampleT() { + t := tensor.New(tensor.WithShape(2, 3), tensor.WithBacking([]int{1, 2, 3, 4, 5, 6})) + t2, err := tensor.T(t) + if err != nil { + fmt.Printf("ERR: %v\n", err) + } + fmt.Printf("T is a safe version of the .T() method\nT:\n%v\nT':\n%v\n", t, t2) + fmt.Printf("The data is unchanged:\nT : %v\nT': %v\n", t.Data(), t2.Data()) + + // Output: + // T is a safe version of the .T() method + // T: + // ⎡1 2 3⎤ + // ⎣4 5 6⎦ + // + // T': + // ⎡1 4⎤ + // ⎢2 5⎥ + // ⎣3 6⎦ + // + // The data is unchanged: + // T : [1 2 3 4 5 6] + // T': [1 2 3 4 5 6] + +}