Skip to content

Commit

Permalink
ndarray: fix type convertion in setindex! (#398)
Browse files Browse the repository at this point in the history
Make this case work
```julia
x = mx.NDArray([1, 2, 3]);
x[:] = 1.1
```
  • Loading branch information
iblislin committed Jan 2, 2018
1 parent 930090b commit a1cef7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ end

function setindex!(arr::NDArray, val::Real, ::Colon)
@assert arr.writable
_set_value(out=arr, src=convert(eltype(arr), val))
_set_value(out = arr, src = dump_mx_param(val))
end

function setindex!(arr::NDArray, val::Array{T}, ::Colon) where T<:Real
Expand Down
8 changes: 8 additions & 0 deletions test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ function test_linear_idx()
x[24] = 42
@test copy(x[24]) == [42]
end

info("NDArray::setindex!::type convert")
let
x = NDArray([1, 2, 3])
@test eltype(x) == Int
x[:] = π
@test copy(x) == [3, 3, 3]
end
end # function test_linear_idx

function test_first()
Expand Down

0 comments on commit a1cef7f

Please sign in to comment.