|
1 | 1 | using ArrayLayouts: LayoutArray
|
2 | 2 | using BlockArrays: blockisequal
|
3 |
| -using DerivableInterfaces: @interface, interface |
| 3 | +using DerivableInterfaces: @interface, AbstractArrayInterface, interface |
4 | 4 | using LinearAlgebra: Adjoint, Transpose
|
5 | 5 | using SparseArraysBase: SparseArraysBase, SparseArrayStyle
|
6 | 6 |
|
@@ -49,15 +49,30 @@ function reblock(
|
49 | 49 | return @view parent(a)[map(I -> Vector(I.blocks), parentindices(a))...]
|
50 | 50 | end
|
51 | 51 |
|
| 52 | +# `map!` specialized to zero-dimensional inputs. |
| 53 | +function map_zero_dim! end |
| 54 | + |
| 55 | +@interface ::AbstractArrayInterface function map_zero_dim!( |
| 56 | + f, a_dest::AbstractArray, a_srcs::AbstractArray... |
| 57 | +) |
| 58 | + a_dest[] = f.(map(a_src -> a_src[], a_srcs)...) |
| 59 | + return a_dest |
| 60 | +end |
| 61 | + |
52 | 62 | # TODO: Move to `blocksparsearrayinterface/map.jl`.
|
53 | 63 | # TODO: Rewrite this so that it takes the blocking structure
|
54 | 64 | # made by combining the blocking of the axes (i.e. the blocking that
|
55 | 65 | # is used to determine `union_stored_blocked_cartesianindices(...)`).
|
56 | 66 | # `reblock` is a partial solution to that, but a bit ad-hoc.
|
57 | 67 | ## TODO: Make this an `@interface AbstractBlockSparseArrayInterface` function.
|
58 |
| -@interface ::AbstractBlockSparseArrayInterface function Base.map!( |
| 68 | +@interface interface::AbstractBlockSparseArrayInterface function Base.map!( |
59 | 69 | f, a_dest::AbstractArray, a_srcs::AbstractArray...
|
60 | 70 | )
|
| 71 | + if iszero(ndims(a_dest)) |
| 72 | + @interface interface map_zero_dim!(f, a_dest, a_srcs...) |
| 73 | + return a_dest |
| 74 | + end |
| 75 | + |
61 | 76 | a_dest, a_srcs = reblock(a_dest), reblock.(a_srcs)
|
62 | 77 | for I in union_stored_blocked_cartesianindices(a_dest, a_srcs...)
|
63 | 78 | BI_dest = blockindexrange(a_dest, I)
|
|
0 commit comments