@@ -286,14 +286,30 @@ end
286286function Base. broadcasted (
287287 :: typeof (Base. literal_pow),
288288 f:: Function ,
289- arg1:: Tensor ,
290- arg2:: Val{P} ,
291- ) where {P}
292- return Base. broadcasted (f, arg1, P)
289+ base:: Tensor ,
290+ exponent:: Val{E} ,
291+ ) where {E}
292+ return Base. broadcasted (f, base, E)
293+ end
294+
295+ function Base. broadcasted (:: typeof (^ ), base:: Tensor , exponent:: Union{Int,Rational{Int}} )
296+ return Power (base, exponent)
293297end
294298
295- function Base. broadcasted (:: typeof (^ ), base:: Tensor , power:: Int )
296- return Power (base, power)
299+ function Base.:(^ )(base:: Tensor , exponent:: Union{Int,Rational{Int}} )
300+ if ! isempty (get_free_indices (base))
301+ throw (DomainError (base, " is not a scalar, use .^ for element-wise power" ))
302+ end
303+
304+ return Power (base, exponent)
305+ end
306+
307+ function Base. literal_pow (f:: typeof (^ ), base:: Tensor , exponent:: Val{E} ) where {E}
308+ if ! isempty (get_free_indices (base))
309+ throw (DomainError (base, " is not a scalar, use .^ for element-wise power" ))
310+ end
311+
312+ return Power (base, E)
297313end
298314
299315function replace_letters (arg:: BinaryOperation{Mult} , letter_map:: Dict )
0 commit comments