Skip to content

Commit 6a4a8c0

Browse files
authored
Only use transform_ldiv when feasible (#114)
* Only use transform_ldiv when feasible * Update bases.jl * Update bases.jl * WeightLayout transform_ldiv * transform only if finite dimensional columns * tests pass * Increase coverage * Update Project.toml
1 parent 3348817 commit 6a4a8c0

File tree

8 files changed

+588
-552
lines changed

8 files changed

+588
-552
lines changed

Project.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ContinuumArrays"
22
uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
3-
version = "0.8.7"
3+
version = "0.9.0"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -17,15 +17,15 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1717
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1818

1919
[compat]
20-
ArrayLayouts = "0.7"
20+
ArrayLayouts = "0.7.2"
2121
BandedMatrices = "0.16"
22-
BlockArrays = "0.15.1, 0.16"
22+
BlockArrays = "0.16"
2323
FillArrays = "0.11, 0.12"
24-
InfiniteArrays = "0.10, 0.11"
24+
InfiniteArrays = "0.11"
2525
Infinities = "0.1"
2626
IntervalSets = "0.5"
27-
LazyArrays = "0.21"
28-
QuasiArrays = "0.6, 0.7"
27+
LazyArrays = "0.21.13"
28+
QuasiArrays = "0.7"
2929
RecipesBase = "1.0"
3030
StaticArrays = "1.0"
3131
julia = "1.6"

src/ContinuumArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import BlockArrays: block, blockindex, unblock, blockedrange, _BlockedUnitRange,
1515
import FillArrays: AbstractFill, getindex_value, SquareEye
1616
import ArrayLayouts: mul, ZerosLayout, ScalarLayout
1717
import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclusion, SubQuasiArray,
18-
QuasiDiagonal, MulQuasiArray, MulQuasiMatrix, MulQuasiVector, QuasiMatMulMat,
18+
QuasiDiagonal, MulQuasiArray, MulQuasiMatrix, MulQuasiVector, QuasiMatMulMat, QuasiArrayLayout,
1919
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle, AbstractQuasiLazyLayout,
2020
LazyQuasiArray, LazyQuasiVector, LazyQuasiMatrix, LazyLayout, LazyQuasiArrayStyle, _factorize,
2121
AbstractQuasiFill, UnionDomain, __sum
@@ -78,6 +78,7 @@ end
7878
@inline to_indices(A::AbstractQuasiArray, inds, I::Tuple{AbstractArray{<:BlockIndex{1}}, Vararg{Any}}) =
7979
(inds[1][I[1]], to_indices(A, _maybetail(inds), tail(I))...)
8080

81+
checkpoints(x::Number) = x
8182
checkpoints(d::AbstractInterval{T}) where T = width(d) .* SVector{3,float(T)}(0.823972,0.01,0.3273484) .+ leftendpoint(d)
8283
checkpoints(d::UnionDomain) = mapreduce(checkpoints,union,d.domains)
8384
checkpoints(x::Inclusion) = checkpoints(x.domain)

src/bases/bases.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ end
5757

5858

5959
@inline copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)}}) = +(broadcast(\,Ref(L.A),arguments(L.B))...)
60-
@inline copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)},<:Any,<:AbstractQuasiVector}) =
60+
@inline copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)},<:Any,<:AbstractQuasiVector}) =
6161
transform_ldiv(L.A, L.B)
6262
for op in (:+, :-)
6363
@eval @inline copy(L::Ldiv{Lay,BroadcastLayout{typeof($op)},<:Any,<:AbstractQuasiVector}) where Lay<:MappedBasisLayouts =
@@ -75,7 +75,7 @@ end
7575
@inline function copy(P::Ldiv{<:AbstractBasisLayout,<:AbstractBasisLayout})
7676
A, B = P.A, P.B
7777
A == B || throw(ArgumentError("Override copy for $(typeof(A)) \\ $(typeof(B))"))
78-
SquareEye{eltype(eltype(P))}((axes(A,2),)) # use double eltype for array-valued
78+
SquareEye{eltype(eltype(P))}((axes(A,2),)) # use double eltype for array-valued
7979
end
8080
@inline function copy(P::Ldiv{<:SubBasisLayouts,<:SubBasisLayouts})
8181
A, B = P.A, P.B
@@ -97,12 +97,15 @@ copy(L::Ldiv{<:MappedBasisLayouts,ApplyLayout{typeof(*)}}) = copy(Ldiv{UnknownLa
9797
copy(L::Ldiv{<:MappedBasisLayouts,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = transform_ldiv(L.A, L.B)
9898

9999
@inline copy(L::Ldiv{<:AbstractBasisLayout,<:SubBasisLayouts}) = apply(\, L.A, ApplyQuasiArray(L.B))
100-
@inline function copy(L::Ldiv{<:SubBasisLayouts,<:AbstractBasisLayout})
100+
@inline function copy(L::Ldiv{<:SubBasisLayouts,<:AbstractBasisLayout})
101101
P = parent(L.A)
102102
kr, jr = parentindices(L.A)
103103
layout_getindex(apply(\, P, L.B), jr, :) # avoid sparse arrays
104104
end
105105

106+
# default to transform for expanding weights
107+
copy(L::Ldiv{<:AbstractBasisLayout,WeightLayout}) = transform_ldiv(L.A, L.B)
108+
106109

107110
for Bas1 in (:Basis, :WeightedBasis), Bas2 in (:Basis, :WeightedBasis)
108111
@eval ==(A::SubQuasiArray{<:Any,2,<:$Bas1}, B::SubQuasiArray{<:Any,2,<:$Bas2}) =
@@ -185,7 +188,7 @@ associates a planned inverse transform with a grid. That is, if `F` is a `Transf
185188
"""
186189
TransformFactorization(grid, ::Nothing, iplan) = TransformFactorization{promote_type(eltype(eltype(grid)),eltype(iplan))}(grid, nothing, iplan)
187190

188-
grid(T::TransformFactorization) = T.grid
191+
grid(T::TransformFactorization) = T.grid
189192

190193
\(a::TransformFactorization{<:Any,<:Any,Nothing}, b::AbstractQuasiVector{T}) where T = a.iplan \ convert(Array{T}, b[a.grid])
191194
\(a::TransformFactorization, b::AbstractQuasiVector) = a.plan * convert(Array, b[a.grid])
@@ -259,13 +262,20 @@ copy(L::Ldiv{<:AbstractBasisLayout}) = transform_ldiv(L.A, L.B)
259262
# TODO: redesign to use simplifiable(\, A, B)
260263
copy(L::Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = transform_ldiv(L.A, L.B)
261264
copy(L::Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)}}) = copy(Ldiv{UnknownLayout,ApplyLayout{typeof(*)}}(L.A, L.B))
262-
copy(L::Ldiv{<:AbstractBasisLayout,<:AbstractLazyLayout}) = transform_ldiv(L.A, L.B)
265+
# A BroadcastLayout of unknown function is only knowable pointwise
266+
transform_ldiv_if_columns(A, B, _) = ApplyQuasiArray(\, A, B)
267+
transform_ldiv_if_columns(A, B, ::Base.OneTo) = transform_ldiv(A,B)
268+
copy(L::Ldiv{<:AbstractBasisLayout,<:BroadcastLayout}) = transform_ldiv_if_columns(L.A, L.B, axes(L.B,2))
269+
# Inclusion are QuasiArrayLayout
270+
copy(L::Ldiv{<:AbstractBasisLayout,QuasiArrayLayout}) = transform_ldiv(L.A, L.B)
271+
# Otherwise keep lazy to support, e.g., U\D*T
272+
copy(L::Ldiv{<:AbstractBasisLayout,<:AbstractLazyLayout}) = ApplyQuasiArray(\, L.A, L.B)
263273
copy(L::Ldiv{<:AbstractBasisLayout,ZerosLayout}) = Zeros{eltype(L)}(axes(L)...)
264274

265275
"""
266276
WeightedFactorization(w, F)
267277
268-
weights a factorization `F` by `w`.
278+
weights a factorization `F` by `w`.
269279
"""
270280
struct WeightedFactorization{T, WW, FAC<:Factorization{T}} <: Factorization{T}
271281
w::WW
@@ -416,7 +426,7 @@ demap(x) = x
416426
demap(x::BroadcastQuasiArray) = BroadcastQuasiArray(x.f, map(demap, arguments(x))...)
417427
demap(V::SubQuasiArray{<:Any,2,<:Any,<:Tuple{Any,Slice}}) = parent(V)
418428
demap(V::SubQuasiArray{<:Any,1}) = parent(V)
419-
function demap(V::SubQuasiArray{<:Any,2})
429+
function demap(V::SubQuasiArray{<:Any,2})
420430
kr, jr = parentindices(V)
421431
demap(parent(V)[kr,:])[:,jr]
422432
end
@@ -466,7 +476,7 @@ end
466476
####
467477

468478

469-
function __sum(::SubBasisLayout, Vm, dims)
479+
function __sum(::SubBasisLayout, Vm, dims)
470480
@assert dims == 1
471481
sum(parent(Vm); dims=dims)[:,parentindices(Vm)[2]]
472482
end

src/bases/splines.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const LinearSpline = Spline{1}
77
const HeavisideSpline = Spline{0}
88

99
Spline{o}(pts::AbstractVector{T}) where {o,T} = Spline{o,float(T)}(pts)
10+
Spline{o}(S::Spline) where {o} = Spline{o}(S.points)
1011

1112
axes(B::Spline{o}) where o =
1213
(Inclusion(first(B.points)..last(B.points)), OneTo(length(B.points)+o-1))

0 commit comments

Comments
 (0)