@@ -63,7 +63,7 @@ which speed up evaluation significantly.
6363"""
6464function eval_tree_array (
6565 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 }
6767 n = size (cX, 2 )
6868 if turbo
6969 @assert T in (Float32, Float64)
@@ -77,7 +77,7 @@ function eval_tree_array(
7777end
7878function eval_tree_array (
7979 tree:: Node{T1} , cX:: AbstractMatrix{T2} , operators:: OperatorEnum ; turbo:: Bool = false
80- ) where {T1<: Real ,T2<: Real }
80+ ) where {T1<: Number ,T2<: Number }
8181 T = promote_type (T1, T2)
8282 @warn " Warning: eval_tree_array received mixed types: tree=$(T1) and data=$(T2) ."
8383 tree = convert (Node{T}, tree)
8787
8888function _eval_tree_array (
8989 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}
9191 n = size (cX, 2 )
9292 # First, we see if there are only constants in the tree - meaning
9393 # we can just return the constant result.
148148
149149function deg2_eval (
150150 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}
152152 @maybe_turbo turbo for j in indices (cumulator_l)
153153 x = op (cumulator_l[j], cumulator_r[j]):: T
154154 cumulator_l[j] = x
158158
159159function deg1_eval (
160160 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}
162162 @maybe_turbo turbo for j in indices (cumulator)
163163 x = op (cumulator[j]):: T
164164 cumulator[j] = x
168168
169169function deg0_eval (
170170 tree:: Node{T} , cX:: AbstractMatrix{T}
171- ):: Tuple{AbstractVector{T},Bool} where {T<: Real }
171+ ):: Tuple{AbstractVector{T},Bool} where {T<: Number }
172172 if tree. constant
173173 n = size (cX, 2 )
174174 return (fill (tree. val:: T , n), true )
179179
180180function deg1_l2_ll0_lr0_eval (
181181 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}
183183 n = size (cX, 2 )
184184 if tree. l. l. constant && tree. l. r. constant
185185 val_ll = tree. l. l. val:: T
229229# op(op2(x)) for x variable or constant
230230function deg1_l1_ll0_eval (
231231 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}
233233 n = size (cX, 2 )
234234 if tree. l. l. constant
235235 val_ll = tree. l. l. val:: T
254254# op(x, y) for x and y variable/constant
255255function deg2_l0_r0_eval (
256256 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}
258258 n = size (cX, 2 )
259259 if tree. l. constant && tree. r. constant
260260 val_l = tree. l. val:: T
297297# op(x, y) for x variable/constant, y arbitrary
298298function deg2_l0_eval (
299299 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}
301301 n = size (cX, 2 )
302302 if tree. l. constant
303303 val = tree. l. val:: T
319319# op(x, y) for x arbitrary, y variable/constant
320320function deg2_r0_eval (
321321 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}
323323 n = size (cX, 2 )
324324 if tree. r. constant
325325 val = tree. r. val:: T
@@ -339,15 +339,15 @@ function deg2_r0_eval(
339339end
340340
341341"""
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 }
343343
344344Evaluate a tree which is assumed to not contain any variable nodes. This
345345gives better performance, as we do not need to perform computation
346346over an entire array when the values are all the same.
347347"""
348348function _eval_constant_tree (
349349 tree:: Node{T} , operators:: OperatorEnum
350- ):: Tuple{T,Bool} where {T<: Real }
350+ ):: Tuple{T,Bool} where {T<: Number }
351351 if tree. degree == 0
352352 return deg0_eval_constant (tree)
353353 elseif tree. degree == 1
@@ -357,13 +357,13 @@ function _eval_constant_tree(
357357 end
358358end
359359
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 }
361361 return tree. val:: T , true
362362end
363363
364364function deg1_eval_constant (
365365 tree:: Node{T} , op:: F , operators:: OperatorEnum
366- ):: Tuple{T,Bool} where {T<: Real ,F}
366+ ):: Tuple{T,Bool} where {T<: Number ,F}
367367 (cumulator, complete) = _eval_constant_tree (tree. l, operators)
368368 ! complete && return zero (T), false
369369 output = op (cumulator):: T
372372
373373function deg2_eval_constant (
374374 tree:: Node{T} , op:: F , operators:: OperatorEnum
375- ):: Tuple{T,Bool} where {T<: Real ,F}
375+ ):: Tuple{T,Bool} where {T<: Number ,F}
376376 (cumulator, complete) = _eval_constant_tree (tree. l, operators)
377377 ! complete && return zero (T), false
378378 (cumulator2, complete2) = _eval_constant_tree (tree. r, operators)
@@ -388,7 +388,7 @@ Evaluate an expression tree in a way that can be auto-differentiated.
388388"""
389389function differentiable_eval_tree_array (
390390 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}
392392 n = size (cX, 2 )
393393 if tree. degree == 0
394394 if tree. constant
405405
406406function deg1_diff_eval (
407407 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}
409409 (left, complete) = differentiable_eval_tree_array (tree. l, cX, operators)
410410 @return_on_false complete left
411411 out = op .(left)
415415
416416function deg2_diff_eval (
417417 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}
419419 (left, complete) = differentiable_eval_tree_array (tree. l, cX, operators)
420420 @return_on_false complete left
421421 (right, complete2) = differentiable_eval_tree_array (tree. r, cX, operators)
0 commit comments