File: generic_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 (67 lines) | stat: -rw-r--r-- 1,123 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package native_test

import (
	"fmt"

	"gorgonia.org/tensor"
	. "gorgonia.org/tensor/native"
)

type MyType int

func Example_vector() {
	backing := []MyType{
		0, 1, 2, 3,
	}
	T := tensor.New(tensor.WithShape(4), tensor.WithBacking(backing))
	val, err := Vector(T)
	if err != nil {
		fmt.Printf("error: %v", err)
	}
	it := val.([]MyType)
	fmt.Println(it)

	// Output:
	// [0 1 2 3]
}

func Example_matrix() {
	backing := []MyType{
		0, 1,
		2, 3,
		4, 5,
	}
	T := tensor.New(tensor.WithShape(3, 2), tensor.WithBacking(backing))
	val, err := Matrix(T)
	if err != nil {
		fmt.Printf("error: %v", err)
	}

	it := val.([][]MyType)
	fmt.Println(it)

	// Output:
	// [[0 1] [2 3] [4 5]]
}

func Example_tensor3() {
	backing := []MyType{
		0, 1, 2, 3,
		4, 5, 6, 7,
		8, 9, 10, 11,

		12, 13, 14, 15,
		16, 17, 18, 19,
		20, 21, 22, 23,
	}
	T := tensor.New(tensor.WithShape(2, 3, 4), tensor.WithBacking(backing))
	val, err := Tensor3(T)
	if err != nil {
		fmt.Printf("error: %v", err)
	}
	it := val.([][][]MyType)
	fmt.Println(it)

	//Output:
	// [[[0 1 2 3] [4 5 6 7] [8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]]
}