Skip to content

Commit

Permalink
A \ ( c .* B) == c .* (A\B) (#101)
Browse files Browse the repository at this point in the history
* A \ ( c .* B) == c .* (A\B)

* add tests

* Update runtests.jl

* InfniteArrays v0.11

* Update runtests.jl

* Update runtests.jl
  • Loading branch information
dlfivefifty committed Jun 22, 2021
1 parent bb69f7b commit 3cfa420
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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 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

2 comments on commit 3cfa420

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/39381

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.2 -m "<description of version>" 3cfa420f32111cd078c1ac8786afd988747612ee
git push origin v0.8.2

Please sign in to comment.