Skip to content

Commit

Permalink
ndarray: type convertion of _rdiv_scalar (#358)
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 ad57be9 commit 642b17b
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 @@ -680,9 +680,10 @@ end
Elementwise divide a scalar by an `NDArray`. Inplace updating.
"""
function rdiv_from!(x::Real, y::NDArray{T}) where {T}
function rdiv_from!(x::Real, y::NDArray)
@assert y.writable
_rdiv_scalar(y, scalar = convert(T, x), out = y)
_rdiv_scalar(y, scalar = x, out = y)
y
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 @@ -417,6 +417,13 @@ function test_rdiv()
y = 1 ./ Float32[1 2; 3 4]
@test copy(x) y
end

info("NDArray:rdiv::type convert")
let x = mx.NDArray([1, 2, 3])
y = 5.5 ./ x
@test eltype(y) == Int # this differs from julia
@test copy(y) == [5, 2, 1]
end
end # function test_rdiv


Expand Down

0 comments on commit 642b17b

Please sign in to comment.