| 1 |
package tensor |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
) |
| 6 |
|
| 7 |
// Data shows how the shape of the *Dense actually affects the return value of .Data(). |
| 8 |
func ExampleDense_Data() { |
| 9 |
T := New(WithShape(2, 2), WithBacking([]float64{1, 2, 3, 4})) |
| 10 |
fmt.Printf("Basics:\n======\nAny kind of arrays: %v\n", T.Data()) |
| 11 |
|
| 12 |
fmt.Printf("\nScalar-like\n===========\n") |
| 13 |
T = New(WithShape(), FromScalar(3.14)) |
| 14 |
fmt.Printf("WithShape(), FromScalar: %v\n", T.Data()) |
| 15 |
|
| 16 |
T = New(WithShape(), WithBacking([]float64{3.14})) |
| 17 |
fmt.Printf("WithShape(), With a slice of 1 as backing: %v\n", T.Data()) |
| 18 |
|
| 19 |
T = New(WithShape(1), FromScalar(3.14)) |
| 20 |
fmt.Printf("WithShape(1), With an initial scalar: %v\n", T.Data()) |
| 21 |
|
| 22 |
T = New(WithShape(1, 1), WithBacking([]float64{3.14})) |
| 23 |
fmt.Printf("WithShape(1, 1), With an initial scalar: %v\n", T.Data()) |
| 24 |
|
| 25 |
T = New(WithShape(1, 1), FromScalar(3.14)) |
| 26 |
fmt.Printf("WithShape(1, 1), With an initial scalar: %v\n", T.Data()) |
| 27 |
|
| 28 |
T.Reshape() |
| 29 |
fmt.Printf("After reshaping to (): %v\n", T.Data()) |
| 30 |
|
| 31 |
// Output: |
| 32 |
// Basics: |
| 33 |
// ====== |
| 34 |
// Any kind of arrays: [1 2 3 4] |
| 35 |
// |
| 36 |
// Scalar-like |
| 37 |
// =========== |
| 38 |
// WithShape(), FromScalar: 3.14 |
| 39 |
// WithShape(), With a slice of 1 as backing: 3.14 |
| 40 |
// WithShape(1), With an initial scalar: [3.14] |
| 41 |
// WithShape(1, 1), With an initial scalar: [3.14] |
| 42 |
// WithShape(1, 1), With an initial scalar: [3.14] |
| 43 |
// After reshaping to (): 3.14 |
| 44 |
|
| 45 |
} |