Skip to content

Commit bebbe18

Browse files
committed
refactor: simplify Max2Tensor further
1 parent 571518c commit bebbe18

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/test_non_number_eval_tree_array.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ mutable struct Max2Tensor{T}
1818
scalar::T
1919
vector::Vector{T}
2020
matrix::Matrix{T}
21-
Max2Tensor{T}() where {T} = new(0, zero(T), Vector{T}(undef, 0), Matrix{T}(undef, 0, 0))
22-
function Max2Tensor{T}(
23-
x::A
24-
) where {T,A<:Union{Number,Vector{<:Number},Matrix{<:Number}}}
21+
22+
#! format: off
23+
function Max2Tensor{T}(x::A=nothing) where {T,A<:Union{Nothing,Number,Vector{<:Number},Matrix{<:Number}}}
2524
return new(
26-
ndims(x),
25+
x === nothing ? 0 : ndims(x),
2726
x isa Number ? Base.convert(T, x) : zero(T),
2827
x isa Vector ? Vector{T}(x) : Vector{T}(undef, 0),
2928
x isa Matrix ? Matrix{T}(x) : Matrix{T}(undef, 0, 0),
3029
)
3130
end
31+
#! format: on
3232
end
3333

3434
function DE.is_valid(val::T) where {Q<:Number,T<:Max2Tensor{Q}}
@@ -117,7 +117,8 @@ Base.invokelatest(
117117

118118
tree = a(Node{Max2Tensor{Float64}}(; feature=1), Max2Tensor{Float64}(3.0))
119119
results = tree(
120-
[Max2Tensor{Float64}(1.0) Max2Tensor{Float64}(2.0) Max2Tensor{Float64}(3.0)]
120+
[Max2Tensor{Float64}(1.0) Max2Tensor{Float64}(2.0) Max2Tensor{Float64}(3.0)],
121+
operators,
121122
)
122123
@test results ==
123124
[Max2Tensor{Float64}(4), Max2Tensor{Float64}(5), Max2Tensor{Float64}(6)]

0 commit comments

Comments
 (0)