Skip to content

Expand functions in P'(x .^2 .* P) #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.10'
- 'lts'
- '1'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Infinities = "0.1"
IntervalSets = "0.7"
LazyArrays = "2"
Makie = "0.20, 0.21"
QuasiArrays = "0.11.5"
QuasiArrays = "0.11.8"
RecipesBase = "1.0"
StaticArrays = "1.0"
julia = "1.10"
Expand Down
44 changes: 42 additions & 2 deletions src/bases/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,54 @@
a * (A \ b)
end

_broadcast_mul_ldiv(::Tuple{ScalarLayout,AbstractBasisLayout}, A, B) =
_broadcast_mul_ldiv((ScalarLayout(),UnknownLayout()), A, B)
_broadcast_mul_ldiv(::Tuple{ScalarLayout,AbstractBasisLayout}, A, B) = _broadcast_mul_ldiv((ScalarLayout(),UnknownLayout()), A, B)

Check warning on line 148 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L148

Added line #L148 was not covered by tests
_broadcast_mul_ldiv(_, A, B) = copy(Ldiv{typeof(MemoryLayout(A)),UnknownLayout}(A,B))

copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(*)}}) = _broadcast_mul_ldiv(map(MemoryLayout,arguments(L.B)), L.A, L.B)
copy(L::Ldiv{<:MappedBasisLayouts,BroadcastLayout{typeof(*)}}) = _broadcast_mul_ldiv(map(MemoryLayout,arguments(L.B)), L.A, L.B)



# multiplication operators, reexpand in basis A
@inline function _broadcast_mul_adj(::Tuple{Any,AbstractBasisLayout}, Ac, B)
a,b = arguments(B)
@assert a isa AbstractQuasiVector # Only works for vec .* mat
A = Ac'
ab = (A * (A \ a)) .* b # broadcasted should be overloaded
MemoryLayout(ab) isa BroadcastLayout && return Ac*transform_ldiv(A, ab)
Ac*ab

Check warning on line 163 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L157-L163

Added lines #L157 - L163 were not covered by tests
end

@inline function _broadcast_mul_adj(::Tuple{Any,ApplyLayout{typeof(*)}}, Ac, B)
a,b = arguments(B)
@assert a isa AbstractQuasiVector # Only works for vec .* mat
args = arguments(*, b)
*(Ac*(a .* first(args)), tail(args)...)

Check warning on line 170 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L166-L170

Added lines #L166 - L170 were not covered by tests
end


function _broadcast_mul_adj(::Tuple{ScalarLayout,Any}, Ac, B)
a,b = arguments(B)
a * (Ac*b)

Check warning on line 176 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L174-L176

Added lines #L174 - L176 were not covered by tests
end

function _broadcast_mul_adj(::Tuple{ScalarLayout,ApplyLayout{typeof(*)}}, Ac, B)
a,b = arguments(B)
a * (Ac*b)

Check warning on line 181 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L179-L181

Added lines #L179 - L181 were not covered by tests
end

_broadcast_mul_adj(::Tuple{ScalarLayout,AbstractBasisLayout}, A, B) = _broadcast_mul_adj((ScalarLayout(),UnknownLayout()), A, B)
_broadcast_mul_adj(_, A, B) = copy(Mul{typeof(MemoryLayout(A)),UnknownLayout}(A,B))

Check warning on line 185 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L184-L185

Added lines #L184 - L185 were not covered by tests

_broadcast_mul_adj_simplifiable(_, ::AbstractBasisLayout) = Val(true)
_broadcast_mul_adj_simplifiable(_, ::ApplyLayout{typeof(*)}) = Val(true)
_broadcast_mul_adj_simplifiable(::ScalarLayout, _) = Val(true)
_broadcast_mul_adj_simplifiable(::ScalarLayout, ::ApplyLayout{typeof(*)}) = Val(true)
_broadcast_mul_adj_simplifiable(::ScalarLayout, ::AbstractBasisLayout) = Val(true)
_broadcast_mul_adj_simplifiable(_, _) = Val(false)

