tlby commented on a change in pull request #9988: [Perl] Sparse feature.
URL: https://github.com/apache/incubator-mxnet/pull/9988#discussion_r172403304
 
 

 ##########
 File path: perl-package/AI-MXNet/lib/AI/MXNet/NDArray/Sparse.pm
 ##########
 @@ -0,0 +1,1342 @@
+# 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.
+
+package AI::MXNet::NDArray::Sparse;
+use strict;
+use warnings;
+use AI::MXNet::Base;
+use AI::MXNet::Function::Parameters;
+use Mouse;
+extends 'AI::MXNet::NDArray';
+
+=head1 NAME
+
+    AI::MXNet::NDArray::Sparse - Sparse NDArray API of MXNet
+=cut
+
+=head1 DESCRIPTION
+
+    The base class of an NDArray stored in a sparse storage format.
+    See AI::MXNet::NDArray::CSR and AI::MXNet::NDArray::RowSparse for more 
details.
+=cut
+
+method _new_alloc_handle(
+    Stype                    $stype,
+    Shape                    $shape,
+    AI::MXNet::Context       $ctx,
+    Bool                     $delay_alloc,
+    Dtype                    $dtype,
+    AuxTypes                 $aux_types,
+    Maybe[ArrayRef[Shape]]   $aux_shapes=
+)
+{
+    confess("only int64 is supported for aux types")
+        if (grep { $_ ne 'int64' } @$aux_types);
+    my $aux_type_ids = [map { DTYPE_STR_TO_MX->{$_} } @$aux_types];
+    $aux_shapes //= [map { [0] } @$aux_types];
+    my $aux_shape_lens = [map { scalar(@$_) } @$aux_shapes];
+    @$aux_shapes = map { @$_ } @$aux_shapes;
+    my $num_aux = @{ $aux_types };
+    my $handle = check_call(
+        AI::MXNetCAPI::NDArrayCreateSparseEx(
+            STORAGE_TYPE_STR_TO_ID->{$stype},
+            $shape,
+            scalar(@$shape),
+            $ctx->device_type_id,
+            $ctx->device_id,
+            $delay_alloc,
+            DTYPE_STR_TO_MX->{$dtype},
+            scalar(@$aux_types),
+            $aux_type_ids,
+            $aux_shape_lens,
+            $aux_shapes
+        )
+    );
+}
+
+method _class_name()
+{
+    my $class = ref $self || $self;
+    $class;
+}
+
+sub not_implemented { confess "Not implemented" }
 
 Review comment:
   perhaps 
"[...](https://perldoc.perl.org/perlsyn.html#The-Ellipsis-Statement)" is 
appropriate here?  it's kinda standard for declaring abstract functions.

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