Skip to content

Commit

Permalink
ndarray: regularize fill! API (#311)
Browse files Browse the repository at this point in the history
In Base, it's

        fill!(A, x)
  • Loading branch information
iblislin authored and pluskid committed Nov 9, 2017
1 parent 3f93ffc commit 678b49e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

* `fill(x, dims, ctx=cpu())`
* `fill(x, dims...)`
* `fill!(x, arr::NDArray)`
* `fill!(arr::NDArray, x)`

* Matrix (2D NDArray) multiplication is available now. (#TBD)

Expand Down
6 changes: 3 additions & 3 deletions src/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,11 @@ broadcast_(::typeof(^), x::NDArray, s::Irrational) = _power_scalar(x, scalar=s)
broadcast_(::typeof(^), s::Irrational, x::NDArray) = _rpower_scalar(x, scalar=s)

"""
fill!(x, arr::NDArray)
fill!(arr::NDArray, x)
Create an `NDArray` filled with the value `x`, like `Base.fill`.
Create an `NDArray` filled with the value `x`, like `Base.fill!`.
"""
function fill!(x, arr::NDArray)
function Base.fill!(arr::NDArray, x)
arr[:] = x
arr
end
Expand Down
4 changes: 2 additions & 2 deletions test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ function test_fill()
end

info("NDArray::fill!::arr")
let x = mx.fill!(42, mx.zeros(2, 3, 4))
let x = fill!(mx.zeros(2, 3, 4), 42)
@test eltype(x) == Float32
@test size(x) == (2, 3, 4)
@test reldiff(copy(x), fill(Float32(42), 2, 3, 4)) < thresh
@test copy(x) fill(Float32(42), 2, 3, 4)
end
end # function test_fill

Expand Down

0 comments on commit 678b49e

Please sign in to comment.