kedarbellare commented on a change in pull request #13993: [Clojure] Add 
resource scope to clojure package
URL: https://github.com/apache/incubator-mxnet/pull/13993#discussion_r251205154
 
 

 ##########
 File path: 
contrib/clojure-package/src/org/apache/clojure_mxnet/resource_scope.clj
 ##########
 @@ -0,0 +1,25 @@
+;;
+;; Licensed to the Apache Software Foundation (ASF) under one or more
+;; contributor license agreements.  See the NOTICE file distributed with
+;; this work for additional information regarding copyright ownership.
+;; The ASF licenses this file to You under the Apache License, Version 2.0
+;; (the "License"); you may not use this file except in compliance with
+;; the License.  You may obtain a copy of the License at
+;;
+;;    http://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+;;
+
+(ns org.apache.clojure-mxnet.resource-scope
+  (:require [org.apache.clojure-mxnet.util :as util])
+  (:import (org.apache.mxnet ResourceScope)))
+
+(defmacro using
+  "Uses a Resource Scope for all forms. This is a way to manage all Native 
Resources like NDArray and Symbol - it will deallocate all Native Resources by 
calling close on them automatically. It will not call close on Native Resources 
returned from the form"
+  [& forms]
+  `(ResourceScope/using (new ResourceScope) (util/forms->scala-fn ~@forms)))
 
 Review comment:
   i don't see a big need for it -- at least for now -- but i was wondering 
whether the motivation was something like 
[tf.variable_scope](https://www.tensorflow.org/api_docs/python/tf/variable_scope)
 (e.g. reusing symbols).

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to