File: flags_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 (90 lines) | stat: -rw-r--r-- 2,694 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package tensor

import "testing"

func TestMemoryFlag(t *testing.T) {
	var defaultFlag MemoryFlag
	if defaultFlag.manuallyManaged() || !defaultFlag.nativelyAccessible() {
		t.Errorf("Something went wrong with the creation of flags")
	}

	a := ManuallyManaged
	if !a.manuallyManaged() {
		t.Errorf("Expected ManuallyManaged to be true")
	}
	if !a.nativelyAccessible() {
		t.Errorf("Expected ManuallyManaged to be nativelyAccessible")
	}

	b := NativelyInaccessible
	if b.manuallyManaged() {
		t.Errorf("Expected NativelyInaccessible to not be manually managed")
	}
	if b.nativelyAccessible() {
		t.Errorf("Expected NativelyInaccessible to be false %v", b.nativelyAccessible())
	}

	c := MakeMemoryFlag(ManuallyManaged, NativelyInaccessible)
	if !c.manuallyManaged() {
		t.Errorf("Expected c to be manually managed")
	}
	if c.nativelyAccessible() {
		t.Errorf("Expected c to be natively inaccessible")
	}
}

func TestDataOrder(t *testing.T) {
	var defaultFlag DataOrder
	if defaultFlag.IsColMajor() || defaultFlag.IsNotContiguous() || defaultFlag.IsTransposed() {
		t.Error("Expected default flag to be row major and contiguous and not transposed")
	}
	if !(defaultFlag.IsRowMajor() && defaultFlag.IsContiguous()) {
		t.Error("Expected default flag to be row major and contiguous")
	}
	if defaultFlag.String() != "Contiguous, RowMajor" {
		t.Errorf("Expected string is \"Contiguous, RowMajor\". Got %q", defaultFlag.String())
	}

	ncrm := MakeDataOrder(NonContiguous)
	if ncrm.IsColMajor() || ncrm.IsContiguous() {
		t.Error("Expected noncontiguous row major.")
	}
	if ncrm.String() != "NonContiguous, RowMajor" {
		t.Errorf("Expected string is \"NonContiguous, RowMajor\". Got %q", defaultFlag.String())
	}

	cm := ColMajor
	if cm.IsRowMajor() {
		t.Error("colMajor cannot be rowMajor")
	}
	if cm.IsNotContiguous() {
		t.Error("ColMajor by default is contiguous")
	}
	if cm.String() != "Contiguous, ColMajor" {
		t.Errorf(`Expected string is "Contiguous, ColMajor". Got %q`, cm.String())
	}

	// check toggle
	rm := cm.toggleColMajor()
	if rm.IsColMajor() {
		t.Errorf("toggled cm should be rm")
	}

	cm = rm.toggleColMajor()
	if cm.IsRowMajor() {
		t.Errorf("toggled rm should be cm")
	}

	transposed := MakeDataOrder(Transposed)
	if !transposed.IsTransposed() {
		t.Error("Expected transposed flag to be set")
	}
	if transposed.String() != "Contiguous, RowMajorᵀ" {
		t.Errorf("Expected string is \"Contiguous, RowMajorᵀ\". Got %q", defaultFlag.String())
	}
	untransposed := transposed.clearTransposed()
	if untransposed != defaultFlag {
		t.Error("Expected default flag after untransposing")
	}

}