Skip to content

Commit 45a176a

Browse files
mcabbottMichael Abbott
andauthored
MemoryLayout(::AbstractArray) (#11)
* let MemoryLayout act on arrays not just types * allow MemoryLayout(::Any) * actually run the tests before pushing Co-authored-by: Michael Abbott <me@escbook>
1 parent 5a82edf commit 45a176a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/memorylayout.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ in memory is unknown.
140140
Julia's internal linear algebra machinery will automatically (and invisibly)
141141
dispatch to BLAS and LAPACK routines if the memory layout is compatible.
142142
"""
143+
@inline MemoryLayout(A) = MemoryLayout(typeof(A))
144+
143145
@inline MemoryLayout(::Type) = UnknownLayout()
144146

145147
@inline MemoryLayout(::Type{<:Number}) = ScalarLayout()
@@ -474,4 +476,4 @@ colsupport(A, j) = colsupport(MemoryLayout(typeof(A)), A, j)
474476
colsupport(A) = colsupport(A, axes(A,2))
475477

476478
rowsupport(::ZerosLayout, A, _) = 1:0
477-
colsupport(::ZerosLayout, A, _) = 1:0
479+
colsupport(::ZerosLayout, A, _) = 1:0

test/test_layouts.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ struct FooNumber <: Number end
1212

1313
@testset "MemoryLayout" begin
1414
@testset "Trivial" begin
15-
@test MemoryLayout(Float64) == MemoryLayout(Int) == MemoryLayout(FooNumber) == ScalarLayout()
16-
@test MemoryLayout(FooBar) == UnknownLayout()
15+
@test MemoryLayout(3.141) == MemoryLayout(Float64) == MemoryLayout(Int) == MemoryLayout(FooNumber) == ScalarLayout()
16+
@test MemoryLayout(FooBar()) == MemoryLayout(FooBar) == UnknownLayout()
1717

1818
A = randn(6)
1919
@test MemoryLayout(typeof(A)) == MemoryLayout(typeof(Base.ReshapedArray(A,(2,3),()))) ==
20-
MemoryLayout(typeof(reinterpret(Float32,A))) == DenseColumnMajor()
20+
MemoryLayout(typeof(reinterpret(Float32,A))) == MemoryLayout(A) == DenseColumnMajor()
2121

2222
@test MemoryLayout(typeof(view(A,1:3))) == DenseColumnMajor()
2323
@test MemoryLayout(typeof(view(A,Base.OneTo(3)))) == DenseColumnMajor()
@@ -27,7 +27,7 @@ struct FooNumber <: Number end
2727

2828
A = randn(6,6)
2929
V = view(A, 1:3,:)
30-
@test MemoryLayout(typeof(V)) == ColumnMajor()
30+
@test MemoryLayout(typeof(V)) == MemoryLayout(V) == ColumnMajor()
3131
end
3232

3333
@testset "adjoint and transpose MemoryLayout" begin

0 commit comments

Comments
 (0)