Skip to content

A \ ( c .* B) == c .* (A\B) #101

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 7 commits into from
Jun 22, 2021
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ContinuumArrays"
uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
version = "0.8.1"
version = "0.8.2"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -21,7 +21,7 @@ ArrayLayouts = "0.7"
BandedMatrices = "0.16"
BlockArrays = "0.15.1"
FillArrays = "0.11"
InfiniteArrays = "0.10"
InfiniteArrays = "0.10, 0.11"
Infinities = "0.1"
IntervalSets = "0.5"
LazyArrays = "0.21"
Expand Down
2 changes: 1 addition & 1 deletion src/ContinuumArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LinearAlgebra: pinv, dot, norm2
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
import BlockArrays: block, blockindex, unblock, blockedrange, _BlockedUnitRange, _BlockArray
import FillArrays: AbstractFill, getindex_value, SquareEye
import ArrayLayouts: mul
import ArrayLayouts: mul, ZerosLayout, ScalarLayout
import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclusion, SubQuasiArray,
QuasiDiagonal, MulQuasiArray, MulQuasiMatrix, MulQuasiVector, QuasiMatMulMat,
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle, AbstractQuasiLazyLayout,
Expand Down
10 changes: 9 additions & 1 deletion src/bases/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ end
A \ ab
end

function _broadcast_mul_ldiv(::Tuple{ScalarLayout,Any}, A, B)
a,b = arguments(B)
a * (A \ b)
end

_broadcast_mul_ldiv(::Tuple{ScalarLayout,AbstractBasisLayout}, A, B) =
_broadcast_mul_ldiv((ScalarLayout(),UnknownLayout()), A, B)
_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)
Expand Down Expand Up @@ -200,14 +207,15 @@ function _factorize(::MappedBasisLayout, L)
MappedFactorization(factorize(view(P,:,jr)), invmap(parentindices(L)[1]))
end

transform_ldiv(A, B, _) = factorize(A) \ B
transform_ldiv(A::AbstractQuasiArray{T}, B::AbstractQuasiArray{V}, _) where {T,V} = factorize(convert(AbstractQuasiArray{promote_type(T,V)}, A)) \ B
transform_ldiv(A, B) = transform_ldiv(A, B, size(A))

copy(L::Ldiv{<:AbstractBasisLayout}) = transform_ldiv(L.A, L.B)
# TODO: redesign to use simplifiable(\, A, B)
copy(L::Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector}) = transform_ldiv(L.A, L.B)
copy(L::Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)}}) = copy(Ldiv{UnknownLayout,ApplyLayout{typeof(*)}}(L.A, L.B))
copy(L::Ldiv{<:AbstractBasisLayout,<:AbstractLazyLayout}) = transform_ldiv(L.A, L.B)
copy(L::Ldiv{<:AbstractBasisLayout,ZerosLayout}) = Zeros{eltype(L)}(axes(L)...)

struct WeightedFactorization{T, WW, FAC<:Factorization{T}} <: Factorization{T}
w::WW
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ end
x = axes(L,1)
@test L[0.123,:]'* (L \ exp.(x)) ≈ exp(0.123) atol=1E-9
@test L[0.123,2:end-1]'* (L[:,2:end-1] \ exp.(x)) ≈ exp(0.123) atol=1E-9

@test L \ zeros(x) ≡ Zeros(10_000)
end
end

Expand Down Expand Up @@ -470,6 +472,11 @@ end
@test_throws BoundsError K[Inclusion(0..0.5), Inclusion(0..0.5)][1,1]
end

@testset "A \\ ( c .* B) == c .* (A\\B) #101" begin
L = LinearSpline(0:5)
@test L \ (2L) == 2(L\L)
end

"""
This is a simple implementation of Chebyshev for testing. Use ClassicalOrthogonalPolynomials
for the real implementation.
Expand Down