You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/09/12 17:38:25 UTC

[GitHub] lanking520 opened a new pull request #12536: [MXNET-913][WIP] Java API --- Scala NDArray Improvement

lanking520 opened a new pull request #12536: [MXNET-913][WIP] Java API --- Scala NDArray Improvement
URL: https://github.com/apache/incubator-mxnet/pull/12536
 
 
   ## Description ##
   This PR contains some addition in NDArray as well as Java compatible functionalities for Scala package.
   
   **`ArgBuilder`**: Allows user to pass in a single variable or a batch variables to construct a Scala Sequence or Scala Map.
   
   **`NDArray`**: Brings some improvement on NDArray such as a `toString` method that can allow user to see a formatted output. Add `new NDArray()` constructor allowing Java users to create a new one through this way.
   
   Unit test is coming soon...
   
   @nswamy @yzhliu @andrewfayres 
   
   ## Demo code ##
   ```java
   import org.apache.mxnet.*;
   import org.apache.mxnet.api.java.*;
   
   
   public class playjava {
   
       static final NDArray$ NDArray = NDArray$.MODULE$;
       public static void main(String[] args) {
           NDArray nd = new NDArray(new float[]{1.0f, 2.0f, 3.0f, 4.0f}, new Shape(new int[]{4, 1}), Context.cpu(0));
           System.out.println(nd);
   
           NDArray result = NDArray.norm(new ArgBuilder().addArg(nd).addArg(2).addArg(1).buildSeq()).get();
           System.out.println(result);
   
           result = NDArray.norm(new ArgBuilder().addArg("ord", 2).addArg("axis", 1).buildMap(),
                   new ArgBuilder().addArg(nd).buildSeq()).get();
           System.out.println(result);
   
           result = NDArray.norm(new ArgBuilder().addBatchArgs(new Object[]{nd, 2, 1}).buildSeq()).get();
           System.out.println(result);
   
           result = result.$minus(3);
           System.out.println(result);
   
       }
   }
   
   ```
   Output:
   ```
   [
    [1.0]
    [2.0]
    [3.0]
    [4.0]
   ]
   
   [1.0,2.0,3.0,4.0]
   
   [-2.0,-1.0,0.0,1.0]
   
   [1.0,2.0,3.0,4.0]
   
   [1.0,2.0,3.0,4.0]
   ```
   
   ## 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](https://issues.apache.org/jira/projects/MXNET/issues) 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
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services