gigasquid opened a new pull request #12447: MXNET-884 - Clojure with-resources 
macro for Improved Memory Handling
URL: https://github.com/apache/incubator-mxnet/pull/12447
 
 
   ## Description ##
   
   This adds a `with-resources` macro to the Clojure package to provide an 
idiomatic way, (similar to `with-open`), to explicitly dispose of resources 
with a `.dispose` call.
   
   It works with any Scala object that has a `.dispose` method -  NDArray, 
Symbol, Executor, Iterators, etc..
   
   Usage is:
   
   ```clojure 
   (util/with-resources [a (ndarray/ones [3])
                         b (ndarray/ones [3])]
       (ndarray/+ a b))
   ```
   Any resources in the binding vector will be disposed. Result resources will 
not.
   
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [X] 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)
   - [X] Changes are complete (i.e. I finished coding on this PR)
   - [X] 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)
   - [X] 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
   - [X] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ## Comments ##
   - The Scala package uses scopes with an NDArrayCollector. However, scopes do 
not mesh well with the Clojure language and the macro pattern for `with-open` 
for resources is well established and idiomatic in Clojure.
   - This will allow users to better control the resources and memory 
management, however it is not a full solution. There is still investigation 
into other avenues ongoing with the Scala package.
   - Applications of with-resources to the examples will happen in a separate PR
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to