Check warning on line 192 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L187-L192

Added lines #L187 - L192 were not covered by tests

simplifiable(L::Mul{<:AdjointBasisLayout,BroadcastLayout{typeof(*)}}) = _broadcast_mul_adj_simplifiable(map(MemoryLayout,arguments(L.B))...)
copy(L::Mul{<:AdjointBasisLayout,BroadcastLayout{typeof(*)}}) = _broadcast_mul_adj(map(MemoryLayout,arguments(L.B)), L.A, L.B)

Check warning on line 195 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L194-L195

Added lines #L194 - L195 were not covered by tests


"""
Expand Down Expand Up @@ -651,6 +690,7 @@
####

simplifiable(::Mul{<:AdjointBasisLayout, <:AbstractBasisLayout}) = Val(true)
@inline simplifiable(L::Mul{<:AdjointBasisLayout,ApplyLayout{typeof(*)}}) = simplifiable(*, L.A, first(arguments(*, L.B)))

Check warning on line 693 in src/bases/bases.jl

View check run for this annotation

Codecov / codecov/patch

src/bases/bases.jl#L693

Added line #L693 was not covered by tests
function copy(M::Mul{<:AdjointBasisLayout, <:AbstractBasisLayout})
A = (M.A)'
A == M.B && return grammatrix(A)
Expand Down
22 changes: 21 additions & 1 deletion test/test_chebyshev.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ContinuumArrays, LinearAlgebra, FastTransforms, QuasiArrays, ArrayLayouts, Base64, LazyArrays, Test
using ContinuumArrays, LinearAlgebra, QuasiArrays, ArrayLayouts, Base64, LazyArrays, Test
using FastTransforms
import ContinuumArrays: Basis, Weight, Map, LazyQuasiArrayStyle, TransformFactorization,
ExpansionLayout, checkpoints, MappedBasisLayout, MappedWeightedBasisLayout,
SubWeightedBasisLayout, WeightedBasisLayout, WeightLayout, basis, grammatrix
Expand Down Expand Up @@ -159,6 +160,25 @@ Base.:(==)(::FooBasis, ::FooBasis) = true

ã = T * (T \ a)
@test T \ (ã .* ã) ≈ [1.5,1,0.5,0,0]

@test T'*(a .* T) isa Matrix
@test T'*(a .* (T * (T \ a))) isa Vector
@test_broken T'f isa Vector
@test T'ã isa Vector
@test T'*(ã .* ã) isa Vector
@test (2T)'*(a .* T) isa Matrix
@test T'*(2T) isa Matrix
@test T'*(2T*randn(5)) isa Vector
@test (2T)'*(T*(1:5)) ≈ T'*(2T*(1:5)) ≈ T'BroadcastQuasiMatrix(*, 2, T*(1:5))
@test T' * (a .* (T * (1:5))) ≈ T' * ((a .* T) * (1:5))
@test T'BroadcastQuasiMatrix(*, 2, 2T) == 4*(T'T)

@test LazyArrays.simplifiable(*, T', T*(1:5)) == Val(true)
@test LazyArrays.simplifiable(*, T', (a .* (T * (1:5)))) == Val(true)
@test LazyArrays.simplifiable(*, T', a .* T) == Val(true)
@test LazyArrays.simplifiable(*, T', 2T) == Val(true)
@test LazyArrays.simplifiable(*, T', BroadcastQuasiMatrix(*, 2, T*(1:5))) == Val(true)
@test LazyArrays.simplifiable(*, T', BroadcastQuasiMatrix(*, 2, 2T)) == Val(true)
end

@testset "sum/dot/diff" begin
Expand Down
2 changes: 1 addition & 1 deletion test/test_splines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
@test Δ == -(*(B',D',D,B))
@test Δ == -(B'D'D*B)
@test Δ == -((B'D')*(D*B))
@test_broken Δ == -B'*(D'D)*B
@test Δ == -B'*(D'D)*B
@test Δ == -(B'*(D'D)*B)

f = L*exp.(L.points) # project exp(x)
Expand Down
Loading