eric-haibin-lin commented on a change in pull request #10374: Sparse support 
for Custom Op
URL: https://github.com/apache/incubator-mxnet/pull/10374#discussion_r178669126
 
 

 ##########
 File path: example/numpy-ops/custom_sparse_sqr.py
 ##########
 @@ -0,0 +1,115 @@
+# 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.
+
+# pylint: skip-file
+import mxnet as mx
+import numpy as np
+
+class Sqr(mx.operator.CustomOp):
+    '''Example of how to use custom op with sparse ndarrays
+    '''
+    def forward(self, is_train, req, in_data, out_data, aux):
+        #self.assign(out_data[0], req[0], mx.nd.sparse.square(in_data[0]))
 
 Review comment:
   Would it make more sense to have an example without using `mx.nd.square`? 
For example:
   ```
   input = in_data[0]
   data = input.data
   output = sparse.csr_matrix((data*data, input.indptr, input.indices), 
shape=...)
   self.assign(out_data[0], req[0], output)
   ```
   
   
   
   
   

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