diff --git a/Project.toml b/Project.toml index 5a322f9..460518c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ContinuumArrays" uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c" -version = "0.9.3" +version = "0.9.4" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/bases/bases.jl b/src/bases/bases.jl index 2aa6ad5..e80c25f 100644 --- a/src/bases/bases.jl +++ b/src/bases/bases.jl @@ -323,18 +323,34 @@ function _broadcastbasis(::typeof(+), _, _, a, b) end _broadcastbasis(::typeof(+), ::MappedBasisLayouts, ::MappedBasisLayouts, a, b) = broadcastbasis(+, demap(a), demap(b))[basismap(a), :] +function _broadcastbasis(::typeof(+), ::SubBasisLayout, ::SubBasisLayout, a, b) + kr_a,jr_a = parentindices(a) + kr_b,jr_b = parentindices(b) + @assert kr_a == kr_b # frist axes must match + view(broadcastbasis(+, parent(a), parent(b)), kr_a, union(jr_a,jr_b)) +end +_broadcastbasis(::typeof(+), ::SubBasisLayout, _, a, b) = broadcastbasis(+, parent(a), b) +_broadcastbasis(::typeof(+), _, ::SubBasisLayout, a, b) = broadcastbasis(+, a, parent(b)) broadcastbasis(::typeof(+), a, b) = _broadcastbasis(+, MemoryLayout(a), MemoryLayout(b), a, b) +broadcastbasis(::typeof(+), a, b, c...) = broadcastbasis(+, broadcastbasis(+, a, b), c...) broadcastbasis(::typeof(-), a, b) = broadcastbasis(+, a, b) -for op in (:+, :-) - @eval function broadcasted(::LazyQuasiArrayStyle{1}, ::typeof($op), f::Expansion, g::Expansion) - S,c = arguments(f) - T,d = arguments(g) - ST = broadcastbasis($op, S, T) - ST * $op((ST \ S) * c , (ST \ T) * d) - end +@eval function broadcasted(::LazyQuasiArrayStyle{1}, ::typeof(-), f::Expansion, g::Expansion) + S,c = arguments(f) + T,d = arguments(g) + ST = broadcastbasis(-, S, T) + ST * ((ST \ S) * c - (ST \ T) * d) +end + +_plus_P_ldiv_Ps_cs(P, ::Tuple{}, ::Tuple{}) = () +_plus_P_ldiv_Ps_cs(P, Q::Tuple, cs::Tuple) = tuple((P \ first(Q)) * first(cs), _plus_P_ldiv_Ps_cs(P, tail(Q), tail(cs))...) +@eval function broadcasted(::LazyQuasiArrayStyle{1}, ::typeof(+), fs::Expansion...) + Ps = first.(arguments.(fs)) + cs = last.(arguments.(fs)) + P = broadcastbasis(+, Ps...) + P * +(_plus_P_ldiv_Ps_cs(P, Ps, cs)...) # +((Ref(P) .\ Ps .* cs)...) end function broadcasted(::LazyQuasiArrayStyle{1}, ::typeof(*), a::Expansion, f::Expansion) diff --git a/src/bases/splines.jl b/src/bases/splines.jl index 35fd46b..743aeaa 100644 --- a/src/bases/splines.jl +++ b/src/bases/splines.jl @@ -9,6 +9,8 @@ const HeavisideSpline = Spline{0} Spline{o}(pts::AbstractVector{T}) where {o,T} = Spline{o,float(T)}(pts) Spline{o}(S::Spline) where {o} = Spline{o}(S.points) +summary(io::IO, L::LinearSpline) = print(io, "LinearSpline($(L.points))") + axes(B::Spline{o}) where o = (Inclusion(first(B.points)..last(B.points)), OneTo(length(B.points)+o-1)) ==(A::Spline{o}, B::Spline{o}) where o = A.points == B.points diff --git a/test/test_splines.jl b/test/test_splines.jl index 62a9c6f..818cbca 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -97,16 +97,25 @@ using ContinuumArrays, LinearAlgebra, Test @testset "+" begin L = LinearSpline([1,2,3]) - b = L*[3,4,5] + L*[1.,2,3] + b = @inferred(L*[3,4,5] + L*[1.,2,3]) @test ApplyStyle(\, typeof(L), typeof(b)) == LdivStyle() @test (L\b) == [4,6,8] B = BroadcastQuasiArray(+, L, L) @test L\B == 2Eye(3) + @test L*[3,4,5] + L*[1.,2,3] + L*[4,5,6] == @inferred(broadcast(+, L*[3,4,5], L*[1.,2,3], L*[4,5,6])) == L*[8,11,14] + b = L*[3,4,5] - L*[1.,2,3] @test (L\b) == [2,2,2] B = BroadcastQuasiArray(-, L, L) @test L\B == 0Eye(3) + + @testset "sub" begin + v = ApplyQuasiArray(*, L[:,2:end], [1,2]) + f = L * [1,2,3] + @test v + f == f + v == L*[1,3,5] + @test v + v == L*[0,2,4] + end end end