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

Numpy take operator implementation & bug fix in ndarray.take #15567

Closed
wants to merge 46 commits into from

Conversation

hgt312
Copy link
Contributor

@hgt312 hgt312 commented Jul 17, 2019

Description

Implementation of numpy take operator in mxnet.
Fix a bug that backward computation of ndarray.take does not check argument mode.

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

Changes

  • add op take
  • bug fix of nd.take
  • auto remove some whitespaces

Comments

Welcome @reminisce, @haojin2 and others for reviewing.

haojin2 and others added 30 commits June 3, 2019 23:10
* Add numpy namespace and initial impl of np.sum (not complete)

* Clean up

* Fix import error

* numpy sum

* add test and backward data type support

* add license to test_numpy_op.py

* improve test to reduce flakiness

* fix sanity build

* extra numeric test and imperative test

* add error message for initial argument
…PIs (apache#14758)

* Infra of new ndarray and symbol types for numpy operators

* Rename

* Fix import problem

* Refactor

* Remove redundant code

* Add docstring

* More on numpy ndarray and symbol

* Override unimplemented methdos for ndarray and _NumpySymbol

* Fix built-in methods of ndarray and _NumpySymbol

* Fix test and sanity check

* Fix pylint

* Address cr comments

* Add unit tests for ndarray and _NumpySymbol

* Add _true_divide

* Fix gpu build

* Add future import division

* More correct way of checking if an output is from a np compat op

* Fix gpu build

* Fix output ndarray/symbol types with at least one new ndarray/symbol

* Modify true_divide doc

* Fix flaky copying zero-size arrays via gpus

* Fix zero size in gluon hybridize and zeros/ones symbol not creating new symbol type

* Fix doc
* Numpy Dot case 1-4 + case 3.5 forward and 0.5 backward

* Backward computation and test coverage
* Add np transpose

More ops and namespaces for submodules

Add relu and sigmoid

Add reshape

Fix symbolic name mismatch

Add maximum and minimum

* Add convenience fluent method

* Add ndarray.item()

* Fix CI

* Fix lint

* Fix lint

* Fix reshape gpu

* Add example

* Remove python notebook outputs

* Remove notebook output

* Add one more example
* Refactor

* Initial refactoring

* Fix notebook

* Move numpy op check from backend to frontend

* Add homogeneous ndarray check

* Fix grouping inhomogeneous types of symbols

* Improve error handling of different types of symbols as outputs

* Fix test

* Fix numpy test

* Fix ci

* Try to fix gpu ci failure
* Refactor notebook

* notebook working with hybrid block

* More refactoring

* Remove unnecessary use_np_compat

* Use class decorator to initialize numpy ndarrays in parameter.py

* Clear notebook outputs

* Improve np decorator

* Remove npe op from optimizer

* Fix CI

* Fix functools.wraps issue in Python2

* Fix ci
* numpy stack

* migrate to use_np_shape
* Unary Ops

* new version of unit tests
* Add np_array semantics for Gluon

Fix notebook

Fix sanity

Fix gluon deferred infer shape

Add np.random.uniform

Add random normal

Add boolean comparison ops

Add np.ndarray indexing

Reformat test ndarray indexing

Fix unit tests

Add one more test of indexing

Fix sanity

Enable amp test

Add np.arange

Revert cython unit test to ctypes

Delete unnecessary use_np_shape decorator from test

Rebase with numpy branch

support range as index

Fix python2 range type check

Add argmax

Disable clojure test

* Fix ci

* Add np.linalg.norm for ord='fro'

* Fix pylint
* Fix

* Fix linear regression gluon

* More fix

* Fix pylint

* Fix for chapter 4

* Add np.add mul div mod pow sub and shuffle

* Fix model selection, underfitting, overfitting

* Fix weight decay

* Fix dropout

* Fix

* Fix chapter 4
* Add np array adapter decorator for layers

* Fix performance regression caused by too many conversions between nd.NDArray and np.ndarray

* Fix pylint

* Fix test backward compatibility issue

* Fix test_lambda
* Add np op doc

* Fix several issues

* Add a N-D dot b 2D support

* Simplify array creation api

* Add swapaxes

* Fix rnn gluon

* More fix

* Fix pylint

* Delete

* Fix mp windows
* numpy split

* numpy split

* unit test

* unit test
* Add npx batch_dot and topk

* Text embedding uses numpy

* Fix SoftmaxCrossEntropyLoss with np

* Fix sentiment cnn

* Fix pylint

* Fix dot attention

* Fix seq2seq attention

* Add np.tile

* Fix transformer

* Fix ci

* Fix ci and rebase
* Fix parameter initializer

* Add np.save and np.load

* Fix read-write

* Fix lint
* numpy amax

* weird cu file diff

* fix the unit test error

* fix gpu bug

* minor fix

* fix lint

* remove scalar value check

* fix the bug on unit test

* fix the case () that breaks the kernel launch

* add zero dimension unit test

* revert the tuple change

* use mshadow maximum

* remove test zero

* change the macro for now

* change the cuda to use mashadow op

* fix the broadcast_reduce_op_value.cu wrong kernel

* add more logic in shape to detect the invalid situation

* change back to type swtich

* change to as_nd_ndarray

* add missing @npx.use_np_shape

* retrigger CI

* address the comment

* undo algorithm import

* remove the numeric gradient check
* draft of multinomial

* rename to more concise name

* finish shape

* complete the forward function

* complete forward without handle 0 dimension & scalar

* handle 0 dimension

* add new line

* fix lint

* fix the build error

* fix lint

* finish unit test

* change the registration

* make multinomial support pvals as mx.ndarray

* delete newline

* fix lint error

* support input as list, mx.ndarray, np.ndarray & unit test

* fix lint

* fix the include error

* fix lint

* refactor & pass the tensor instead of tuple to kernel

* fix lint

* updata the doc

* address the comment
* draft

* finish linspace implementation

* finish linspace

* delete newline

* fix pylint

* add more unit test

* address comment

* add more test case

* disable too-many-arguments

* resolve confliction

* add ctx
* Add np.prod

* Fix ndarray.reshape accepting positional integers as arguments

* Rebase

* Fix rebase error

* Add np.ndarray.flatten

* Fix

* Add broadcast_to

* Add meshgrid and broadcast_arrays

* Fix sin, cos, sinh, cosh not supporting scalars

* Add more unary ops supporting python scalars

* Fix

* Fix

* Fix ci

* Fix sanity
* Change op name style to lower case underscore

* Add ops under image to npx

* Add image submodule to npx

* Fix split_and_load use np

* Fix fine tuning

* Fix bbox and anchor

* Fix odd

* Fix ssd and rcnn

* Remove restriction on binary element-wise scalar

* Fix gan

* Fix sanity

* Try to fix website build failure

* Add npx.random.seed

* Fix doc
reminisce and others added 11 commits June 28, 2019 01:08
* add cython support for numpy

* stay with original API for backward compatibility
…15382)

