File: op.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 (117 lines) | stat: -rw-r--r-- 2,113 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main

import "reflect"

type Op interface {
	Name() string
	Arity() int
	SymbolTemplate() string
	TypeClass() TypeClass
	IsFunc() bool
}

type TypedOp interface {
	Op
	Kind() reflect.Kind
}

type BinOp interface {
	Op
	IsBinOp()
}

type UnaryOp interface {
	Op
	IsUnaryOp()
}

type RetSamer interface {
	RetSame() bool
}

type basicBinOp struct {
	symbol string
	name   string
	isFunc bool
	is     TypeClass
}

type arithOp struct {
	basicBinOp
	TypeClassName   string
	HasIdentity     bool
	Identity        int
	IsInv           bool
	Inv             string
	IsCommutative   bool
	IsInvolutionary bool
}

type cmpOp struct {
	basicBinOp
	TypeClassName string
	Inv string
	IsTransitive bool
	IsSymmetric bool
}

func (op basicBinOp) Name() string           { return op.name }
func (op basicBinOp) Arity() int             { return 2 }
func (op basicBinOp) SymbolTemplate() string { return op.symbol }
func (op basicBinOp) TypeClass() TypeClass   { return op.is }
func (op basicBinOp) IsFunc() bool           { return op.isFunc }
func (op basicBinOp) IsBinOp()               {}

type TypedBinOp struct {
	BinOp
	k reflect.Kind
}

// IsFunc contains special conditions
func (op TypedBinOp) IsFunc() bool {
	if op.Name() == "Mod" && isFloatCmplx(op.k) {
		return true
	}
	return op.BinOp.IsFunc()
}

func (op TypedBinOp) Kind() reflect.Kind { return op.k }

type unaryOp struct {
	symbol string
	name   string
	isfunc bool
	is     TypeClass

	TypeClassName string // mainly used in tests
	Inv string
}

func (op unaryOp) Name() string           { return op.name }
func (op unaryOp) Arity() int             { return 1 }
func (op unaryOp) SymbolTemplate() string { return op.symbol }
func (op unaryOp) TypeClass() TypeClass   { return op.is }
func (op unaryOp) IsFunc() bool           { return op.isfunc }
func (op unaryOp) IsUnaryOp()             {}

type TypedUnaryOp struct {
	UnaryOp
	k reflect.Kind
}

func (op TypedUnaryOp) Kind() reflect.Kind { return op.k }

type specialUnaryOp struct {
	unaryOp
	additionalParams []string
}

type Level int

const (
	Basic Level = iota
	InternalE
	StdEng
	Dense
	API
)