Skip to content

Commit

Permalink
More constructors and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Nov 14, 2024
1 parent cabfea7 commit 0e02381
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 52 deletions.
2 changes: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.3.67"
version = "0.3.68"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ function BlockSparseArray{T,N,A}(
return BlockSparseArray{T,N,A}(blocks, axes)
end

function BlockSparseArray{T,N,A}(
axes::Vararg{AbstractUnitRange,N}
) where {T,N,A<:AbstractArray{T,N}}
return BlockSparseArray{T,N,A}(axes)
end

function BlockSparseArray{T,N,A}(
dims::Tuple{Vararg{Vector{Int},N}}
) where {T,N,A<:AbstractArray{T,N}}
return BlockSparseArray{T,N,A}(blockedrange.(dims))
end

# Fix ambiguity error.
function BlockSparseArray{T,0,A}(axes::Tuple{}) where {T,A<:AbstractArray{T,0}}
blocks = default_blocks(A, axes)
return BlockSparseArray{T,0,A}(blocks, axes)
end

function BlockSparseArray{T,N,A}(
dims::Vararg{Vector{Int},N}
) where {T,N,A<:AbstractArray{T,N}}
return BlockSparseArray{T,N,A}(dims)
end

function BlockSparseArray{T,N}(axes::Tuple{Vararg{AbstractUnitRange,N}}) where {T,N}
return BlockSparseArray{T,N,default_arraytype(T, axes)}(axes)
end
Expand Down Expand Up @@ -119,56 +143,25 @@ function BlockSparseArray{T}() where {T}
return BlockSparseArray{T}(())
end

function BlockSparseArray{T,N,A}(
::UndefInitializer, dims::Tuple
) where {T,N,A<:AbstractArray{T,N}}
return BlockSparseArray{T,N,A}(dims)
end

# undef
function BlockSparseArray{T,N}(
::UndefInitializer, axes::Tuple{Vararg{AbstractUnitRange,N}}
) where {T,N}
return BlockSparseArray{T,N}(axes)
end

function BlockSparseArray{T,N}(
::UndefInitializer, axes::Vararg{AbstractUnitRange,N}
) where {T,N}
return BlockSparseArray{T,N}(axes)
end

function BlockSparseArray{T,N}(
::UndefInitializer, dims::Tuple{Vararg{Vector{Int},N}}
) where {T,N}
return BlockSparseArray{T,N}(dims)
end

function BlockSparseArray{T,N}(::UndefInitializer, dims::Vararg{Vector{Int},N}) where {T,N}
return BlockSparseArray{T,N}(dims)
end

function BlockSparseArray{T}(
::UndefInitializer, axes::Tuple{Vararg{AbstractUnitRange}}
) where {T}
return BlockSparseArray{T}(axes)
end

function BlockSparseArray{T}(::UndefInitializer, axes::Vararg{AbstractUnitRange}) where {T}
return BlockSparseArray{T}(axes...)
function BlockSparseArray{T,N,A,Blocks}(
::UndefInitializer, args...
) where {T,N,A<:AbstractArray{T,N},Blocks<:AbstractArray{A,N}}
return BlockSparseArray{T,N,A,Blocks}(args...)
end

# Fix ambiguity error.
function BlockSparseArray{T}(::UndefInitializer) where {T}
return BlockSparseArray{T}()
function BlockSparseArray{T,N,A}(
::UndefInitializer, args...
) where {T,N,A<:AbstractArray{T,N}}
return BlockSparseArray{T,N,A}(args...)
end

function BlockSparseArray{T}(::UndefInitializer, dims::Tuple{Vararg{Vector{Int}}}) where {T}
return BlockSparseArray{T}(dims)
function BlockSparseArray{T,N}(::UndefInitializer, args...) where {T,N}
return BlockSparseArray{T,N}(args...)
end

function BlockSparseArray{T}(::UndefInitializer, dims::Vararg{Vector{Int}}) where {T}
return BlockSparseArray{T}(dims...)
function BlockSparseArray{T}(::UndefInitializer, args...) where {T}
return BlockSparseArray{T}(args...)
end

# Base `AbstractArray` interface
Expand Down
16 changes: 8 additions & 8 deletions NDTensors/src/lib/BlockSparseArrays/test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ using .NDTensorsTestUtils: devices_list, is_supported_eltype
BlockSparseArray{elt},
BlockSparseArray{elt,2},
BlockSparseMatrix{elt},
## BlockSparseArray{elt,2,Matrix{elt}},
## BlockSparseMatrix{elt,Matrix{elt}},
## BlockSparseArray{elt,2,Matrix{elt},SparseMatrixDOK{Matrix{elt}}},
## BlockSparseMatrix{elt,Matrix{elt},SparseMatrixDOK{Matrix{elt}}},
BlockSparseArray{elt,2,Matrix{elt}},
BlockSparseMatrix{elt,Matrix{elt}},
## BlockSparseArray{elt,2,Matrix{elt},SparseMatrixDOK{Matrix{elt}}}, # TODO
## BlockSparseMatrix{elt,Matrix{elt},SparseMatrixDOK{Matrix{elt}}}, # TODO
)
for args in (
bs,
Expand Down Expand Up @@ -116,10 +116,10 @@ using .NDTensorsTestUtils: devices_list, is_supported_eltype
BlockSparseArray{elt},
BlockSparseArray{elt,1},
BlockSparseVector{elt},
## BlockSparseArray{elt,1,Vector{elt}},
## BlockSparseVector{elt,Vector{elt}},
## BlockSparseArray{elt,1,Vector{elt},SparseVectorDOK{Vector{elt}}},
## BlockSparseVector{elt,Vector{elt},SparseVectorDOK{Vector{elt}}},
BlockSparseArray{elt,1,Vector{elt}},
BlockSparseVector{elt,Vector{elt}},
## BlockSparseArray{elt,1,Vector{elt},SparseVectorDOK{Vector{elt}}}, # TODO
## BlockSparseVector{elt,Vector{elt},SparseVectorDOK{Vector{elt}}}, # TODO
)
for args in (
bs,
Expand Down

0 comments on commit 0e02381

Please sign in to comment.