Skip to content

Commit

Permalink
[UnallocatedArrays] Fix UnallocatedArray constructor (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmp5VT authored May 20, 2024
1 parent dc4d3db commit 3c692da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NDTensors/src/lib/UnallocatedArrays/src/unallocatedfill.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct UnallocatedFill{ElT,N,Axes,Alloc} <: AbstractFill{ElT,N,Axes}
end

function UnallocatedFill{ElT,N,Axes}(f::Fill, alloc::Type) where {ElT,N,Axes}
return new{ElT,N,Axes,Type{alloc}}(f, alloc)
return UnallocatedFill{ElT,N,Axes,Type{alloc}}(f, alloc)
end

function UnallocatedFill{ElT,N}(f::Fill, alloc) where {ElT,N}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct UnallocatedZeros{ElT,N,Axes,Alloc} <: AbstractZeros{ElT,N,Axes}
end

function UnallocatedZeros{ElT,N,Axes}(z::Zeros, alloc::Type) where {ElT,N,Axes}
return new{ElT,N,Axes,Type{alloc}}(z, alloc)
return UnallocatedZeros{ElT,N,Axes,Type{alloc}}(z, alloc)
end

function UnallocatedZeros{ElT,N}(z::Zeros, alloc) where {ElT,N}
Expand Down
5 changes: 5 additions & 0 deletions NDTensors/src/lib/UnallocatedArrays/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ using .NDTensorsTestUtils: devices_list
@test iszero(norm(Z))
@test iszero(Z[2, 3])
@test allocate(Z) isa dev(Matrix{elt})
Zp = UnallocatedZeros{elt}(Zeros(2, 3), dev(Matrix{elt}))
@test Zp == Z
Zp = set_alloctype(z, dev(Matrix{elt}))
@test Zp == Z
Zc = copy(Z)
Expand All @@ -44,13 +46,16 @@ using .NDTensorsTestUtils: devices_list
# UnallocatedFill
f = Fill{elt}(3, (2, 3, 4))
F = UnallocatedFill(f, Array{elt,ndims(f)})

@test F isa AbstractFill
@test size(F) == (2, 3, 4)
@test length(F) == 24
@test sum(F) elt(3) * 24
@test norm(F) sqrt(elt(3)^2 * 24)
@test F[2, 3, 1] == elt(3)
@test allocate(F) isa Array{elt,3}
Fp = UnallocatedFill{elt}(Fill(3, (2, 3, 4)), Array{elt,ndims(f)})
@test Fp == F
Fp = allocate(F)
@test norm(Fp) norm(F)
Fs = similar(F)
Expand Down

0 comments on commit 3c692da

Please sign in to comment.