mseeger commented on a change in pull request #15795: [Numpy] Differentiable svd
URL: https://github.com/apache/incubator-mxnet/pull/15795#discussion_r313282149
 
 

 ##########
 File path: src/operator/linalg_impl.h
 ##########
 @@ -1234,6 +1234,137 @@ LINALG_GPU_SYEVD_WORKSPACE_QUERY(DnDsyevd, double)
 
 #endif  // __CUDACC__
 
+//////////////////////////////// GESVD 
////////////////////////////////////////////
+
+// CPU/GPU-versions of LAPACK function "gesvd"
+
+template<typename xpu, typename DType> inline
+void check_gesvd(const Tensor<xpu, 2, DType>& UT,
+                 const Tensor<xpu, 1, DType>& L,
+                 const Tensor<xpu, 2, DType>& V) {
+  // Any checking that helps user debug potential problems.
+  CHECK_LE(V.size(0), V.size(1))
+    << "The second to last dimension of A must be less or equal to the "
+    << "last dimension";
+  CHECK_EQ(UT.size(0), UT.size(1))
+    << "UT must be square matrix";
+  CHECK_EQ(V.size(0), L.size(0))
+    << "V, L have incompatible sizes";
+  CHECK_EQ(V.size(0), UT.size(0))
+    << "V, UT must have compatible sizes";
+}
+
+#define LINALG_CPU_GESVD(fname, DType) \
+template<> inline \
+void linalg_gesvd<cpu, DType>(const Tensor<cpu, 2, DType>& UT, \
+                              const Tensor<cpu, 1, DType>& L, \
+                              const Tensor<cpu, 2, DType>& V, \
+                              const Tensor<cpu, 1, DType>& work, \
+                              Stream<cpu> *s) { \
+  check_gesvd(UT, L, V); \
+  DType lwork(0); \
+  MXNET_LAPACK_##fname(MXNET_LAPACK_ROW_MAJOR, V.size(0), V.size(1), \
 
 Review comment:
   I think this is wrong. You must have done the workspace query before 
(calling the other function), so the size of work will be fine to pass for 
lwork, right? So no need to do the workspace query again here.

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


With regards,
Apache Git Services

Reply via email to