gigasquid 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_r251205025
 
 

 ##########
 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:
   That's a good question. From looking at the Scala api I would say that it 
would enable finer grained control - you could manually add or remove native 
resources from a scope and then manually call close on it. But I don't think 
that we need to expose that on the Clojure side, unless you have a different 
view on it.

----------------------------------------------------------------
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