Skip to content

Commit 3eb6cf5

Browse files
authored
UniformScaling, _broadcast_mul_mul with scalars (#75)
* _broadcast_mul_mul with scalars * UniformScaling * add tests
1 parent b879cea commit 3eb6cf5

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuasiArrays"
22
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.7"
4+
version = "0.7.1"
55

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

src/quasibroadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ BroadcastStyle(::Type{<:SubArray{T,N,P,I}}) where {T,N,P<:AbstractQuasiArray,I}
175175

176176
# support (x .* D) * y
177177
__broadcast_mul_mul(::Val{false}, (a,B), C) = ApplyQuasiArray(*, a .* B, C)
178-
__broadcast_mul_mul(::Val{true}, (a,B)::Tuple{AbstractQuasiVector,AbstractQuasiMatrix}, C) = a .* (B*C)
178+
__broadcast_mul_mul(::Val{true}, (a,B)::Tuple{Union{AbstractQuasiVector,Number},AbstractQuasiMatrix}, C) = a .* (B*C)
179179
__broadcast_mul_mul(::Val{true}, (A,b)::Tuple{AbstractQuasiMatrix,AbstractQuasiVector}, C) = b .* (A*C)
180-
LazyArrays._broadcast_mul_mul((a,B)::Tuple{AbstractQuasiVector,AbstractQuasiMatrix}, C) = __broadcast_mul_mul(simplifiable(*, B, C), (a,B), C)
180+
LazyArrays._broadcast_mul_mul((a,B)::Tuple{Union{AbstractQuasiVector,Number},AbstractQuasiMatrix}, C) = __broadcast_mul_mul(simplifiable(*, B, C), (a,B), C)
181181
LazyArrays._broadcast_mul_mul((A,b)::Tuple{AbstractQuasiMatrix,AbstractQuasiVector}, C) = __broadcast_mul_mul(simplifiable(*, A, C), (A,b), C)
182182

183183

src/quasifill.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ isone(::QuasiEye) = true
181181
@inline QuasiEye{T}(A::AbstractQuasiMatrix) where T = QuasiEye{T}(axes(A))
182182
@inline QuasiEye(A::AbstractQuasiMatrix) = QuasiEye{eltype(A)}(axes(A))
183183

184+
quasiscaling(J, ax) = QuasiDiagonal(QuasiFill(J.λ, ax))
185+
186+
for op in (:+, :-, :*, :/, :\)
187+
@eval begin
188+
$op(A::AbstractQuasiMatrix, J::UniformScaling) = $op(A, quasiscaling(J, axes(A,2)))
189+
$op(J::UniformScaling, A::AbstractQuasiMatrix) = $op(quasiscaling(J, axes(A,1)), A)
190+
end
191+
end
192+
184193

185194
#########
186195
# Special matrix types

test/test_quasifill.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ import QuasiArrays: AbstractQuasiFill
157157
@test A[[1,3],1] Ones{Int}(2)
158158
@test A[[1,3],[3,4]] Ones{Int}(2,2)
159159
@test_throws BoundsError A[1:26]
160-
160+
161161
A = QuasiZeros{Int}(ax,ax)
162162
@test A[[1,3],1] Zeros{Int}(2)
163163
@test A[[1,3],[3,4]] Zeros{Int}(2,2)
@@ -297,7 +297,7 @@ import QuasiArrays: AbstractQuasiFill
297297
@test QuasiZeros(ax,bx) * A isa QuasiZeros
298298
@test B * QuasiZeros(bx,cx) isa QuasiZeros
299299
@test_throws DimensionMismatch B * QuasiZeros(ax, ax)
300-
300+
301301
# Check multiplication by Adjoint vectors works as expected.
302302
@test QuasiArray(randn(3, 4),ax,bx)' * QuasiZeros(ax) === QuasiZeros(bx)
303303
@test QuasiArray(randn(4),bx)' * QuasiZeros(bx) == zero(Float64)
@@ -690,5 +690,18 @@ import QuasiArrays: AbstractQuasiFill
690690
@testset "Static eval" begin
691691
o = QuasiOnes([1,3,4])
692692
@test view(o,SVector(1,3)) o[SVector(1,3)] Ones((SOneTo(2),))
693-
end
693+
end
694+
695+
@testset "UniformScaling" begin
696+
A = QuasiArray(randn(3,3), 0:0.5:1,0:0.5:1)
697+
@test A+2I 2I+A QuasiArray(A.parent+2I, 0:0.5:1,0:0.5:1)
698+
@test A-2I -(2I-A) QuasiArray(A.parent-2I, 0:0.5:1,0:0.5:1)
699+
@test A*(2I) (2I)*A 2A
700+
@test A/(2I) (2I)\A A/2
701+
702+
B = QuasiArray(randn(3,3), 0:0.5:1,1:0.5:2)
703+
@test_throws DimensionMismatch B+I
704+
@test_throws DimensionMismatch I+B
705+
@test B*I I*B B
706+
end
694707
end

0 commit comments

Comments
 (0)