Spaces:
Sleeping
Sleeping
File size: 1,364 Bytes
a1e832b |
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 |
# Evaluate an equation over an array of datapoints
function evalTreeArray(tree::Node)::Union{Array{Float32, 1}, Nothing}
return evalTreeArray(tree, X)
end
# Evaluate an equation over an array of datapoints
function evalTreeArray(tree::Node, cX::Array{Float32, 2})::Union{Array{Float32, 1}, Nothing}
clen = size(cX)[1]
if tree.degree == 0
if tree.constant
return fill(tree.val, clen)
else
return copy(cX[:, tree.val])
end
elseif tree.degree == 1
cumulator = evalTreeArray(tree.l, cX)
if cumulator === nothing
return nothing
end
op_idx = tree.op
UNAOP!(cumulator, op_idx, clen)
@inbounds for i=1:clen
if isinf(cumulator[i]) || isnan(cumulator[i])
return nothing
end
end
return cumulator
else
cumulator = evalTreeArray(tree.l, cX)
if cumulator === nothing
return nothing
end
array2 = evalTreeArray(tree.r, cX)
if array2 === nothing
return nothing
end
op_idx = tree.op
BINOP!(cumulator, array2, op_idx, clen)
@inbounds for i=1:clen
if isinf(cumulator[i]) || isnan(cumulator[i])
return nothing
end
end
return cumulator
end
end
|