Skip to content

Commit

Permalink
Merge pull request #13833 from artkuo/rangemulsol
Browse files Browse the repository at this point in the history
fix range bugs for matrix multiply/solve
  • Loading branch information
andreasnoack committed Nov 12, 2015
2 parents 5393150 + 392b1a3 commit 0d2ea5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function naivesub!{T}(A::Bidiagonal{T}, b::AbstractVector, x::AbstractVector = b
x
end

function \{T,S}(A::Bidiagonal{T}, B::AbstractVecOrMat{S})
function \{T,S}(A::Bidiagonal{T}, B::StridedVecOrMat{S})
TS = typeof(zero(T)*zero(S) + zero(T)*zero(S))
TS == S ? A_ldiv_B!(A, copy(B)) : A_ldiv_B!(A, convert(AbstractArray{TS}, B))
end
Expand Down
4 changes: 4 additions & 0 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ end
./(r::FloatRange, x::Real) = FloatRange(r.start/x, r.step/x, r.len, r.divisor)
./(r::LinSpace, x::Real) = LinSpace(r.start / x, r.stop / x, r.len, r.divisor)

# Matrix multiplication/solve on ranges, A*r should treat r as collected vector
*{T}(A::AbstractArray{T, 2}, r::Range) = A*collect(r)
\{T}(A::AbstractArray{T, 2}, r::Range) = A\collect(r)

promote_rule{T1,T2}(::Type{UnitRange{T1}},::Type{UnitRange{T2}}) =
UnitRange{promote_type(T1,T2)}
convert{T}(::Type{UnitRange{T}}, r::UnitRange{T}) = r
Expand Down
5 changes: 5 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ end
@test all(([1:5;] - (1:5)) .== 0)
@test all(((1:5) - [1:5;]) .== 0)

# matrix multiplication between matrix and range, e.g. A*r
@test [1 2 3;]*(1:3) == [14]
# and a matrix solve A\r
@test [1 0; 0 1]\linspace(1,2,2) [1., 2.]

# tricky floating-point ranges

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

0 comments on commit 0d2ea5c

Please sign in to comment.