* seven numpy docs finished

* Style partly fixed

* Style fixed; example output updated according to new output style

* Style fixed; added scalar input support for np.tile

* End of file spare line fixed

* Fixed according to comments

* Fixed according to comments

* Removed dead code according to comment

* `out` param comment modified

* trailing newline fixed

* Function signature override fixed

* Mistype typo fixed

* Removed duplicate functions due to rebase

* Fixed signature of tile; minor refinement in style

* Fixed tile typo for sanity check
apache#15370)

* Doc fix for split, stack, transpose, mean, rint, radians, log2.

* Minor syntax fix

* Add some disable=line-too-long to pass pylint test

* Add Notes following the guide of example PR by Mu Li

* Minor syntax fix

* Fix a non-ascii character

* Fix issues mentioned in review by @reminisce

* Register mean into npi namespace and wrap it to have same sigatrue as
standard numpy

* Add mean to __all__ list

* Note the imcompatibility of broacasting to output

* Specify out must have the same type

* Minor syntax fix

* Clearify the `out` in symbol is only a dummy variable

Fix the mess due to pull rebase

Correct the wrong return statement in multiarray

Again, syntax fix

Syntax fix one more time
…apache#15377)

* add _np_zeros_like

some fix on '_np_zeros_like'
add '_npi_linspace'

try reciprocal

improve `zeros_like`

improve `linspace`

try build

try build by delete `see also` in python/mxnet/context.py

square & reciprocal

finish reciprocal

finish square

finish arcsin

revert context.py

fix 2 mistakes

bug fix for `linspace` and render

unify docs

try _np_linspace

fix some mistakes in _numpy_op_doc.py

remove `see also` sections from symbol docs.
remove _npi_linspace from _numpy_op_doc

fix `_numpy_op_doc`.
fix `zeros_like`

fix `linspace`

finish reciprocal.

fix `square`.

fix `arcsin`

fix problems about pylint

fix example in `linspace`

fix something

fix according to the comments

remove linkless `see also`

fix according to comments

fix to pass sanity

change signature of `linspace`

fix a mistake

* fix bug for build website

* fix render of note of `reciprocal`
* add numpy compatible trace

* add doc for trace
* Add numpy compatible argsort

* Minor syntax fix
address the comment
* Add numpy compatible hstack that currently pass CPU tests

Regsiter hstack in GPU

Rgister backward function to GPU

Add some comments

Fix the issues pointed out in code review

Minor syntax fix according to comments

Add docs

* Minor syntax fix
* implements numpy tensordot

* Fixed bugs and optimized backward operator

* Rewrited tests

* Debuging

* Debuging 0-size input

* Moved axis-reordering from frontend to backend

* Added comments

* integrated forward part

* Add more tests

* Fixed GPU bugs

* Add comments to tensordot

* Add empty lines.

* Change tests

* Remove redundant code

* Change file names

* Add numerical backward test

* Change np.dot for case 5.

* Remove spaces.

* Remove more spaces.

* Add head files.

* Remove spaces in python interface

* Refactored.

* Changed intereface.

* changed GPU test.

* Clean codes.

* Change styles.

* Remove blank lines.

* Add blank lines

* Recover lines.

* Support python 2

* Test Python 2

* Add more tests

* Add error msg

* Change comments.
@hgt312 hgt312 requested a review from szha as a code owner July 17, 2019 07:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants