Skip to content

Commit ca07b1a

Browse files
authored
Use size to determine transform dispatch (#63)
* Use size to determine transform dispatch * Update bases.jl * More summarys * add mappedweightrdbasislayout subarray * Update runtests.jl * Update Project.toml * Update bases.jl * Update Project.toml * Update Project.toml * increase coverage * delete unneeded summary
1 parent 48fadba commit ca07b1a

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

Project.toml

Lines changed: 4 additions & 4 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.3.3"
3+
version = "0.3.4"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -13,13 +13,13 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
1414

1515
[compat]
16-
ArrayLayouts = "0.4.7"
16+
ArrayLayouts = "0.4.10"
1717
BandedMatrices = "0.15.17"
1818
FillArrays = "0.9.3, 0.10"
1919
InfiniteArrays = "0.8"
2020
IntervalSets = "0.4, 0.5"
21-
LazyArrays = "0.18"
22-
QuasiArrays = "0.3.4"
21+
LazyArrays = "0.19"
22+
QuasiArrays = "0.3.5"
2323
julia = "1.5"
2424

2525
[extras]

src/ContinuumArrays.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using IntervalSets, LinearAlgebra, LazyArrays, FillArrays, BandedMatrices, Quasi
33
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==, ^,
44
IndexStyle, IndexLinear, ==, OneTo, tail, similar, copyto!, copy, diff,
55
first, last, show, isempty, findfirst, findlast, findall, Slice, union, minimum, maximum, sum, _sum,
6-
getproperty, isone, iszero, zero, abs, <, , >, , string
6+
getproperty, isone, iszero, zero, abs, <, , >, , string, summary
77
import Base.Broadcast: materialize, BroadcastStyle, broadcasted
88
import LazyArrays: MemoryLayout, Applied, ApplyStyle, flatten, _flatten, colsupport, most, combine_mul_styles, AbstractArrayApplyStyle,
99
adjointlayout, arguments, _mul_arguments, call, broadcastlayout, layout_getindex, UnknownLayout,
@@ -113,7 +113,7 @@ end
113113
# Affine map represents A*x .+ b
114114
abstract type AbstractAffineQuasiVector{T,AA,X,B} <: AbstractQuasiVector{T} end
115115

116-
show(io::IO, ::MIME"text/plain", a::AbstractAffineQuasiVector) = print(io, "$(a.A) * $(a.x) .+ ($(a.b))")
116+
summary(io::IO, a::AbstractAffineQuasiVector) = print(io, "$(a.A) * $(a.x) .+ ($(a.b))")
117117

118118
struct AffineQuasiVector{T,AA,X,B} <: AbstractAffineQuasiVector{T,AA,X,B}
119119
A::AA
@@ -229,10 +229,8 @@ const AffineMappedQuasiMatrix = SubQuasiArray{<:Any, 2, <:Any, <:Tuple{AbstractA
229229
_sum(V::AffineMappedQuasiVector, ::Colon) = parentindices(V)[1].A \ sum(parent(V))
230230

231231
# pretty print for bases
232-
show(io::IO, P::AffineMappedQuasiMatrix) = print(io, "$(parent(P)) affine mapped to $(parentindices(P)[1].x.domain)")
233-
show(io::IO, P::AffineMappedQuasiVector) = print(io, "$(parent(P)) affine mapped to $(parentindices(P)[1].x.domain)")
234-
show(io::IO, ::MIME"text/plain", P::AffineMappedQuasiMatrix) = show(io, P)
235-
show(io::IO, ::MIME"text/plain", P::AffineMappedQuasiVector) = show(io, P)
232+
summary(io::IO, P::AffineMappedQuasiMatrix) = print(io, "$(parent(P)) affine mapped to $(parentindices(P)[1].x.domain)")
233+
summary(io::IO, P::AffineMappedQuasiVector) = print(io, "$(parent(P)) affine mapped to $(parentindices(P)[1].x.domain)")
236234

237235
const QInfAxes = Union{Inclusion,AbstractAffineQuasiVector}
238236

src/bases/bases.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MemoryLayout(::Type{<:Weight}) = WeightLayout()
2828
adjointlayout(::Type, ::AbstractBasisLayout) = AdjointBasisLayout()
2929
adjointlayout(::Type, ::SubBasisLayout) = AdjointSubBasisLayout()
3030
adjointlayout(::Type, ::MappedBasisLayouts) = AdjointMappedBasisLayout()
31-
broadcastlayout(::Type{typeof(*)}, ::WeightLayout, ::BasisLayout) = WeightedBasisLayout()
31+
broadcastlayout(::Type{typeof(*)}, ::WeightLayout, ::AbstractBasisLayout) = WeightedBasisLayout()
3232
broadcastlayout(::Type{typeof(*)}, ::WeightLayout, ::SubBasisLayout) = WeightedBasisLayout()
3333
broadcastlayout(::Type{typeof(*)}, ::WeightLayout, ::MappedBasisLayouts) = MappedWeightedBasisLayout()
3434

@@ -64,12 +64,12 @@ end
6464
@inline copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(-)},<:Any,<:AbstractQuasiVector}) =
6565
transform_ldiv(L.A, L.B)
6666

67-
function copy(P::Ldiv{<:AbstractBasisLayout,<:AbstractBasisLayout})
67+
@inline function copy(P::Ldiv{<:AbstractBasisLayout,<:AbstractBasisLayout})
6868
A, B = P.A, P.B
6969
A == B || throw(ArgumentError("Override copy for $(typeof(A)) \\ $(typeof(B))"))
7070
SquareEye{eltype(P)}((axes(A,2),))
7171
end
72-
function copy(P::Ldiv{<:SubBasisLayouts,<:SubBasisLayouts})
72+
@inline function copy(P::Ldiv{<:SubBasisLayouts,<:SubBasisLayouts})
7373
A, B = P.A, P.B
7474
parent(A) == parent(B) ||
7575
throw(ArgumentError("Override copy for $(typeof(A)) \\ $(typeof(B))"))
@@ -91,7 +91,7 @@ end
9191

