Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix range bugs for matrix multiply/solve #13833

Merged
merged 1 commit into from
Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -633,6 +633,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 @@ -244,6 +244,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