Skip to content

Commit

Permalink
Start simplifying the UnallocatedZeros file
Browse files Browse the repository at this point in the history
  • Loading branch information
kmp5VT committed Oct 23, 2023
1 parent 071ae92 commit 1a849c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
2 changes: 2 additions & 0 deletions NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## TODO All constructors not fully implemented but so far it matches the
## constructors found in `FillArrays`. Need to fix io
struct UnallocatedFill{ElT,N,Axes,Alloc<:AbstractArray} <: FillArrays.AbstractFill{ElT,N,Axes}

Check warning on line 3 in NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl:3:-struct UnallocatedFill{ElT,N,Axes,Alloc<:AbstractArray} <: FillArrays.AbstractFill{ElT,N,Axes} NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl:4:- f::FillArrays.Fill{ElT, N, Axes} NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl:3:+struct UnallocatedFill{ElT,N,Axes,Alloc<:AbstractArray} <: NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl:4:+ FillArrays.AbstractFill{ElT,N,Axes} NDTensors/src/UnallocatedArrays/src/unallocatedfill.jl:5:+ f::FillArrays.Fill{ElT,N,Axes}
f::FillArrays.Fill{ElT, N, Axes}

Expand Down
45 changes: 10 additions & 35 deletions NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl
Original file line number Diff line number Diff line change
@@ -1,52 +1,28 @@
## TODO still working to make this implementation simplified
struct UnallocatedZeros{ElT,N,Axes,Alloc<:AbstractArray{ElT,N}} <:
FillArrays.AbstractZeros{ElT,N,Axes}
z::FillArrays.Zeros{ElT,N,Axes}
function UnallocatedZeros{ElT,N,Alloc}(inds::Tuple) where {ElT,N,Alloc}
z = FillArrays.Zeros{ElT,N}(inds)
Axes = typeof(FillArrays.axes(z))
return new{ElT,N,Axes,Alloc}(z)
end

function UnallocatedZeros{ElT,N,Alloc}(::Tuple{}) where {ElT,N,Alloc}
@assert N == 1
z = FillArrays.Zeros{ElT,N}(1)
Axes = typeof(FillArrays.axes(z))
return new{ElT,N,Axes,Alloc}(z)
function UnallocatedZeros{ElT,N,Axes,Alloc}(inds::Tuple) where{ElT,N,Axes,Alloc}

Check warning on line 6 in NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:6:- function UnallocatedZeros{ElT,N,Axes,Alloc}(inds::Tuple) where{ElT,N,Axes,Alloc} NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:6:+ function UnallocatedZeros{ElT,N,Axes,Alloc}(inds::Tuple) where {ElT,N,Axes,Alloc}
z = FillArrays.Zeros(inds)
ax = typeof(FillArrays.axes(z))
new{ElT,N,ax,Alloc}(z)

Check warning on line 9 in NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:9:- new{ElT,N,ax,Alloc}(z) NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:9:+ return new{ElT,N,ax,Alloc}(z)
end

function UnallocatedZeros{ElT,N,Axes,Alloc}(inds::Tuple) where {ElT,N,Axes,Alloc}
@assert Axes == typeof(Base.axes(inds))
z = FillArrays.Zeros{ElT,N}(inds)
return new{ElT,N,Axes,Alloc}(z)
function UnallcoatedZeros{ElT,0,Tuple{},Alloc}(inds::Tuple{}) where{ElT,Alloc}

Check warning on line 12 in NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:12:- function UnallcoatedZeros{ElT,0,Tuple{},Alloc}(inds::Tuple{}) where{ElT,Alloc} NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:12:+ function UnallcoatedZeros{ElT,0,Tuple{},Alloc}(inds::Tuple{}) where {ElT,Alloc}
z = FillArrays.Zeros(inds)
new{ElT,0,Tuple{},Alloc}(z)

Check warning on line 14 in NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:14:- new{ElT,0,Tuple{},Alloc}(z) NDTensors/src/UnallocatedArrays/src/unallocatedzeros.jl:14:+ return new{ElT,0,Tuple{},Alloc}(z)
end
end

function UnallocatedZeros{ElT,N,Axes,Alloc}() where {ElT,N,Axes,Alloc<:AbstractArray{ElT,N}}
return UnallocatedZeros{ElT,N,Axes,Alloc}[]
end
function UnallocatedZeros(alloc::Type{<:AbstractArray}, inds...)
@assert ndims(alloc) == length(inds)
alloc = specify_eltype(alloc)
return UnallocatedZeros{eltype(alloc),ndims(alloc),alloc}(Tuple(inds))
end

function UnallocatedZeros{ElT}(alloc::Type{<:AbstractArray}, inds...) where {ElT}
alloc = set_eltype(alloc, ElT)
N = length(Tuple(inds))
alloc = set_ndims(alloc, N)
return UnallocatedZeros(alloc, inds...)
end

Base.ndims(::UnallocatedZeros{ElT,N}) where {ElT,N} = N
ndims(::UnallocatedZeros{ElT,N}) where {ElT,N} = N
Base.eltype(::UnallocatedZeros{ElT}) where {ElT} = ElT
alloctype(::UnallocatedZeros{ElT,N,Axes,Alloc}) where {ElT,N,Axes,Alloc} = Alloc
function alloctype(::Type{<:UnallocatedZeros{ElT,N,Axes,Alloc}}) where {ElT,N,Axes,Alloc}
return Alloc
end
axes(::Type{<:UnallocatedZeros{ElT,N,Axes}}) where {ElT,N,Axes} = Axes

Base.size(zero::UnallocatedZeros) = Base.size(zero.z)
Base.axes(::Type{<:UnallocatedZeros{ElT,N,Axes}}) where {ElT,N,Axes} = Axes
Base.size(Z::UnallocatedZeros) = Base.size(Z.z)

Base.print_array(io::IO, X::UnallocatedZeros) = Base.print_array(io, X.z)

Expand All @@ -60,7 +36,6 @@ dims(z::UnallocatedZeros) = Tuple(size(z.z))
dim(z::UnallocatedZeros) = dim(size(z.z))
copy(z::UnallocatedZeros) = UnallocatedZeros{eltype(z),ndims(z),alloctype(z)}(dims(z))

Base.vec(z::Type{<:UnallocatedZeros}) = z
Base.vec(z::UnallocatedZeros) = z

function Base.convert(x::Type{T}, z::UnallocatedZeros) where {T<:Base.Array}
Expand Down

0 comments on commit 1a849c9

Please sign in to comment.