Skip to content

Commit 392b1a3

Browse files
committed
fix range bugs for matrix multiply/solve, with AbstractMatrix
1 parent d0f9e12 commit 392b1a3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

base/linalg/bidiag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function naivesub!{T}(A::Bidiagonal{T}, b::AbstractVector, x::AbstractVector = b
262262
x
263263
end
264264

265-
function \{T,S}(A::Bidiagonal{T}, B::AbstractVecOrMat{S})
265+
function \{T,S}(A::Bidiagonal{T}, B::StridedVecOrMat{S})
266266
TS = typeof(zero(T)*zero(S) + zero(T)*zero(S))
267267
TS == S ? A_ldiv_B!(A, copy(B)) : A_ldiv_B!(A, convert(AbstractArray{TS}, B))
268268
end

base/range.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ end
633633
./(r::FloatRange, x::Real) = FloatRange(r.start/x, r.step/x, r.len, r.divisor)
634634
./(r::LinSpace, x::Real) = LinSpace(r.start / x, r.stop / x, r.len, r.divisor)
635635

636+
# Matrix multiplication/solve on ranges, A*r should treat r as collected vector
637+
*{T}(A::AbstractArray{T, 2}, r::Range) = A*collect(r)
638+
\{T}(A::AbstractArray{T, 2}, r::Range) = A\collect(r)
639+
636640
promote_rule{T1,T2}(::Type{UnitRange{T1}},::Type{UnitRange{T2}}) =
637641
UnitRange{promote_type(T1,T2)}
638642
convert{T}(::Type{UnitRange{T}}, r::UnitRange{T}) = r

test/ranges.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ end
244244
@test all(([1:5;] - (1:5)) .== 0)
245245
@test all(((1:5) - [1:5;]) .== 0)
246246

247+
# matrix multiplication between matrix and range, e.g. A*r
248+
@test [1 2 3;]*(1:3) == [14]
249+
# and a matrix solve A\r
250+
@test [1 0; 0 1]\linspace(1,2,2) [1., 2.]
251+
247252
# tricky floating-point ranges
248253

249254
@test [0.1:0.1:0.3;] == [linspace(0.1,0.3,3);] == [1:3;]./10

0 commit comments

Comments
 (0)