Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UnallocatedArrays] Fix UnallocatedArray constructor #1454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading