Skip to content

Commit

Permalink
fix many test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Sep 21, 2016
1 parent ba198f5 commit 47e8eca
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
11 changes: 2 additions & 9 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ imag{T<:Real}(x::AbstractArray{T}) = zero(x)
+{T<:Number}(x::AbstractArray{T}) = x
*{T<:Number}(x::AbstractArray{T,2}) = x

## Binary arithmetic operators ##

*(A::Number, B::AbstractArray) = A .* B
*(A::AbstractArray, B::Number) = A .* B

/(A::AbstractArray, B::Number) = A ./ B

\(A::Number, B::AbstractArray) = B ./ A

# index A[:,:,...,i,:,:,...] where "i" is in dimension "d"

"""
Expand Down Expand Up @@ -446,4 +437,6 @@ end

# aliases so that one only need overload broadcast for ==,!=,<,<=
broadcast(::typeof(>), A, B) = B .< A
broadcast(::typeof(>), A::AbstractArray, B::AbstractArray) = B .< A
broadcast(::typeof(>=), A, B) = B .<= A
broadcast(::typeof(>=), A::AbstractArray, B::AbstractArray) = B .<= A
42 changes: 22 additions & 20 deletions base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ end
promote_array_type(F, ::Type, ::Type, T::Type) = T
promote_array_type{S<:Real, A<:AbstractFloat}(F, ::Type{S}, ::Type{A}, ::Type) = A
promote_array_type{S<:Integer, A<:Integer}(F, ::Type{S}, ::Type{A}, ::Type) = A
promote_array_type{S<:Integer, A<:Integer}(::typeof(/), ::Type{S}, ::Type{A}, T::Type) = T
promote_array_type{S<:Integer, A<:Integer}(::typeof(\), ::Type{S}, ::Type{A}, T::Type) = T
promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) = T
promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T
promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T

for f in (:+, :-, :div, :mod, :&, :|, :$)
Expand All @@ -64,28 +68,26 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray)
return F
end

for f in (:div, :mod, :rem, :&, :|, :$)
@eval begin
function ($f){T}(A::Number, B::AbstractArray{T})
R = promote_op($f, typeof(A), T)
S = promote_array_type($f, typeof(A), T, R)
S === Any && return [($f)(A, b) for b in B]
F = similar(B, S)
for (iF, iB) in zip(eachindex(F), eachindex(B))
@inbounds F[iF] = ($f)(A, B[iB])
end
return F
for f in (:*, :/, :\, :div, :mod, :rem, :&, :|, :$)
f != :/ && @eval function ($f){T}(A::Number, B::AbstractArray{T})
R = promote_op($f, typeof(A), T)
S = promote_array_type($f, typeof(A), T, R)
S === Any && return [($f)(A, b) for b in B]
F = similar(B, S)
for (iF, iB) in zip(eachindex(F), eachindex(B))
@inbounds F[iF] = ($f)(A, B[iB])
end
function ($f){T}(A::AbstractArray{T}, B::Number)
R = promote_op($f, T, typeof(B))
S = promote_array_type($f, typeof(B), T, R)
S === Any && return [($f)(a, B) for a in A]
F = similar(A, S)
for (iF, iA) in zip(eachindex(F), eachindex(A))
@inbounds F[iF] = ($f)(A[iA], B)
end
return F
return F
end
f != :\ && @eval function ($f){T}(A::AbstractArray{T}, B::Number)
R = promote_op($f, T, typeof(B))
S = promote_array_type($f, typeof(B), T, R)
S === Any && return [($f)(a, B) for a in A]
F = similar(A, S)
for (iF, iA) in zip(eachindex(F), eachindex(A))
@inbounds F[iF] = ($f)(A[iA], B)
end
return F
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Base: ReshapedArray, promote_op, setindex_shape_check, to_shape
using Base.Sort: Forward
using Base.LinAlg: AbstractTriangular, PosDefException

import Base: +, -, *, \, /, &, |, $, broadcast
import Base: +, -, *, \, /, &, |, $, broadcast, ==
import Base: A_mul_B!, Ac_mul_B, Ac_mul_B!, At_mul_B, At_mul_B!
import Base: A_mul_Bc, A_mul_Bt, Ac_mul_Bc, At_mul_Bt
import Base: At_ldiv_B, Ac_ldiv_B, A_ldiv_B!
Expand Down
4 changes: 3 additions & 1 deletion base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,12 @@ broadcast(::typeof(*), x::AbstractSparseVector{Bool}, y::BitVector) = _vmul(x, y
# definition of operators

for (op, vop) in [(:+, :_vadd), (:-, :_vsub), (:*, :_vmul)]
@eval begin
op != :* && @eval begin
$(op)(x::AbstractSparseVector, y::AbstractSparseVector) = $(vop)(x, y)
$(op)(x::StridedVector, y::AbstractSparseVector) = $(vop)(x, y)
$(op)(x::AbstractSparseVector, y::StridedVector) = $(vop)(x, y)
end
@eval begin
broadcast(::typeof($op), x::AbstractSparseVector, y::AbstractSparseVector) = $(vop)(x, y)
broadcast(::typeof($op), x::StridedVector, y::AbstractSparseVector) = $(vop)(x, y)
broadcast(::typeof($op), x::AbstractSparseVector, y::StridedVector) = $(vop)(x, y)
Expand Down
3 changes: 2 additions & 1 deletion base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ end
# can be displayed nicely.
function get_test_result(ex)
orig_ex = Expr(:inert, ex)
# Normalize comparison operator calls to :comparison expressions
# Normalize non-dot comparison operator calls to :comparison expressions
if isa(ex, Expr) && ex.head == :call && length(ex.args)==3 &&
first(string(ex.args[1])) != '.' &&
(ex.args[1] === :(==) || Base.operator_precedence(ex.args[1]) == comparison_prec)
testret = :(eval_comparison(Expr(:comparison,
$(esc(ex.args[2])), $(esc(ex.args[1])), $(esc(ex.args[3])))))
Expand Down
10 changes: 5 additions & 5 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ b = rand(6,7)

module RetTypeDecl
using Base.Test
import Base: +, *, .*, convert
import Base: +, *, broadcast, convert

immutable MeterUnits{T,P} <: Number
val::T
Expand All @@ -1513,15 +1513,15 @@ module RetTypeDecl
(+){T,pow}(x::MeterUnits{T,pow}, y::MeterUnits{T,pow}) = MeterUnits{T,pow}(x.val+y.val)
(*){T,pow}(x::Int, y::MeterUnits{T,pow}) = MeterUnits{typeof(x*one(T)),pow}(x*y.val)
(*){T}(x::MeterUnits{T,1}, y::MeterUnits{T,1}) = MeterUnits{T,2}(x.val*y.val)
(.*){T}(x::MeterUnits{T,1}, y::MeterUnits{T,1}) = MeterUnits{T,2}(x.val*y.val)
broadcast{T}(::typeof(*), x::MeterUnits{T,1}, y::MeterUnits{T,1}) = MeterUnits{T,2}(x.val*y.val)
convert{T,pow}(::Type{MeterUnits{T,pow}}, y::Real) = MeterUnits{T,pow}(convert(T,y))

@test @inferred(m+[m,m]) == [m+m,m+m]
@test @inferred([m,m]+m) == [m+m,m+m]
@test @inferred(m.*[m,m]) == [m2,m2]
@test @inferred([m,m].*m) == [m2,m2]
@test @inferred(broadcast(*,m,[m,m])) == [m2,m2]
@test @inferred(broadcast(*,[m,m],m)) == [m2,m2]
@test @inferred([m 2m; m m]*[m,m]) == [3m2,2m2]
@test @inferred([m m].*[m,m]) == [m2 m2; m2 m2]
@test @inferred(broadcast(*,[m m],[m,m])) == [m2 m2; m2 m2]
end

# range, range ops
Expand Down
3 changes: 2 additions & 1 deletion test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ end

# issue #9684
let
undot(op) = Symbol(string(op)[2:end])
for (ex1, ex2) in [("5.≠x", "5.!=x"),
("5.≥x", "5.>=x"),
("5.≤x", "5.<=x")]
ex1 = parse(ex1); ex2 = parse(ex2)
@test ex1.head === :call && (ex1.head === ex2.head)
@test ex1.args[2] === 5 && ex2.args[2] === 5
@test is(eval(Main, ex1.args[1]), eval(Main, ex2.args[1]))
@test is(eval(Main, undot(ex1.args[1])), eval(Main, undot(ex2.args[1])))
@test ex1.args[3] === :x && (ex1.args[3] === ex2.args[3])
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ end
@test (1:2:6) + 0.3 == 1+0.3:2:5+0.3
@test (1:2:6) - 1 == 0:2:4
@test (1:2:6) - 0.3 == 1-0.3:2:5-0.3
@test 2 .- (1:3) == 1:-1:-1
@test 2 - (1:3) == 1:-1:-1

# operations between ranges and arrays
@test all(([1:5;] + (5:-1:1)) .== 6)
Expand Down

0 comments on commit 47e8eca

Please sign in to comment.