@@ -6,29 +6,49 @@ abstract type AbstractOperatorEnum end
66 OperatorEnum
77
88Defines an enum over operators, along with their derivatives.
9+
910# Fields
10- - `binops`: A tuple of binary operators. Scalar input type.
11- - `unaops`: A tuple of unary operators. Scalar input type.
11+ - `ops`: A tuple of operators, with index `i` corresponding to the operator tuple for a node of degree `i`.
1212"""
13- struct OperatorEnum{B,U} <: AbstractOperatorEnum
14- binops:: B
15- unaops:: U
13+ struct OperatorEnum{OPS<: Tuple{Vararg{Tuple}} } <: AbstractOperatorEnum
14+ ops:: OPS
15+ end
16+
17+ function OperatorEnum (binary_operators:: Tuple , unary_operators:: Tuple )
18+ return OperatorEnum ((unary_operators, binary_operators))
1619end
1720
1821"""
1922 GenericOperatorEnum
2023
2124Defines an enum over operators, along with their derivatives.
25+
2226# Fields
23- - `binops`: A tuple of binary operators.
24- - `unaops`: A tuple of unary operators.
27+ - `ops`: A tuple of operators, with index `i` corresponding to the operator tuple for a node of degree `i`.
2528"""
26- struct GenericOperatorEnum{B,U} <: AbstractOperatorEnum
27- binops:: B
28- unaops:: U
29+ struct GenericOperatorEnum{OPS<: Tuple{Vararg{Tuple}} } <: AbstractOperatorEnum
30+ ops:: OPS
31+ end
32+
33+ function GenericOperatorEnum (binops:: Tuple , unaops:: Tuple )
34+ return GenericOperatorEnum ((unaops, binops))
2935end
3036
3137Base. copy (op:: AbstractOperatorEnum ) = op
3238# TODO : Is this safe? What if a vector is passed here?
3339
40+ @inline function Base. getindex (op:: AbstractOperatorEnum , i:: Int )
41+ return getfield (op, :ops )[i]
42+ end
43+ @inline function Base. getproperty (op:: AbstractOperatorEnum , k:: Symbol )
44+ if k == :unaops
45+ return getfield (op, :ops )[1 ]
46+ elseif k == :binops
47+ ops = getfield (op, :ops )
48+ return length (ops) > 1 ? ops[2 ] : ()
49+ else
50+ return getfield (op, k)
51+ end
52+ end
53+
3454end
0 commit comments