@@ -35,20 +35,19 @@ function !(A::AbstractArray{Bool})
35
35
end
36
36
37
37
# # Binary arithmetic operators ##
38
-
39
- promote_array_type {Scalar, Arry} (F, :: Type{Scalar} , :: Type{Arry} ) = promote_op (F, Scalar, Arry)
40
- promote_array_type {S<:Real, A<:AbstractFloat} (F, :: Type{S} , :: Type{A} ) = A
41
- promote_array_type {S<:Integer, A<:Integer} (F, :: Type{S} , :: Type{A} ) = A
42
- promote_array_type {S<:Integer} (F, :: Type{S} , :: Type{Bool} ) = S
43
- promote_array_type (F, :: Type{Bool} , :: Type{Bool} ) = promote_op (F, Bool, Bool)
44
-
45
- # Handle operations that return different types
46
- for f in (:./ , :.\ , :.^ )
47
- @eval ($ f)(x:: Number , Y:: AbstractArray ) =
48
- reshape ((promote_eltype_op ($ f, x, Y))[ ($ f)(x, y) for y in Y ], size (Y))
49
- @eval ($ f)(X:: AbstractArray , y:: Number ) =
50
- reshape ((promote_eltype_op ($ f, X, y))[ ($ f)(x, y) for x in X ], size (X))
51
- end
38
+ promote_array_type {S<:Number, A<:AbstractArray} (F, :: Type{S} , :: Type{A} ) =
39
+ promote_array_type (F, S, eltype (A), promote_op (F, S, eltype (A)))
40
+ promote_array_type {S<:Number, A<:AbstractArray} (F, :: Type{A} , :: Type{S} ) =
41
+ promote_array_type (F, S, eltype (A), promote_op (F, eltype (A), S))
42
+
43
+ promote_array_type {S, A, P} (F, :: Type{S} , :: Type{A} , :: Type{P} ) = P
44
+ promote_array_type {S<:Real, A<:AbstractFloat, P} (F, :: Type{S} , :: Type{A} , :: Type{P} ) = A
45
+ promote_array_type {S<:Integer, A<:Integer, P} (F:: typeof (./ ), :: Type{S} , :: Type{A} , :: Type{P} ) = P
46
+ promote_array_type {S<:Integer, A<:Integer, P} (F:: typeof (.\ ), :: Type{S} , :: Type{A} , :: Type{P} ) = P
47
+ promote_array_type {S<:Integer, A<:Integer, P} (F, :: Type{S} , :: Type{A} , :: Type{P} ) = A
48
+ promote_array_type {S<:Integer, P} (F:: typeof (./ ), :: Type{S} , :: Type{Bool} , :: Type{P} ) = P
49
+ promote_array_type {S<:Integer, P} (F:: typeof (.\ ), :: Type{S} , :: Type{Bool} , :: Type{P} ) = P
50
+ promote_array_type {S<:Integer, P} (F, :: Type{S} , :: Type{Bool} , :: Type{P} ) = P
52
51
53
52
for f in (:+ , :- , :div , :mod , :& , :| , :$ )
54
53
@eval begin
@@ -82,17 +81,17 @@ for f in (:+, :-, :div, :mod, :&, :|, :$)
82
81
end
83
82
end
84
83
end
85
- for f in (:.+ , :.- , :.* , :.÷ , :.% , :.<< , :.>> , :div , :mod , :rem , :& , :| , :$ )
84
+ for f in (:.+ , :.- , :.* , :./ , : .\ , : .^ , : . ÷ , :.% , :.<< , :.>> , :div , :mod , :rem , :& , :| , :$ )
86
85
@eval begin
87
86
function ($ f){T}(A:: Number , B:: AbstractArray{T} )
88
- F = similar (B, promote_array_type ($ f,typeof (A),T ))
87
+ F = similar (B, promote_array_type ($ f,typeof (A),typeof (B) ))
89
88
for (iF, iB) in zip (eachindex (F), eachindex (B))
90
89
@inbounds F[iF] = ($ f)(A, B[iB])
91
90
end
92
91
return F
93
92
end
94
93
function ($ f){T}(A:: AbstractArray{T} , B:: Number )
95
- F = similar (A, promote_array_type ($ f,typeof (B),T ))
94
+ F = similar (A, promote_array_type ($ f,typeof (A), typeof (B) ))
96
95
for (iF, iA) in zip (eachindex (F), eachindex (A))
97
96
@inbounds F[iF] = ($ f)(A[iA], B)
98
97
end
0 commit comments