From a163127aad8dacdc7e9348ccb65626e90edf3452 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 22 Dec 2016 12:58:32 -0500 Subject: [PATCH] Make op(Array, Scalar) use broadcast --- base/arraymath.jl | 36 ++---------------------------------- test/broadcast.jl | 2 +- test/linalg/lapack.jl | 2 +- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/base/arraymath.jl b/base/arraymath.jl index e23d8829ad871..3f66ff2bd23c7 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -91,42 +91,10 @@ end for f in (:div, :mod, :rem, :&, :|, :xor, :/, :\, :*, :+, :-) if 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) - RF, RB = eachindex(F), eachindex(B) - if RF == RB - for i in RB - @inbounds F[i] = ($f)(A, B[i]) - end - else - for (iF, iB) in zip(RF, RB) - @inbounds F[iF] = ($f)(A, B[iB]) - end - end - return F - end + @eval ($f){T}(A::Number, B::AbstractArray{T}) = broadcast($f, A, B) end if 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) - RF, RA = eachindex(F), eachindex(A) - if RF == RA - for i in RA - @inbounds F[i] = ($f)(A[i], B) - end - else - for (iF, iA) in zip(RF, RA) - @inbounds F[iF] = ($f)(A[iA], B) - end - end - return F - end + @eval ($f){T}(A::AbstractArray{T}, B::Number) = broadcast($f, A, B) end end diff --git a/test/broadcast.jl b/test/broadcast.jl index 41d40c1c2909d..c7b12a74fadcd 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -186,7 +186,7 @@ let a = Real[2, 2.0, 4//2] / 2 @test eltype(a) == Real end let a = Real[2, 2.0, 4//2] / 2.0 - @test eltype(a) == Real + @test eltype(a) == Float64 end # issue 16164 diff --git a/test/linalg/lapack.jl b/test/linalg/lapack.jl index 26320e3d00bcc..efae0368c8b93 100644 --- a/test/linalg/lapack.jl +++ b/test/linalg/lapack.jl @@ -488,7 +488,7 @@ end @testset "posv and some errors for friends" begin @testset for elty in (Float32, Float64, Complex64, Complex128) - A = 0.01*rand(elty,10,10) + A = rand(elty,10,10)/100 A += real(diagm(10*real(rand(elty,10)))) if elty <: Complex A = A + A'