9292
for Bas1 in (:Basis, :WeightedBasis), Bas2 in (:Basis, :WeightedBasis)
9393
@eval ==(A::SubQuasiArray{<:Any,2,<:$Bas1}, B::SubQuasiArray{<:Any,2,<:$Bas2}) =
94-
all(parentindices(A) == parentindices(B)) && parent(A) == parent(B)
94+
parentindices(A) == parentindices(B) && parent(A) == parent(B)
9595
end
9696

9797

@@ -132,7 +132,7 @@ TransformFactorization(grid, ::Nothing, iplan) =
132132

133133
grid(T::TransformFactorization) = T.grid
134134

135-
\(a::TransformFactorization{<:Any,<:Any,Nothing}, b::AbstractQuasiVector) = a.iplan \ convert(Array, b[a.grid])
135+
\(a::TransformFactorization{<:Any,<:Any,Nothing}, b::AbstractQuasiVector{T}) where T = a.iplan \ convert(Array{T}, b[a.grid])
136136
\(a::TransformFactorization, b::AbstractQuasiVector) = a.plan * convert(Array, b[a.grid])
137137

138138
\(a::TransformFactorization{<:Any,<:Any,Nothing}, b::AbstractVector) = a.iplan \ b
@@ -159,7 +159,7 @@ _factorize(::SubBasisLayout, L) = ProjectionFactorization(factorize(parent(L)),
159159
# end
160160

161161
transform_ldiv(A, B, _) = factorize(A) \ B
162-
transform_ldiv(A, B) = transform_ldiv(A, B, axes(A))
162+
transform_ldiv(A, B) = transform_ldiv(A, B, size(A))
163163

164164
copy(L::Ldiv{<:AbstractBasisLayout,<:Any,<:Any,<:AbstractQuasiVector}) =
165165
transform_ldiv(L.A, L.B)
@@ -271,8 +271,9 @@ end
271271
# we represent as a Mul with a banded matrix
272272
sublayout(::AbstractBasisLayout, ::Type{<:Tuple{<:Inclusion,<:AbstractUnitRange}}) = SubBasisLayout()
273273
sublayout(::AbstractBasisLayout, ::Type{<:Tuple{<:AbstractAffineQuasiVector,<:AbstractUnitRange}}) = MappedBasisLayout()
274-
sublayout(::WeightedBasisLayout, ::Type{<:Tuple{<:AbstractAffineQuasiVector,<:AbstractUnitRange}}) = MappedWeightedBasisLayout()
274+
sublayout(::WeightedBasisLayouts, ::Type{<:Tuple{<:AbstractAffineQuasiVector,<:AbstractUnitRange}}) = MappedWeightedBasisLayout()
275275
sublayout(::WeightedBasisLayout, ::Type{<:Tuple{<:Inclusion,<:AbstractUnitRange}}) = SubWeightedBasisLayout()
276+
sublayout(::MappedWeightedBasisLayout, ::Type{<:Tuple{<:Inclusion,<:AbstractUnitRange}}) = MappedWeightedBasisLayout()
276277

277278
@inline sub_materialize(::AbstractBasisLayout, V::AbstractQuasiArray) = V
278279
@inline sub_materialize(::AbstractBasisLayout, V::AbstractArray) = V

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ end
158158
@test f[2.1] 2
159159

160160
@test @inferred(H'H) == @inferred(materialize(applied(*,H',H))) == Eye(2)
161+
@test summary(f) == "(Spline{0,Float64,Array{$Int,1}}) * (2-element Array{$Int,1})"
161162
end
162163

163164
@testset "LinearSpline" begin
@@ -339,6 +340,7 @@ end
339340
@testset "sub-of-sub" begin
340341
L = LinearSpline([1,2,3])
341342
V = view(L,:,1:2)
343+
@test V == V
342344
V2 = view(V,1.1:0.1:2,:)
343345
@test V2 == L[1.1:0.1:2,1:2]
344346
end
@@ -468,7 +470,7 @@ end
468470
H = HeavisideSpline([1,2,3,6])
469471
B = H[5x .+ 1,:]
470472
u = H * [1,2,3]
471-
@test stringmime("text/plain", B) == "Spline{0,Float64,Array{Int64,1}}([1, 2, 3, 6]) affine mapped to 0..1"
473+
@test stringmime("text/plain", B) == "Spline{0,Float64,Array{Int64,1}} affine mapped to 0..1"
472474
end
473475
end
474476

@@ -525,9 +527,13 @@ Base.broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), a::Expansion{<:Any,<:Che
525527
end
526528
@testset "Mapped" begin
527529
y = affine(0..1, x)
530+
531+
@test summary(T[y,:]) == "Chebyshev affine mapped to 0..1"
528532
@test MemoryLayout(wT[y,:]) isa MappedWeightedBasisLayout
529533
@test MemoryLayout(w[y] .* T[y,:]) isa MappedWeightedBasisLayout
530534
@test wT[y,:][[0.1,0.2],1:5] == (w[y] .* T[y,:])[[0.1,0.2],1:5] == (w .* T[:,1:5])[y,:][[0.1,0.2],:]
535+
@test MemoryLayout(wT[y,1:3]) isa MappedWeightedBasisLayout
536+
@test wT[y,1:3][[0.1,0.2],1:2] == wT[y[[0.1,0.2]],1:2]
531537
end
532538

533539
@testset "Broadcasted" begin

0 commit comments

Comments
 (0)