File: example_dense_basics_test.go

package info (click to toggle)
golang-github-gorgonia-tensor 0.9.24-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,696 kB
  • sloc: sh: 18; asm: 18; makefile: 8
file content (45 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package tensor

import (
	"fmt"
)

// Data shows how the shape of the *Dense actually affects the return value of .Data().
func ExampleDense_Data() {
	T := New(WithShape(2, 2), WithBacking([]float64{1, 2, 3, 4}))
	fmt.Printf("Basics:\n======\nAny kind of arrays: %v\n", T.Data())

	fmt.Printf("\nScalar-like\n===========\n")
	T = New(WithShape(), FromScalar(3.14))
	fmt.Printf("WithShape(), FromScalar: %v\n", T.Data())

	T = New(WithShape(), WithBacking([]float64{3.14}))
	fmt.Printf("WithShape(), With a slice of 1 as backing: %v\n", T.Data())

	T = New(WithShape(1), FromScalar(3.14))
	fmt.Printf("WithShape(1), With an initial scalar: %v\n", T.Data())

	T = New(WithShape(1, 1), WithBacking([]float64{3.14}))
	fmt.Printf("WithShape(1, 1), With an initial scalar: %v\n", T.Data())

	T = New(WithShape(1, 1), FromScalar(3.14))
	fmt.Printf("WithShape(1, 1), With an initial scalar: %v\n", T.Data())

	T.Reshape()
	fmt.Printf("After reshaping to (): %v\n", T.Data())

	// Output:
	// Basics:
	// ======
	// Any kind of arrays: [1 2 3 4]
	//
	// Scalar-like
	// ===========
	// WithShape(), FromScalar: 3.14
	// WithShape(), With a slice of 1 as backing: 3.14
	// WithShape(1), With an initial scalar: [3.14]
	// WithShape(1, 1), With an initial scalar: [3.14]
	// WithShape(1, 1), With an initial scalar: [3.14]
	// After reshaping to (): 3.14

}