Skip to content

Commit

Permalink
ndarray: type convert of _mul_scalar (#356)
Browse files Browse the repository at this point in the history
Ref: #353
  • Loading branch information
iblislin authored and pluskid committed Dec 4, 2017
1 parent fd7fb79 commit b9855c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,14 @@ broadcast_(::typeof(-), x::Real, y::NDArray) = x - y
Elementwise multiplication into `dst` of either a scalar or an `NDArray` of the same shape.
Inplace updating.
"""
function mul_to!(dst::NDArray{T}, arg::NDArrayOrReal) where T
function mul_to!(dst::NDArray, arg::NDArrayOrReal)
@assert dst.writable
if isa(arg, Real)
_mul_scalar(dst, scalar = convert(T, arg), out = dst)
_mul_scalar(dst, scalar = arg, out = dst)
else
_mul(dst, arg, out = dst)
end
dst
end

import Base: *
Expand Down
7 changes: 7 additions & 0 deletions test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ function test_mul()
y = x .* x
@test copy(y) == [1. 4.]
end

info("NDArray::mul::scalar::type convert")
let x = mx.NDArray([1, 2, 3])
y = x .* π
@test eltype(x) == Int
@test copy(y) == [3, 6, 9]
end
end

function test_div()
Expand Down

0 comments on commit b9855c4

Please sign in to comment.