Skip to content

Commit

Permalink
ndarray: type convertion of _plus_scalar (#360)
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 b9855c4 commit ad57be9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,11 @@ end
Add a bunch of arguments into `dst`. Inplace updating.
"""
function add_to!(dst::NDArray{T}, args::NDArrayOrReal...) where T
function add_to!(dst::NDArray, args::NDArrayOrReal...)
@assert dst.writable
for arg in args
if isa(arg, Real)
_plus_scalar(dst, scalar = convert(T, arg), out = dst)
_plus_scalar(dst, scalar = arg, out = dst)
else
_plus!(dst, arg)
end
Expand Down
9 changes: 9 additions & 0 deletions test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ function test_plus()
@test copy(x .+ 42) == [43 44; 45 46]
@test copy(0 .+ x .+ y .+ 41) == [43 44; 45 46]
end

info("NDArray::plus::scalar::type convert")
let x = mx.NDArray([1, 2, 3])
y = x .+ 0.5
@test copy(y) == copy(x)

y = x .+ 2.9
@test copy(y) == [3, 4, 5]
end
end

function test_minus()
Expand Down

0 comments on commit ad57be9

Please sign in to comment.