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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlockSparseArrays"
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.8"
version = "0.2.9"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
19 changes: 17 additions & 2 deletions src/abstractblocksparsearray/map.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArrayLayouts: LayoutArray
using BlockArrays: blockisequal
using DerivableInterfaces: @interface, interface
using DerivableInterfaces: @interface, AbstractArrayInterface, interface
using LinearAlgebra: Adjoint, Transpose
using SparseArraysBase: SparseArraysBase, SparseArrayStyle

Expand Down Expand Up @@ -49,15 +49,30 @@ function reblock(
return @view parent(a)[map(I -> Vector(I.blocks), parentindices(a))...]
end

# `map!` specialized to zero-dimensional inputs.
function map_zero_dim! end

@interface ::AbstractArrayInterface function map_zero_dim!(
f, a_dest::AbstractArray, a_srcs::AbstractArray...
)
a_dest[] = f.(map(a_src -> a_src[], a_srcs)...)
return a_dest
end

# TODO: Move to `blocksparsearrayinterface/map.jl`.
# TODO: Rewrite this so that it takes the blocking structure
# made by combining the blocking of the axes (i.e. the blocking that
# is used to determine `union_stored_blocked_cartesianindices(...)`).
# `reblock` is a partial solution to that, but a bit ad-hoc.
## TODO: Make this an `@interface AbstractBlockSparseArrayInterface` function.
@interface ::AbstractBlockSparseArrayInterface function Base.map!(
@interface interface::AbstractBlockSparseArrayInterface function Base.map!(
f, a_dest::AbstractArray, a_srcs::AbstractArray...
)
if iszero(ndims(a_dest))
@interface interface map_zero_dim!(f, a_dest, a_srcs...)
return a_dest
end

a_dest, a_srcs = reblock(a_dest), reblock.(a_srcs)
for I in union_stored_blocked_cartesianindices(a_dest, a_srcs...)
BI_dest = blockindexrange(a_dest, I)
Expand Down
7 changes: 5 additions & 2 deletions test/basics/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ arrayts = (Array, JLArray)
@test iszero(@allowscalar(a[CartesianIndex()]))
@test a[Block()] == dev(fill(0))
@test iszero(@allowscalar(a[Block()][]))
# Broken:
## @test b[Block()[]] == 2
@test @allowscalar(a[Block()[]]) == 0
@test Array(a) isa Array{elt,0}
@test Array(a) == fill(0)
for b in (
(b = copy(a); @allowscalar b[] = 2; b),
(b = copy(a); @allowscalar b[CartesianIndex()] = 2; b),
Expand All @@ -206,6 +207,8 @@ arrayts = (Array, JLArray)
@test b[Block()] == dev(fill(2))
@test @allowscalar(b[Block()][]) == 2
@test @allowscalar(b[Block()[]]) == 2
@test Array(b) isa Array{elt,0}
@test Array(b) == fill(2)
end
end

Expand Down
Loading