Skip to content

Commit 1c8b423

Browse files
authored
copy of subarray should call sub_materialize (#59)
* copy of subarray should call sub_materialize * Update ArrayLayouts.jl * test adjtrans copy
1 parent 79e2012 commit 1c8b423

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.6.2"
4+
version = "0.6.3"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/ArrayLayouts.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ include("factorizations.jl")
102102
@inline sub_materialize(V::SubArray) = sub_materialize(MemoryLayout(V), V)
103103
@inline sub_materialize(V::AbstractArray) = V # Anything not a SubArray is already materialized
104104

105+
copy(A::SubArray{<:Any,N,<:LayoutArray}) where N = sub_materialize(A)
106+
copy(A::SubArray{<:Any,N,<:AdjOrTrans{<:Any,<:LayoutArray}}) where N = sub_materialize(A)
107+
105108
@inline layout_getindex(A, I...) = sub_materialize(view(A, I...))
106109

107110
macro _layoutgetindex(Typ)

test/test_layoutarray.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ArrayLayouts, LinearAlgebra, Test
2+
import ArrayLayouts: sub_materialize
23

34
struct MyMatrix <: LayoutMatrix{Float64}
45
A::Matrix{Float64}
@@ -42,8 +43,12 @@ MemoryLayout(::Type{MyVector}) = DenseColumnMajor()
4243

4344
@test a'a == transpose(a)a == dot(a,a) == dot(a,a.A) == dot(a.A,a) == 14
4445
v = view(a,1:3)
46+
@test copy(v) == sub_materialize(v) == a[1:3]
4547
@test dot(v,a) == dot(v,a.A) == dot(a,v) == dot(a.A,v) == dot(v,v) == 14
4648

49+
V = view(a',:,1:3)
50+
@test copy(V) == sub_materialize(V) == (a')[:,1:3]
51+
4752
s = SparseVector(3, [1], [2])
4853
@test a's == s'a == dot(a,s) == dot(s,a) == dot(s,a.A)
4954
end

0 commit comments

Comments
 (0)