We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0b786d7 commit 0d11eecCopy full SHA for 0d11eec
2 files changed
src/abstractblocksparsearray/unblockedsubarray.jl
@@ -27,6 +27,27 @@ function TypeParameterAccessors.similartype(arraytype::Type{<:UnblockedSubArray}
27
return similartype(blocktype(parenttype(arraytype)), elt)
28
end
29
30
+function Base.similar(
31
+ a::UnblockedSubArray, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}}
32
+)
33
+ return similar(similartype(blocktype(parenttype(a)), elt), axes)
34
+end
35
+function Base.similar(a::UnblockedSubArray, elt::Type, size::Tuple{Int,Vararg{Int}})
36
+ return similar(a, elt, Base.OneTo.(size))
37
38
+
39
+function ArrayLayouts.sub_materialize(a::UnblockedSubArray)
40
+ a_cpu = adapt(Array, a)
41
+ a_cpu′ = similar(a_cpu)
42
+ a_cpu′ .= a_cpu
43
+ if typeof(a) === typeof(a_cpu)
44
+ return a_cpu′
45
+ end
46
+ a′ = similar(a)
47
+ a′ .= a_cpu′
48
+ return a′
49
50
51
function Base.map!(
52
f, a_dest::AbstractArray, a_src1::UnblockedSubArray, a_src_rest::UnblockedSubArray...
53
)
test/test_basics.jl
@@ -56,7 +56,6 @@ arrayts = (Array, JLArray)
56
a[Block(1, 1)] = dev(randn(elt, 2, 2))
57
a[Block(2, 2)] = dev(randn(elt, 3, 3))
58
@test_broken a[:, [2, 4]]
59
- @test_broken a[[3, 5], [2, 4]]
60
61
# TODO: Fix this and turn it into a proper test.
62
a = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))
@@ -713,6 +712,13 @@ arrayts = (Array, JLArray)
713
712
@test a[Block(2, 2)[1:2, 2:3]] == b
714
@test blockstoredlength(a) == 1
715
+ # Non-contiguous slicing.
716
+ a = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))
717
+ a[Block(1, 1)] = dev(randn(elt, 2, 2))
718
+ a[Block(2, 2)] = dev(randn(elt, 3, 3))
719
+ I = ([3, 5], [2, 4])
720
+ @test a[I...] == Array(a)[I...]
721
722
a = BlockSparseArray{elt}(undef, [2, 3], [2, 3])
723
@views for b in [Block(1, 1), Block(2, 2)]
724
a[b] = randn(elt, size(a[b]))
0 commit comments