From d768e36078d88081ff613232d5e8860a9228f931 Mon Sep 17 00:00:00 2001 From: Wang Jiajun Date: Fri, 24 May 2019 20:11:29 +0800 Subject: [PATCH] update comments and docs --- src/operator/linalg.h | 4 ++-- src/operator/linalg_impl.h | 6 +++--- src/operator/tensor/la_op.cc | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/operator/linalg.h b/src/operator/linalg.h index e532e2b91cb9..8f1eedae03ac 100644 --- a/src/operator/linalg.h +++ b/src/operator/linalg.h @@ -228,7 +228,7 @@ void linalg_getri(const Tensor& LU, // Note that this function only implements GPU version with "getriBatched" in cuBLAS. // Unlike lapack routines in cpu, it is computed out-of-place, so the final matrix -// inversion is stored in A. +// inverse is stored in A. template void linalg_batch_getri(const Tensor& A, const Tensor& LU, @@ -237,7 +237,7 @@ void linalg_batch_getri(const Tensor& A, //////////////////////////////// INVERSE //////////////////////////////////////////// -// CPU/GPU-versions of matrix inversion combining LAPACK function "getrf" and "getri" +// CPU/GPU-versions of matrix inverse combining LAPACK function "getrf" and "getri" // Note that A = inverse(B) template void linalg_batch_inverse(const Tensor& A, diff --git a/src/operator/linalg_impl.h b/src/operator/linalg_impl.h index 8353868db6fc..958e95555502 100644 --- a/src/operator/linalg_impl.h +++ b/src/operator/linalg_impl.h @@ -1429,7 +1429,7 @@ LINALG_GPU_BATCH_GETRI(DgetriBatched, double) //////////////////////////////// INVERSE //////////////////////////////////////////// -// CPU/GPU-versions of matrix inversion combining LAPACK function "getrf" and "getri" +// CPU/GPU-versions of matrix inverse combining LAPACK function "getrf" and "getri" // Note A = inverse(B) #define LINALG_CPU_BATCH_INVERSE(xpu, DType) \ @@ -1490,7 +1490,7 @@ template<> inline \ void linalg_batch_inverse(const Tensor& A, \ const Tensor& B, \ const mxnet::OpContext& ctx) { \ - LOG(FATAL) << "gpu matrix inversion requires CUDA version >= 8.0!"; \ + LOG(FATAL) << "gpu matrix inverse requires CUDA version >= 8.0!"; \ } #endif // CUDA_VERSION >= 8000 @@ -1552,7 +1552,7 @@ void linalg_batch_det_backward_helper(const Tensor& L const Tensor& temp, \ const DType zero_det, \ const mxnet::OpContext& ctx) { \ - LOG(FATAL) << "gpu matrix inversion requires CUDA version >= 8.0!"; \ + LOG(FATAL) << "gpu matrix inverse requires CUDA version >= 8.0!"; \ } #endif // CUDA_VERSION >= 8000 diff --git a/src/operator/tensor/la_op.cc b/src/operator/tensor/la_op.cc index c426e52a844f..ce7d1d5de692 100644 --- a/src/operator/tensor/la_op.cc +++ b/src/operator/tensor/la_op.cc @@ -952,18 +952,18 @@ If *n>2*, *det* is performed separately on the trailing two dimensions for all inputs (batch mode). .. note:: The operator supports float32 and float64 data types only. -.. note:: There is no gradient backwarded when det(A) == 0 because it's - rarely hit upon in float point computation and the Jacobi's - formula on determinant gradient is not computationally efficient - when A is non-invertible. +.. note:: There is no gradient backwarded when A is non-invertible (which is + equivalent to det(A) = 0) because zero is rarely hit upon in float + point computation and the Jacobi's formula on determinant gradient + is not computationally efficient when A is non-invertible. Examples:: - Single matrix inversion + Single matrix determinant A = [[1., 4.], [2., 3.]] det(A) = [-5.] - Batch matrix inversion + Batch matrix determinant A = [[[1., 4.], [2., 3.]], [[2., 3.], [1., 4.]]] det(A) = [-5., 5.] @@ -1006,16 +1006,18 @@ for all inputs (batch mode). .. note:: The operator supports float32 and float64 data types only. .. note:: The gradient is not properly defined on sign, so the gradient of it is not backwarded. +.. note:: No gradient is backwarded when A is non-invertible. Please see + the docs of operator det for detail. Examples:: - Single matrix inversion + Single matrix signed log determinant A = [[2., 3.], [1., 4.]] sign, logabsdet = slogdet(A) sign = [1.] logabsdet = [1.609438] - Batch matrix inversion + Batch matrix signed log determinant A = [[[2., 3.], [1., 4.]], [[1., 2.], [2., 4.]], [[1., 2.], [4., 3.]]]