@@ -63,7 +63,7 @@ which speed up evaluation significantly.
63
63
"""
64
64
function eval_tree_array (
65
65
tree:: Node{T} , cX:: AbstractMatrix{T} , operators:: OperatorEnum ; turbo:: Bool = false
66
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real }
66
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number }
67
67
n = size (cX, 2 )
68
68
if turbo
69
69
@assert T in (Float32, Float64)
@@ -77,7 +77,7 @@ function eval_tree_array(
77
77
end
78
78
function eval_tree_array (
79
79
tree:: Node{T1} , cX:: AbstractMatrix{T2} , operators:: OperatorEnum ; turbo:: Bool = false
80
- ) where {T1<: Real ,T2<: Real }
80
+ ) where {T1<: Number ,T2<: Number }
81
81
T = promote_type (T1, T2)
82
82
@warn " Warning: eval_tree_array received mixed types: tree=$(T1) and data=$(T2) ."
83
83
tree = convert (Node{T}, tree)
87
87
88
88
function _eval_tree_array (
89
89
tree:: Node{T} , cX:: AbstractMatrix{T} , operators:: OperatorEnum , :: Val{turbo}
90
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,turbo}
90
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,turbo}
91
91
n = size (cX, 2 )
92
92
# First, we see if there are only constants in the tree - meaning
93
93
# we can just return the constant result.
148
148
149
149
function deg2_eval (
150
150
cumulator_l:: AbstractVector{T} , cumulator_r:: AbstractVector{T} , op:: F , :: Val{turbo}
151
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,turbo}
151
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,turbo}
152
152
@maybe_turbo turbo for j in indices (cumulator_l)
153
153
x = op (cumulator_l[j], cumulator_r[j]):: T
154
154
cumulator_l[j] = x
158
158
159
159
function deg1_eval (
160
160
cumulator:: AbstractVector{T} , op:: F , :: Val{turbo}
161
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,turbo}
161
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,turbo}
162
162
@maybe_turbo turbo for j in indices (cumulator)
163
163
x = op (cumulator[j]):: T
164
164
cumulator[j] = x
168
168
169
169
function deg0_eval (
170
170
tree:: Node{T} , cX:: AbstractMatrix{T}
171
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real }
171
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number }
172
172
if tree. constant
173
173
n = size (cX, 2 )
174
174
return (fill (tree. val:: T , n), true )
179
179
180
180
function deg1_l2_ll0_lr0_eval (
181
181
tree:: Node{T} , cX:: AbstractMatrix{T} , op:: F , op_l:: F2 , :: Val{turbo}
182
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,F2,turbo}
182
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,F2,turbo}
183
183
n = size (cX, 2 )
184
184
if tree. l. l. constant && tree. l. r. constant
185
185
val_ll = tree. l. l. val:: T
229
229
# op(op2(x)) for x variable or constant
230
230
function deg1_l1_ll0_eval (
231
231
tree:: Node{T} , cX:: AbstractMatrix{T} , op:: F , op_l:: F2 , :: Val{turbo}
232
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,F2,turbo}
232
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,F2,turbo}
233
233
n = size (cX, 2 )
234
234
if tree. l. l. constant
235
235
val_ll = tree. l. l. val:: T
254
254
# op(x, y) for x and y variable/constant
255
255
function deg2_l0_r0_eval (
256
256
tree:: Node{T} , cX:: AbstractMatrix{T} , op:: F , :: Val{turbo}
257
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,turbo}
257
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,turbo}
258
258
n = size (cX, 2 )
259
259
if tree. l. constant && tree. r. constant
260
260
val_l = tree. l. val:: T
297
297
# op(x, y) for x variable/constant, y arbitrary
298
298
function deg2_l0_eval (
299
299
tree:: Node{T} , cumulator:: AbstractVector{T} , cX:: AbstractArray{T} , op:: F , :: Val{turbo}
300
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,turbo}
300
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,turbo}
301
301
n = size (cX, 2 )
302
302
if tree. l. constant
303
303
val = tree. l. val:: T
319
319
# op(x, y) for x arbitrary, y variable/constant
320
320
function deg2_r0_eval (
321
321
tree:: Node{T} , cumulator:: AbstractVector{T} , cX:: AbstractArray{T} , op:: F , :: Val{turbo}
322
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,turbo}
322
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,turbo}
323
323
n = size (cX, 2 )
324
324
if tree. r. constant
325
325
val = tree. r. val:: T
@@ -339,15 +339,15 @@ function deg2_r0_eval(
339
339
end
340
340
341
341
"""
342
- _eval_constant_tree(tree::Node{T}, operators::OperatorEnum)::Tuple{T,Bool} where {T<:Real }
342
+ _eval_constant_tree(tree::Node{T}, operators::OperatorEnum)::Tuple{T,Bool} where {T<:Number }
343
343
344
344
Evaluate a tree which is assumed to not contain any variable nodes. This
345
345
gives better performance, as we do not need to perform computation
346
346
over an entire array when the values are all the same.
347
347
"""
348
348
function _eval_constant_tree (
349
349
tree:: Node{T} , operators:: OperatorEnum
350
- ):: Tuple{T,Bool} where {T<: Real }
350
+ ):: Tuple{T,Bool} where {T<: Number }
351
351
if tree. degree == 0
352
352
return deg0_eval_constant (tree)
353
353
elseif tree. degree == 1
@@ -357,13 +357,13 @@ function _eval_constant_tree(
357
357
end
358
358
end
359
359
360
- @inline function deg0_eval_constant (tree:: Node{T} ):: Tuple{T,Bool} where {T<: Real }
360
+ @inline function deg0_eval_constant (tree:: Node{T} ):: Tuple{T,Bool} where {T<: Number }
361
361
return tree. val:: T , true
362
362
end
363
363
364
364
function deg1_eval_constant (
365
365
tree:: Node{T} , op:: F , operators:: OperatorEnum
366
- ):: Tuple{T,Bool} where {T<: Real ,F}
366
+ ):: Tuple{T,Bool} where {T<: Number ,F}
367
367
(cumulator, complete) = _eval_constant_tree (tree. l, operators)
368
368
! complete && return zero (T), false
369
369
output = op (cumulator):: T
372
372
373
373
function deg2_eval_constant (
374
374
tree:: Node{T} , op:: F , operators:: OperatorEnum
375
- ):: Tuple{T,Bool} where {T<: Real ,F}
375
+ ):: Tuple{T,Bool} where {T<: Number ,F}
376
376
(cumulator, complete) = _eval_constant_tree (tree. l, operators)
377
377
! complete && return zero (T), false
378
378
(cumulator2, complete2) = _eval_constant_tree (tree. r, operators)
@@ -388,7 +388,7 @@ Evaluate an expression tree in a way that can be auto-differentiated.
388
388
"""
389
389
function differentiable_eval_tree_array (
390
390
tree:: Node{T1} , cX:: AbstractMatrix{T} , operators:: OperatorEnum
391
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,T1}
391
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,T1}
392
392
n = size (cX, 2 )
393
393
if tree. degree == 0
394
394
if tree. constant
405
405
406
406
function deg1_diff_eval (
407
407
tree:: Node{T1} , cX:: AbstractMatrix{T} , op:: F , operators:: OperatorEnum
408
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,T1}
408
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,T1}
409
409
(left, complete) = differentiable_eval_tree_array (tree. l, cX, operators)
410
410
@return_on_false complete left
411
411
out = op .(left)
415
415
416
416
function deg2_diff_eval (
417
417
tree:: Node{T1} , cX:: AbstractMatrix{T} , op:: F , operators:: OperatorEnum
418
- ):: Tuple{AbstractVector{T},Bool} where {T<: Real ,F,T1}
418
+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number ,F,T1}
419
419
(left, complete) = differentiable_eval_tree_array (tree. l, cX, operators)
420
420
@return_on_false complete left
421
421
(right, complete2) = differentiable_eval_tree_array (tree. r, cX, operators)
0 commit comments