Skip to content

Commit 725b9be

Browse files
authored
Update for New ArrayLayouts (#38)
* Start updating for new LazyArrays/ArrayLayouts * getindex for Mul * tests pass! * Add indextype, fix bugs * Improve copy * MulQuasiArray * Number * Simplify Mul routines * Fix for Julia v1.5 * Update test_quasilazy.jl * Update matmul.jl * Remove fullmaterialize * Update lazyquasiarrays.jl * Update QuasiArrays.jl * update Project * Remove stale code * Test number reduce, add / and \ * Update test_quasilazy.jl * Broadcasted -> broadcasted, add QuasiArray constructors * Fix broadcast2broadcastarray * specify layout for arguments * Update Project.toml
1 parent d7e95cc commit 725b9be

13 files changed

+168
-254
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ os:
55
- osx
66
- windows
77
julia:
8-
- 1.3
98
- 1.5
109
- nightly
1110
matrix:

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name = "QuasiArrays"
22
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
33
authors = ["Sheehan Olver <solver@mac.com>"]
4-
version = "0.2.3"
4+
version = "0.3.0"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
88
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010

1111
[compat]
12-
ArrayLayouts = "0.2.4, 0.3"
13-
LazyArrays = "0.16.3"
14-
julia = "1.3"
12+
ArrayLayouts = "0.4.3"
13+
LazyArrays = "0.17"
14+
julia = "1.5"
1515

1616
[extras]
1717
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"

src/QuasiArrays.jl

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module QuasiArrays
2-
using Base, LinearAlgebra, LazyArrays
2+
using Base, LinearAlgebra, LazyArrays, ArrayLayouts
33
import Base: getindex, size, axes, axes1, length, ==, isequal, iterate, CartesianIndices, LinearIndices,
44
Indices, IndexStyle, getindex, setindex!, parent, vec, convert, similar, copy, copyto!, zero,
55
map, eachindex, eltype, first, last, firstindex, lastindex, in, reshape, all,
@@ -33,14 +33,15 @@ import LinearAlgebra: transpose, adjoint, checkeltype_adjoint, checkeltype_trans
3333
AbstractTriangular, pinv, inv, promote_leaf_eltypes, power_by_squaring,
3434
integerpow, schurpow, tr, factorize
3535

36-
import LazyArrays: MemoryLayout, UnknownLayout, Mul, ApplyLayout, BroadcastLayout, ,
37-
lmaterialize, _lmaterialize, InvOrPInv, ApplyStyle, AbstractLazyLayout, LazyLayout,
38-
FlattenMulStyle, IdentityMulStyle, MulAddStyle, LazyArrayApplyStyle,
36+
import ArrayLayouts: indextype, concretize
37+
import LazyArrays: MemoryLayout, UnknownLayout, Mul, ApplyLayout, BroadcastLayout,
38+
InvOrPInv, ApplyStyle, AbstractLazyLayout, LazyLayout,
39+
MulStyle, MulAddStyle, LazyArrayApplyStyle, combine_mul_styles, DefaultArrayApplyStyle,
3940
Applied, flatten, _flatten, arguments, _mat_mul_arguments, _vec_mul_arguments,
4041
rowsupport, colsupport, tuple_type_memorylayouts, applylayout, broadcastlayout,
41-
LdivApplyStyle, most, InvLayout, PInvLayout, sub_materialize,
42+
LdivStyle, most, InvLayout, PInvLayout, sub_materialize, lazymaterialize,
4243
_mul, rowsupport, DiagonalLayout, adjointlayout, transposelayout, conjlayout,
43-
sublayout, call, combine_mul_styles, result_mul_style, LazyArrayStyle, layout_getindex
44+
sublayout, call, LazyArrayStyle, layout_getindex, _broadcast2broadcastarray
4445

4546
import Base.IteratorsMD
4647

@@ -49,25 +50,7 @@ export AbstractQuasiArray, AbstractQuasiMatrix, AbstractQuasiVector, materialize
4950
QuasiAdjoint, QuasiTranspose, ApplyQuasiArray, ApplyQuasiMatrix, ApplyQuasiVector,
5051
BroadcastQuasiArray, BroadcastQuasiMatrix, BroadcastQuasiVector, indextype
5152

52-
if VERSION < v"1.3-"
53-
"""
54-
broadcast_preserving_zero_d(f, As...)
55-
56-
Like [`broadcast`](@ref), except in the case of a 0-dimensional result where it returns a 0-dimensional container
57-
58-
Broadcast automatically unwraps zero-dimensional results to be just the element itself,
59-
but in some cases it is necessary to always return a container — even in the 0-dimensional case.
60-
"""
61-
function broadcast_preserving_zero_d(f, As...)
62-
bc = broadcasted(f, As...)
63-
r = materialize(bc)
64-
return length(axes(bc)) == 0 ? fill!(similar(bc, typeof(r)), r) : r
65-
end
66-
broadcast_preserving_zero_d(f) = fill(f())
67-
broadcast_preserving_zero_d(f, as::Number...) = fill(f(as...))
68-
else
69-
import Base.Broadcast: broadcast_preserving_zero_d
70-
end
53+
import Base.Broadcast: broadcast_preserving_zero_d
7154

7255
abstract type AbstractQuasiArray{T,N} end
7356
AbstractQuasiVector{T} = AbstractQuasiArray{T,1}

src/abstractquasiarray.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ convert(::Type{AbstractArray{T,N}}, a::AbstractQuasiArray{<:Any,N}) where {T,N}
4242
convert(::Type{AbstractMatrix}, a::AbstractQuasiMatrix) = convert(AbstractArray, a)
4343
convert(::Type{AbstractVector}, a::AbstractQuasiVector) = convert(AbstractArray, a)
4444

45-
indextype(A::AbstractQuasiArray) = Tuple{map(eltype, axes(A))...}
46-
4745

4846
"""
4947
size(A::AbstractQuasiArray, [dim])

src/inv.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11

2-
ApplyStyle(::typeof(\), ::Type{A}, ::Type{B}) where {A<:AbstractQuasiArray,B<:AbstractQuasiArray} =
3-
quasildivapplystyle(MemoryLayout(A), MemoryLayout(B))
4-
ApplyStyle(::typeof(\), ::Type{A}, ::Type{B}) where {A<:AbstractQuasiArray,B<:AbstractArray} =
5-
quasildivapplystyle(MemoryLayout(A), MemoryLayout(B))
6-
ApplyStyle(::typeof(\), ::Type{A}, ::Type{B}) where {A<:AbstractArray,B<:AbstractQuasiArray} =
7-
quasildivapplystyle(MemoryLayout(A), MemoryLayout(B))
2+
ApplyStyle(::typeof(\), ::Type{<:AbstractQuasiArray}, ::Type{<:AbstractQuasiArray}) = LdivStyle()
3+
ApplyStyle(::typeof(\), ::Type{<:AbstractArray}, ::Type{<:AbstractQuasiArray}) = LdivStyle()
4+
ApplyStyle(::typeof(\), ::Type{<:AbstractQuasiArray}, ::Type{<:AbstractArray}) = LdivStyle()
85

9-
quasildivapplystyle(_, _) = LdivApplyStyle()
106

117
similar(L::Ldiv, ::Type{T}, axes::Tuple{<:AbstractQuasiVector,<:AbstractQuasiVector}) where T = similar(QuasiArray{T}, axes)
128
similar(L::Ldiv, ::Type{T}, axes::Tuple{<:AbstractQuasiVector,<:AbstractVector}) where T = similar(QuasiArray{T}, axes)
@@ -53,8 +49,6 @@ pinv(A::PInvQuasiMatrix) = first(A.args)
5349
@propagate_inbounds getindex(A::PInvQuasiMatrix{T}, k::Int, j::Int) where T =
5450
(Applied(A)*[Zeros(j-1); one(T); Zeros(size(A,2) - j)])[k]
5551

56-
*(A::PInvQuasiMatrix, B::AbstractQuasiMatrix, C...) = apply(*,Applied(A), B, C...)
57-
*(A::PInvQuasiMatrix, B::MulQuasiArray, C...) = apply(*,Applied(A), Applied(B), C...)
5852

5953
## QuasiArray special case
6054
inv(A::QuasiMatrix) = QuasiArray(inv(A.parent), reverse(A.axes))

src/lazyquasiarrays.jl

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const LazyQuasiMatrix{T} = LazyQuasiArray{T,2}
1919

2020
struct LazyQuasiArrayApplyStyle <: AbstractQuasiArrayApplyStyle end
2121

22+
abstract type AbstractQuasiLazyLayout <: AbstractLazyLayout end
2223
struct QuasiLazyLayout <: AbstractLazyLayout end
2324

2425
MemoryLayout(::Type{<:LazyQuasiArray}) = QuasiLazyLayout()
25-
26+
lazymaterialize(F, args::Union{AbstractQuasiArray,AbstractArray}...) = copy(ApplyQuasiArray(F, args...))
27+
concretize(A::AbstractQuasiArray) = convert(QuasiArray, A)
2628

2729
###
2830
# ApplyQuasiArray
@@ -61,13 +63,10 @@ ApplyQuasiMatrix(f, factors...) = ApplyQuasiMatrix(applied(f, factors...))
6163

6264
axes(A::ApplyQuasiArray) = axes(Applied(A))
6365
size(A::ApplyQuasiArray) = map(length, axes(A))
64-
copy(A::ApplyQuasiArray) = copy(Applied(A))
65-
66-
@propagate_inbounds getindex(A::ApplyQuasiArray{T,N}, kj::Vararg{Number,N}) where {T,N} =
67-
Applied(A)[kj...]
66+
copy(A::ApplyQuasiArray) = A # immutable arrays don't need to copy
6867

69-
@propagate_inbounds getindex(A::ApplyQuasiArray{T,N}, kj::QuasiCartesianIndex{N}) where {T,N} =
70-
A[kj.I...]
68+
@propagate_inbounds _getindex(::Type{IND}, A::ApplyQuasiArray, I::IND) where {M,IND} =
69+
Applied(A)[I...]
7170

7271
MemoryLayout(M::Type{ApplyQuasiArray{T,N,F,Args}}) where {T,N,F,Args} =
7372
applylayout(F, tuple_type_memorylayouts(Args)...)
@@ -104,7 +103,6 @@ BroadcastQuasiArray{T,N}(bc::Broadcasted{Style,Axes,F,Args}) where {T,N,Style,Ax
104103
BroadcastQuasiArray{T}(bc::Broadcasted{<:Union{Nothing,BroadcastStyle},<:Tuple{Vararg{Any,N}},<:Any,<:Tuple}) where {T,N} =
105104
BroadcastQuasiArray{T,N}(bc)
106105

107-
_broadcast2broadcastarray(a, b...) = tuple(a, b...)
108106
_broadcast2broadcastarray(a::Broadcasted{<:LazyQuasiArrayStyle}, b...) = tuple(BroadcastQuasiArray(a), b...)
109107

110108
_BroadcastQuasiArray(bc::Broadcasted) = BroadcastQuasiArray{combine_eltypes(bc.f, bc.args)}(bc)
@@ -113,15 +111,14 @@ BroadcastQuasiArray(bc::Broadcasted{S}) where S =
113111
BroadcastQuasiArray(b::BroadcastQuasiArray) = b
114112
BroadcastQuasiArray(f, A, As...) = BroadcastQuasiArray(broadcasted(f, A, As...))
115113

116-
Broadcasted(A::BroadcastQuasiArray) = instantiate(broadcasted(A.f, A.args...))
117-
114+
broadcasted(A::BroadcastQuasiArray) = instantiate(broadcasted(A.f, A.args...))
118115

119-
axes(A::BroadcastQuasiArray) = axes(Broadcasted(A))
116+
axes(A::BroadcastQuasiArray) = axes(broadcasted(A))
120117
size(A::BroadcastQuasiArray) = map(length, axes(A))
121118

122119
IndexStyle(::BroadcastQuasiArray{<:Any,1}) = IndexLinear()
123120

124-
@propagate_inbounds getindex(A::BroadcastQuasiArray, kj::Number...) = Broadcasted(A)[kj...]
121+
@propagate_inbounds getindex(A::BroadcastQuasiArray, kj::Number...) = broadcasted(A)[kj...]
125122
@propagate_inbounds getindex(A::BroadcastQuasiArray{T,N}, kj::QuasiCartesianIndex{N}) where {T,N} =
126123
A[kj.I...]
127124

@@ -141,19 +138,12 @@ BroadcastStyle(::Type{<:LazyQuasiArray{<:Any,N}}) where N = LazyQuasiArrayStyle{
141138
MemoryLayout(M::Type{BroadcastQuasiArray{T,N,F,Args}}) where {T,N,F,Args} =
142139
broadcastlayout(F, tuple_type_memorylayouts(Args)...)
143140

141+
arguments(b::BroadcastLayout, V::SubQuasiArray) = LazyArrays._broadcast_sub_arguments(V)
144142

145143
###
146144
# *
147145
###
148146

149-
combine_mul_styles(::QuasiLazyLayout) = LazyQuasiArrayApplyStyle()
150-
result_mul_style(::LazyQuasiArrayApplyStyle, ::LazyQuasiArrayApplyStyle) = LazyQuasiArrayApplyStyle()
151-
result_mul_style(::LazyQuasiArrayApplyStyle, ::MulAddStyle) = LazyQuasiArrayApplyStyle()
152-
result_mul_style(::MulAddStyle, ::LazyQuasiArrayApplyStyle) = LazyQuasiArrayApplyStyle()
153-
result_mul_style(::LazyQuasiArrayApplyStyle, ::LazyArrayApplyStyle) = LazyQuasiArrayApplyStyle()
154-
result_mul_style(::LazyArrayApplyStyle, ::LazyQuasiArrayApplyStyle) = LazyQuasiArrayApplyStyle()
155-
result_mul_style(::LazyQuasiArrayApplyStyle, _) = LazyQuasiArrayApplyStyle()
156-
result_mul_style(_, ::LazyQuasiArrayApplyStyle) = LazyQuasiArrayApplyStyle()
157147

158148
ndims(M::Applied{LazyQuasiArrayApplyStyle,typeof(*)}) = ndims(last(M.args))
159149

@@ -164,6 +154,8 @@ arguments(a::AbstractQuasiArray) = arguments(MemoryLayout(typeof(a)), a)
164154
arguments(::ApplyLayout{typeof(*)}, V::SubQuasiArray{<:Any,2}) = _mat_mul_arguments(V)
165155
arguments(::ApplyLayout{typeof(*)}, V::SubQuasiArray{<:Any,1}) = _vec_mul_arguments(V)
166156

157+
ApplyQuasiArray(M::Mul) = ApplyQuasiArray(*, M.A, M.B)
158+
QuasiArray(M::Mul) = QuasiArray(ApplyQuasiArray(M))
167159

168160
###
169161
# ^

0 commit comments

Comments
 (0)