Skip to content

Commit 9347092

Browse files
committed
refactor: simplify Max2Tensor
1 parent 6fae896 commit 9347092

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/test_non_number_eval_tree_array.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ mutable struct Max2Tensor{T}
1818
scalar::T
1919
vector::Vector{T}
2020
matrix::Matrix{T}
21-
Max2Tensor{T}() where {T} = new(Int8(0), zero(T), T[], Array{T,2}(undef, 0, 0))
22-
function Max2Tensor{T}(scalar::W) where {T,W<:Number}
23-
return new(Int8(0), Base.convert(T, scalar), T[], Array{T,2}(undef, 0, 0))
24-
end
25-
function Max2Tensor{T}(vector::Vector{W}) where {T,W<:Number}
26-
return new(Int8(1), zero(T), Vector{T}(vector), Array{T,2}(undef, 0, 0))
27-
end
28-
function Max2Tensor{T}(matrix::Matrix{W}) where {T,W<:Number}
29-
return new(Int8(2), zero(T), T[], Matrix{T}(matrix))
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}}}
25+
return new(
26+
ndims(x),
27+
x isa Number ? Base.convert(T, x) : zero(T),
28+
x isa Vector ? Vector{T}(x) : Vector{T}(undef, 0),
29+
x isa Matrix ? Matrix{T}(x) : Matrix{T}(undef, 0, 0),
30+
)
3031
end
3132
end
3233

0 commit comments

Comments
 (0)