Skip to content

Commit 3cfa420

Browse files
authored
A \ ( c .* B) == c .* (A\B) (#101)
* A \ ( c .* B) == c .* (A\B) * add tests * Update runtests.jl * InfniteArrays v0.11 * Update runtests.jl * Update runtests.jl
1 parent bb69f7b commit 3cfa420

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.8.1"
3+
version = "0.8.2"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/ContinuumArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import LinearAlgebra: pinv, dot, norm2
1313
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
1414
import BlockArrays: block, blockindex, unblock, blockedrange, _BlockedUnitRange, _BlockArray
1515
import FillArrays: AbstractFill, getindex_value, SquareEye
16-
import ArrayLayouts: mul
16+
import ArrayLayouts: mul, ZerosLayout, ScalarLayout
1717
import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclusion, SubQuasiArray,
1818
QuasiDiagonal, MulQuasiArray, MulQuasiMatrix, MulQuasiVector, QuasiMatMulMat,
1919
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle, AbstractQuasiLazyLayout,

src/bases/bases.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ end
115115
A \ ab
116116
end
117117

118+
function _broadcast_mul_ldiv(::Tuple{ScalarLayout,Any}, A, B)
119+
a,b = arguments(B)
120+
a * (A \ b)
121+
end
122+
123+
_broadcast_mul_ldiv(::Tuple{ScalarLayout,AbstractBasisLayout}, A, B) =
124+
_broadcast_mul_ldiv((ScalarLayout(),UnknownLayout()), A, B)
118125
_broadcast_mul_ldiv(_, A, B) = copy(Ldiv{typeof(MemoryLayout(A)),UnknownLayout}(A,B))
119126

120127
copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(*)}}) = _broadcast_mul_ldiv(map(MemoryLayout,arguments(L.B)), L.A, L.B)
@@ -200,14 +207,15 @@ function _factorize(::MappedBasisLayout, L)
200207
MappedFactorization(factorize(view(P,:,jr)), invmap(parentindices(L)[1]))
201208
end
202209

203-
transform_ldiv(A, B, _) = factorize(A) \ B
210+
transform_ldiv(A::AbstractQuasiArray{T}, B::AbstractQuasiArray{V}, _) where {T,V} = factorize(convert(AbstractQuasiArray{promote_type(T,V)}, A)) \ B
204211
transform_ldiv(A, B) = transform_ldiv(A, B, size(A))
205212

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

212220
struct WeightedFactorization{T, WW, FAC<:Factorization{T}} <: Factorization{T}
213221
w::WW

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ end
334334
x = axes(L,1)
335335
@test L[0.123,:]'* (L \ exp.(x)) exp(0.123) atol=1E-9
336336
@test L[0.123,2:end-1]'* (L[:,2:end-1] \ exp.(x)) exp(0.123) atol=1E-9
337+
338+
@test L \ zeros(x) Zeros(10_000)
337339
end
338340
end
339341

@@ -470,6 +472,11 @@ end
470472
@test_throws BoundsError K[Inclusion(0..0.5), Inclusion(0..0.5)][1,1]
471473
end
472474

475+
@testset "A \\ ( c .* B) == c .* (A\\B) #101" begin
476+
L = LinearSpline(0:5)
477+
@test L \ (2L) == 2(L\L)
478+
end
479+
473480
"""
474481
This is a simple implementation of Chebyshev for testing. Use ClassicalOrthogonalPolynomials
475482
for the real implementation.

0 commit comments

Comments
 (0)