Skip to content

Commit 04ac7e8

Browse files
authored
Support lmul!/rmul! when data is not #undef (#467)
* Support lmul!/rmul! when data is not defined * Check for primitive type
1 parent c4e85f4 commit 04ac7e8

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-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 = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "1.9.0"
3+
version = "1.9.1"
44

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

src/generic/broadcast.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ function _banded_broadcast_BandedColumn!(dest, f, src, z)
357357
end
358358

359359
function _banded_broadcast!(dest::AbstractMatrix, f, (src,x)::Tuple{AbstractMatrix{T},Number}, ::BandedColumns, ::BandedColumns) where T
360+
isprimitivetype(T) || return _banded_broadcast!(dest, f, (src, x), BandedLayout(), BandedLayout())
360361
z = f(zero(T),x)
361362
iszero(z) || checkbroadcastband(dest, size(src), bandwidths(broadcasted(f, src,x)))
362363

@@ -367,6 +368,8 @@ function _banded_broadcast!(dest::AbstractMatrix, f, (src,x)::Tuple{AbstractMatr
367368
end
368369

369370
function _banded_broadcast!(dest::AbstractMatrix, f, (x, src)::Tuple{Number,AbstractMatrix{T}}, ::BandedColumns, ::BandedColumns) where T
371+
isprimitivetype(T) || return _banded_broadcast!(dest, f, (x, src), BandedLayout(), BandedLayout())
372+
370373
z = f(x, zero(T))
371374
iszero(z) || checkbroadcastband(dest, size(src), bandwidths(broadcasted(f, x,src)))
372375

@@ -824,12 +827,14 @@ function _banded_broadcast(f, A::AbstractMatrix{T}, ::BandedColumns) where T
824827
_BandedMatrix(Bdata_new, axes(A,1), bandwidths(A)...)
825828
end
826829
function _banded_broadcast(f, (src,x)::Tuple{AbstractMatrix{T},Number}, ::BandedColumns) where T
830+
isprimitivetype(T) || return _banded_broadcast(f, (src,x), BandedLayout())
827831
iszero(f(zero(T),x)) || return _default_banded_broadcast(broadcasted(f, src,x))
828832
Bdata = bandeddata(src)
829833
Bdata_new = reshape(f.(vec(Bdata), x), size(Bdata))
830834
_BandedMatrix(Bdata_new, axes(src,1), bandwidths(src)...)
831835
end
832836
function _banded_broadcast(f, (x, src)::Tuple{Number,AbstractMatrix{T}}, ::BandedColumns) where T
837+
isprimitivetype(T) || return _banded_broadcast(f, (x,src), BandedLayout())
833838
iszero(f(x, zero(T))) || return _default_banded_broadcast(broadcasted(f, x,src))
834839
Bdata = bandeddata(src)
835840
Bdata_new = reshape(f.(x, vec(Bdata)), size(Bdata))
@@ -935,12 +940,20 @@ end
935940

936941

937942
function _banded_lmul!::Number, A::AbstractMatrix, ::BandedColumns)
938-
lmul!(α, bandeddata(A))
943+
if !isprimitivetype(eltype(A))
944+
_banded_lmul!(α, A, BandedLayout()) # avoid undefined
945+
else
946+
lmul!(α, bandeddata(A))
947+
end
939948
A
940949
end
941950

942951
function _banded_rmul!(A::AbstractMatrix, α::Number, ::BandedColumns)
943-
rmul!(bandeddata(A), α)
952+
if !isprimitivetype(eltype(A))
953+
_banded_rmul!(A, α, BandedLayout()) # avoid undefined
954+
else
955+
rmul!(bandeddata(A), α)
956+
end
944957
A
945958
end
946959

test/test_broadcasting.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ Random.seed!(0)
770770
@test_throws BandError B[band(100)] .= 10
771771
@test_throws BandError B[band(-100)] .= 10
772772
end
773+
774+
@testset "BigFloat l/rmul!" begin
775+
A = BandedMatrices._BandedMatrix(Matrix{BigFloat}(undef, 3, 5), 5, 1, 1)
776+
for j = axes(A,2), k = colsupport(A,j)
777+
A[k,j] = 1
778+
end
779+
B = 2A
780+
@test B == A*2
781+
lmul!(2, A)
782+
@test A == B
783+
rmul!(A, 2)
784+
@test A == 2B
785+
end
773786
end
774787

775788
end # module

0 commit comments

Comments
 (0)