Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Julia: deprecate mx.empty, replace it with UndefInitializer constructor #13934

Merged
merged 1 commit into from
Jan 21, 2019

Conversation

iblislin
Copy link
Member

@iblislin iblislin commented Jan 19, 2019

In Julia 0.7+, constructing an uninitialized array is provided via
the APIs:

  • Array{T,N}(undef, dims...)
  • Array{T,N}(undef, dims)
  • Array{T}(undef, dims...)
  • Array{T}(undef, dims)

There is an API mx.empty(dims...) serving for this purpose.

This PR proposes that deprecating the original API mx.empty and
provide the functionality with the API design similar to Julia's Base.

  • NDArray{T,N}(undef, dims...)
  • NDArray{T,N}(undef, dims)
  • NDArray{T}(undef, dims...)
  • NDArray{T}(undef, dims)
  • NDArray(undef, dims...)
  • NDArray(undef, dims)

e.g.

julia> NDArray{Int,2}(undef, 5, 2)
5×2 NDArray{Int64,2} @ CPU0:
 94290755905104  94290752678143
 94290752660544     68719476760
 94290752674408  94290737734368
 94290752660544              18
 94290752674408              18

julia> NDArray(undef, 5, 2)  # default type is `mx.MX_float`
5×2 NDArray{Float32,2} @ CPU0:
 -29112.406f0       5.2029858f-8
      3.0763f-41    6.7375383f-10
      1.7613131f19  0.0f0
      4.840456f30   0.0f0
      4.4262863f30  0.0f0
  • The original mx.empty APIs are still functional.
    If user invokes them, a deprecation warning will be popped up.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

In Julia 0.7+, constructing a uninitialized array is provided via
the APIs:
        - `Array{T,N}(undef, dims...)`
        - `Array{T,N}(undef, dims)`
        - `Array{T}(undef,   dims...)`
        - `Array{T}(undef,   dims)`

There is an API `mx.empty(dims...)` serving for this purpose.

This PR proposes that deprecating the original API `mx.empty` and
provide the functionality with the API design similar to Julia's Base.

        - `NDArray{T,N}(undef, dims...)`
        - `NDArray{T,N}(undef, dims)`
        - `NDArray{T}(undef,   dims...)`
        - `NDArray{T}(undef,   dims)`
        - `NDArray(undef,      dims...)`
        - `NDArray(undef,      dims)`

e.g.

```julia
julia> NDArray{Int,2}(undef, 5, 2)
5×2 NDArray{Int64,2} @ CPU0:
 94290755905104  94290752678143
 94290752660544     68719476760
 94290752674408  94290737734368
 94290752660544              18
 94290752674408              18

julia> NDArray(undef, 5, 2)  # default type is `mx.MX_float`
5×2 NDArray{Float32,2} @ CPU0:
 -29112.406f0       5.2029858f-8
      3.0763f-41    6.7375383f-10
      1.7613131f19  0.0f0
      4.840456f30   0.0f0
      4.4262863f30  0.0f0
```

- The original `mx.empty` APIs are still functional.
  If user invokes them, a deprecation warning will be popped up.
@iblislin iblislin changed the title Julia: deprecate mx.empty, replace it with UndefInitializer Julia: deprecate mx.empty, replace it with UndefInitializer constructor Jan 19, 2019
Copy link
Contributor

@marcoabreu marcoabreu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is backwards compatible, right?

@iblislin
Copy link
Member Author

iblislin commented Jan 21, 2019

Yeah, for instance:

julia> mx.empty(2, 3)
┌ Warning: `mx.empty(dims...)` is deprecated, use `NDArray(undef, dims...)` instead.
└ @ MXNet.mx ~/.julia/dev/MXNet/src/deprecated.jl:193
2×3 NDArray{Float32,2} @ CPU0:
 -2.690016f-37  -2.7809797f-37  4.5f-44
  3.0819f-41     3.0819f-41     0.0f0  

julia> mx.empty((2, 3))
┌ Warning: `mx.empty(dims, ctx)` is deprecated, use `NDArray(undef, dims; ctx = ctx)` instead.
└ @ MXNet.mx ~/.julia/dev/MXNet/src/deprecated.jl:187
2×3 NDArray{Float32,2} @ CPU0:
 -3.1642064f-37  1.7975115f19     8.0f-44
  3.0819f-41     0.00017281323f0  0.0f0

By Julia's convention, any API changes will pop a deprecation warning (we call it depwarn in Julia community) to help user update their code.
Usually, the depwarn will be removed and turned into error in the next package release cycle.

@marcoabreu
Copy link
Contributor

Awesome, thanks. Feel free to merge whenever you are ready

