github.com/wzzhu/tensor@v0.9.24/genlib2/op.go (about) 1 package main 2 3 import "reflect" 4 5 type Op interface { 6 Name() string 7 Arity() int 8 SymbolTemplate() string 9 TypeClass() TypeClass 10 IsFunc() bool 11 } 12 13 type TypedOp interface { 14 Op 15 Kind() reflect.Kind 16 } 17 18 type BinOp interface { 19 Op 20 IsBinOp() 21 } 22 23 type UnaryOp interface { 24 Op 25 IsUnaryOp() 26 } 27 28 type RetSamer interface { 29 RetSame() bool 30 } 31 32 type basicBinOp struct { 33 symbol string 34 name string 35 isFunc bool 36 is TypeClass 37 } 38 39 type arithOp struct { 40 basicBinOp 41 TypeClassName string 42 HasIdentity bool 43 Identity int 44 IsInv bool 45 Inv string 46 IsCommutative bool 47 IsInvolutionary bool 48 } 49 50 type cmpOp struct { 51 basicBinOp 52 TypeClassName string 53 Inv string 54 IsTransitive bool 55 IsSymmetric bool 56 } 57 58 func (op basicBinOp) Name() string { return op.name } 59 func (op basicBinOp) Arity() int { return 2 } 60 func (op basicBinOp) SymbolTemplate() string { return op.symbol } 61 func (op basicBinOp) TypeClass() TypeClass { return op.is } 62 func (op basicBinOp) IsFunc() bool { return op.isFunc } 63 func (op basicBinOp) IsBinOp() {} 64 65 type TypedBinOp struct { 66 BinOp 67 k reflect.Kind 68 } 69 70 // IsFunc contains special conditions 71 func (op TypedBinOp) IsFunc() bool { 72 if op.Name() == "Mod" && isFloatCmplx(op.k) { 73 return true 74 } 75 return op.BinOp.IsFunc() 76 } 77 78 func (op TypedBinOp) Kind() reflect.Kind { return op.k } 79 80 type unaryOp struct { 81 symbol string 82 name string 83 isfunc bool 84 is TypeClass 85 86 TypeClassName string // mainly used in tests 87 Inv string 88 } 89 90 func (op unaryOp) Name() string { return op.name } 91 func (op unaryOp) Arity() int { return 1 } 92 func (op unaryOp) SymbolTemplate() string { return op.symbol } 93 func (op unaryOp) TypeClass() TypeClass { return op.is } 94 func (op unaryOp) IsFunc() bool { return op.isfunc } 95 func (op unaryOp) IsUnaryOp() {} 96 97 type TypedUnaryOp struct { 98 UnaryOp 99 k reflect.Kind 100 } 101 102 func (op TypedUnaryOp) Kind() reflect.Kind { return op.k } 103 104 type specialUnaryOp struct { 105 unaryOp 106 additionalParams []string 107 } 108 109 type Level int 110 111 const ( 112 Basic Level = iota 113 InternalE 114 StdEng 115 Dense 116 API 117 )