You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/01/16 00:22:24 UTC

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17279: [Numpy] Add linalg.pinv op

haojin2 commented on a change in pull request #17279: [Numpy] Add linalg.pinv op
URL: https://github.com/apache/incubator-mxnet/pull/17279#discussion_r367175293
 
 

 ##########
 File path: src/operator/numpy/linalg/np_pinv.cc
 ##########
 @@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file np_pinv.cc
+ * \brief CPU implementation of the PINV Operator
+ */
+
+#include "./np_pinv-inl.h"
+
+namespace mxnet {
+namespace op {
+
+bool PinvOpShape(const nnvm::NodeAttrs& attrs,
+                 mxnet::ShapeVector *in_attrs,
+                 mxnet::ShapeVector *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 2U);
+  CHECK_EQ(out_attrs->size(), 1U);
+  const mxnet::TShape& a_shape = (*in_attrs)[0];
+  const mxnet::TShape& rcond_shape = (*in_attrs)[1];
+  const mxnet::TShape& pinv_shape = (*out_attrs)[0];
+  const int a_ndim = a_shape.ndim();
+
+  if (shape_is_known(a_shape)) {
+    // Forward shape inference.
+    CHECK_GE(a_ndim, 2)
+      << "Array must be at least two-dimensional";
+    // Calculte pinv shape.
+    std::vector<int> pinv_shape_vec(a_ndim, -1);
+    for (int i = 0; i < a_ndim - 2; ++i) {
+      pinv_shape_vec[i] = a_shape[i];
+    }
+    pinv_shape_vec[a_ndim - 2] = a_shape[a_ndim - 1];
+    pinv_shape_vec[a_ndim - 1] = a_shape[a_ndim - 2];
+    SHAPE_ASSIGN_CHECK(*out_attrs, 0, mxnet::TShape(pinv_shape_vec.begin(), pinv_shape_vec.end()));
+    // Check rcond shape.
+    GetOrCheckCutoffAndLargeShape(attrs, a_shape, rcond_shape, nullptr, nullptr);
+  } else {
+    // Backward shape inference.
+    if (shape_is_known(pinv_shape)) {
 
 Review comment:
   `else if (shape_is_known(pinv_shape))`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services