@iblislin iblislin merged commit 372222b into master Jan 21, 2019
@iblislin iblislin deleted the ib/ndarray-undef branch January 21, 2019 14:59
jessr92 pushed a commit to jessr92/incubator-mxnet that referenced this pull request Jan 27, 2019
…he#13934)

In Julia 0.7+, constructing a uninitialized array is provided via
the APIs:
        - `Array{T,N}(undef, dims...)`
        - `Array{T,N}(undef, dims)`
        - `Array{T}(undef,   dims...)`
        - `Array{T}(undef,   dims)`

There is an API `mx.empty(dims...)` serving for this purpose.

This PR proposes that deprecating the original API `mx.empty` and
provide the functionality with the API design similar to Julia's Base.

        - `NDArray{T,N}(undef, dims...)`
        - `NDArray{T,N}(undef, dims)`
        - `NDArray{T}(undef,   dims...)`
        - `NDArray{T}(undef,   dims)`
        - `NDArray(undef,      dims...)`
        - `NDArray(undef,      dims)`

e.g.

```julia
julia> NDArray{Int,2}(undef, 5, 2)
5×2 NDArray{Int64,2} @ CPU0:
 94290755905104  94290752678143
 94290752660544     68719476760
 94290752674408  94290737734368
 94290752660544              18
 94290752674408              18

julia> NDArray(undef, 5, 2)  # default type is `mx.MX_float`
5×2 NDArray{Float32,2} @ CPU0:
 -29112.406f0       5.2029858f-8
      3.0763f-41    6.7375383f-10
      1.7613131f19  0.0f0
      4.840456f30   0.0f0
      4.4262863f30  0.0f0
```

- The original `mx.empty` APIs are still functional.
  If user invokes them, a deprecation warning will be popped up.
stephenrawls pushed a commit to stephenrawls/incubator-mxnet that referenced this pull request Feb 16, 2019
…he#13934)

In Julia 0.7+, constructing a uninitialized array is provided via
the APIs:
        - `Array{T,N}(undef, dims...)`
        - `Array{T,N}(undef, dims)`
        - `Array{T}(undef,   dims...)`
        - `Array{T}(undef,   dims)`

There is an API `mx.empty(dims...)` serving for this purpose.

This PR proposes that deprecating the original API `mx.empty` and
provide the functionality with the API design similar to Julia's Base.

        - `NDArray{T,N}(undef, dims...)`
        - `NDArray{T,N}(undef, dims)`
        - `NDArray{T}(undef,   dims...)`
        - `NDArray{T}(undef,   dims)`
        - `NDArray(undef,      dims...)`
        - `NDArray(undef,      dims)`

e.g.

```julia
julia> NDArray{Int,2}(undef, 5, 2)
5×2 NDArray{Int64,2} @ CPU0:
 94290755905104  94290752678143
 94290752660544     68719476760
 94290752674408  94290737734368
 94290752660544              18
 94290752674408              18

julia> NDArray(undef, 5, 2)  # default type is `mx.MX_float`
5×2 NDArray{Float32,2} @ CPU0:
 -29112.406f0       5.2029858f-8
      3.0763f-41    6.7375383f-10
      1.7613131f19  0.0f0
      4.840456f30   0.0f0
      4.4262863f30  0.0f0
```

- The original `mx.empty` APIs are still functional.
  If user invokes them, a deprecation warning will be popped up.
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
…he#13934)

In Julia 0.7+, constructing a uninitialized array is provided via
the APIs:
        - `Array{T,N}(undef, dims...)`
        - `Array{T,N}(undef, dims)`
        - `Array{T}(undef,   dims...)`
        - `Array{T}(undef,   dims)`

There is an API `mx.empty(dims...)` serving for this purpose.

This PR proposes that deprecating the original API `mx.empty` and
provide the functionality with the API design similar to Julia's Base.

        - `NDArray{T,N}(undef, dims...)`
        - `NDArray{T,N}(undef, dims)`
        - `NDArray{T}(undef,   dims...)`
        - `NDArray{T}(undef,   dims)`
        - `NDArray(undef,      dims...)`
        - `NDArray(undef,      dims)`

e.g.

```julia
julia> NDArray{Int,2}(undef, 5, 2)
5×2 NDArray{Int64,2} @ CPU0:
 94290755905104  94290752678143
 94290752660544     68719476760
 94290752674408  94290737734368
 94290752660544              18
 94290752674408              18

julia> NDArray(undef, 5, 2)  # default type is `mx.MX_float`
5×2 NDArray{Float32,2} @ CPU0:
 -29112.406f0       5.2029858f-8
      3.0763f-41    6.7375383f-10
      1.7613131f19  0.0f0
      4.840456f30   0.0f0
      4.4262863f30  0.0f0
```

- The original `mx.empty` APIs are still functional.
  If user invokes them, a deprecation warning will be popped up.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants