Skip to content
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.9.0"
version = "0.9.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down Expand Up @@ -35,10 +35,10 @@ FunctionImplementations = "0.4"
GPUArraysCore = "0.2"
LinearAlgebra = "1.10"
MapBroadcast = "0.1.5"
NamedDimsArrays = "0.13"
NamedDimsArrays = "0.13, 0.14"
Random = "1.10"
SparseArrays = "1.10"
TensorAlgebra = "0.6.2"
TensorAlgebra = "0.6.2, 0.7"
TypeParameterAccessors = "0.4.3"
julia = "1.10"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module SparseArraysBaseNamedDimsArraysExt

using NamedDimsArrays: AbstractNamedDimsArray, AbstractNamedUnitRange, denamed, inds,
nameddims, nameddimsof
name, nameddims, nameddimsof
using SparseArraysBase: SparseArraysBase, dense, oneelement

function SparseArraysBase.dense(a::AbstractNamedDimsArray)
Expand All @@ -13,7 +13,7 @@ end
function SparseArraysBase.oneelement(
value, index::NTuple{N, Int}, ax::NTuple{N, AbstractNamedUnitRange}
) where {N}
return nameddims(oneelement(value, index, only.(axes.(denamed.(ax)))), ax)
return nameddims(oneelement(value, index, denamed.(ax)), name.(ax))
end

end
4 changes: 2 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ FillArrays = "1.13.0"
FunctionImplementations = "0.4"
JLArrays = "0.2.0, 0.3"
LinearAlgebra = "<0.0.1, 1"
NamedDimsArrays = "0.13"
NamedDimsArrays = "0.13, 0.14"
Random = "<0.0.1, 1"
SafeTestsets = "0.1.0"
SparseArrays = "1.10"
SparseArraysBase = "0.9"
StableRNGs = "1.0.2"
Suppressor = "0.2.8"
TensorAlgebra = "0.6"
TensorAlgebra = "0.6, 0.7"
Test = "<0.0.1, 1"
30 changes: 16 additions & 14 deletions test/test_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ using JLArrays: JLArray
using SparseArraysBase: dense, sparsezeros
using Test: @test, @testset

module TestDenseUtils
struct MySparseArrayDOK{T, N, S <: AbstractVector{T}} <: AbstractArray{T, N}
storedvalues::S
storedindices::Dict{CartesianIndex{N}, Int}
size::NTuple{N, Int}
end
Base.size(a::MySparseArrayDOK) = a.size
function Base.getindex(a::MySparseArrayDOK{<:Any, N}, I::Vararg{Int, N}) where {N}
storageindex = get(a.storedindices, CartesianIndex(I), nothing)
isnothing(storageindex) && return zero(eltype(a))
return a.storedvalues[storageindex]
end
Base.parent(a::MySparseArrayDOK) = a.storedvalues
end

elts = (Float32, ComplexF64)
arrayts = (Array, JLArray)
@testset "dense (arraytype=$arrayt, eltype=$elt)" for arrayt in arrayts, elt in elts
Expand All @@ -17,20 +32,7 @@ arrayts = (Array, JLArray)
end

@testset "Custom sparse array" begin
struct MySparseArrayDOK{T, N, S <: AbstractVector{T}} <: AbstractArray{T, N}
storedvalues::S
storedindices::Dict{CartesianIndex{N}, Int}
size::NTuple{N, Int}
end
Base.size(a::MySparseArrayDOK) = a.size
function Base.getindex(a::MySparseArrayDOK{<:Any, N}, I::Vararg{Int, N}) where {N}
storageindex = get(a.storedindices, CartesianIndex(I), nothing)
isnothing(storageindex) && return zero(eltype(a))
return a.storedvalues[storageindex]
end
Base.parent(a::MySparseArrayDOK) = a.storedvalues

s = MySparseArrayDOK(
s = TestDenseUtils.MySparseArrayDOK(
dev(elt[2, 4]), Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4)
)
d = dense(s)
Expand Down
Loading