Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
update comments and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arcadiaphy committed May 24, 2019
1 parent 9826d25 commit d768e36
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/operator/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void linalg_getri(const Tensor<xpu, 2, DType>& 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<typename xpu, typename DType>
void linalg_batch_getri(const Tensor<xpu, 3, DType>& A,
const Tensor<xpu, 3, DType>& LU,
Expand All @@ -237,7 +237,7 @@ void linalg_batch_getri(const Tensor<xpu, 3, DType>& 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<typename xpu, typename DType>
void linalg_batch_inverse(const Tensor<xpu, 3, DType>& A,
Expand Down
6 changes: 3 additions & 3 deletions src/operator/linalg_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -1490,7 +1490,7 @@ template<> inline \
void linalg_batch_inverse<xpu, DType>(const Tensor<xpu, 3, DType>& A, \
const Tensor<xpu, 3, DType>& 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
Expand Down Expand Up @@ -1552,7 +1552,7 @@ void linalg_batch_det_backward_helper<xpu, DType>(const Tensor<xpu, 3, DType>& L
const Tensor<xpu, 3, DType>& 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
Expand Down
18 changes: 10 additions & 8 deletions src/operator/tensor/la_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.]
Expand Down Expand Up @@ -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.]]]
Expand Down

0 comments on commit d768e36

Please sign in to comment.