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

[Numpy] Basic indexing in symbolic interface #15905

Closed
wants to merge 3 commits into from

Conversation

mikemwx
Copy link
Contributor

@mikemwx mikemwx commented Aug 15, 2019

Description

Implement basic slicing in symbolic interface

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 my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Add npx_reshape to support reshape with special flags

    • -1 to infer this dimension from the other given dimensions
    • -2 copy the current dimension from the input to the output
    • -3 skip the current dimension if and only if the current dimension is of size 1, report an error otherwise
    • -4 copy all remaining dimensions from the input to the output
    • -5 use the product of the next two consecutive dimensions in the output
    • -6 split current dimension in the output into the next two dimensions in the input
  • Implement basic slicing in _symbol.py : __getitem__, basic slicing means slicing with

    • an integer
    • a pyslice
    • a tuple of integers and pyslices

A flag _output_is_list is added to symbol class in the frontend to differentiate the cases in which a symbol with only one output Node is conceptually a list, eg: split(x, 1)

  • Overload the Group function in Symbol
  • Overload the save, save_json_string, load, load_json_string to specially take care of the newly added flag

Comments

Based on the current implementation, any operator that generates a list-like output should register their name in the list python/mxnet/base.py:_NP_OUTPUT_IS_LIST_OPERATORS

  • backward compatibility is tested by running: tests/python/unittest/test_gluon.py

Thank @reminisce and @haojin2 for reviewing

@mikemwx mikemwx requested a review from szha as a code owner August 15, 2019 06:10
@haojin2 haojin2 self-assigned this Aug 15, 2019
@haojin2 haojin2 added the Numpy label Aug 15, 2019
" -5 use the product of two consecutive dimensions of the input"
" shape as the output"
" -6 split one dimension of the input into two dimensions passed"
" subsequent to -6 in the new shape");
Copy link
Member

Choose a reason for hiding this comment

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

I find that the reverse flag in the original nd.reshape will also be useful.

Sometimes, I'd like to reshape (..., N * C) --> (..., N, C), and could not do so without the reverse option.

@szha
Copy link
Member

szha commented Nov 4, 2019

closing as inactive duplicate of #16621

@szha szha closed this Nov 4, 2019
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.

4 participants