From d2a9ba899588263f6384239d98f4eb290ff515f6 Mon Sep 17 00:00:00 2001 From: Sergiy Matusevych Date: Fri, 9 Nov 2018 13:08:37 -0800 Subject: [PATCH 1/2] implement low-level bindings for THLapack_* functions --- TorchSharp/Raw/Lapack.generated.cs | 1857 ++++++++++++++++++++++++++++ TorchSharp/Raw/Lapack.tt | 327 +++++ TorchSharp/TorchSharp.csproj | 8 + 3 files changed, 2192 insertions(+) create mode 100644 TorchSharp/Raw/Lapack.generated.cs create mode 100644 TorchSharp/Raw/Lapack.tt diff --git a/TorchSharp/Raw/Lapack.generated.cs b/TorchSharp/Raw/Lapack.generated.cs new file mode 100644 index 000000000..28ba533ae --- /dev/null +++ b/TorchSharp/Raw/Lapack.generated.cs @@ -0,0 +1,1857 @@ + +using System; +using System.Runtime.InteropServices; + +namespace TorchSharp.Raw { + + internal static class Lapack { + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + byte tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THByteLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + short tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THShortLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + int tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THIntLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + long tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THLongLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + double tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THDoubleLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_gesv( + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_gels( + byte trans, + int m, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_syev( + byte jobz, + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ w, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_geev( + byte jobvl, + byte jobvr, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ wr, + IntPtr /* scalar_t* */ wi, + IntPtr /* scalar_t* */ vl, + int ldvl, + IntPtr /* scalar_t* */ vr, + int ldvr, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_gesdd( + byte jobz, + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ s, + IntPtr /* scalar_t* */ u, + int ldu, + IntPtr /* scalar_t* */ vt, + int ldvt, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ iwork, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_getrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* int* */ info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_getrs( + byte trans, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_getri( + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ ipiv, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_potrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_potri( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_potrs( + char uplo, + int n, + int nrhs, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ b, + int ldb, + IntPtr /* int* */ info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_pstrf( + byte uplo, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* int* */ piv, + IntPtr /* int* */ rank, + float tol, + IntPtr /* scalar_t* */ work, + IntPtr /* int* */ info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_geqrf( + int m, + int n, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_orgqr( + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void THFloatLapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + IntPtr /* scalar_t* */ a, + int lda, + IntPtr /* scalar_t* */ tau, + IntPtr /* scalar_t* */ c, + int ldc, + IntPtr /* scalar_t* */ work, + int lwork, + IntPtr /* int* */ info); + } +} diff --git a/TorchSharp/Raw/Lapack.tt b/TorchSharp/Raw/Lapack.tt new file mode 100644 index 000000000..f191a24cc --- /dev/null +++ b/TorchSharp/Raw/Lapack.tt @@ -0,0 +1,327 @@ +<#@ Template Language="C#" #> +<#@ Assembly Name="System.Core" #> +<#@ Output Extension=".generated.cs" #> +<#@ Include File="Types.ttinclude" #> + +using System; +using System.Runtime.InteropServices; + +namespace TorchSharp.Raw { + + internal static class Lapack { +<# +foreach (var type in TorchTypeDef.Types) { + + string tIntPtr = "IntPtr /* int* */"; +#> + + // Solve AX=B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesv)( + // int n, int nrhs, scalar_t *a, int lda, int *ipiv, + // scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_gesv( + int n, + int nrhs, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> ipiv, + <#=type.Ptr#> b, + int ldb, + <#=tIntPtr#> info); + + // Solve a triangular system of the form A * X = B or A^T * X = B + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(trtrs)( + // char uplo, char trans, char diag, int n, int nrhs, + // scalar_t *a, int lda, scalar_t *b, int ldb, int* info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_trtrs( + byte uplo, + byte trans, + byte diag, + int n, + int nrhs, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> b, + int ldb, + <#=tIntPtr#> info); + + // Evaluate ||AX-B|| + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gels)( + // char trans, int m, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_gels( + byte trans, + int m, + int n, + int nrhs, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> b, + int ldb, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // Eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(syev)( + // char jobz, char uplo, int n, scalar_t *a, int lda, + // scalar_t *w, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_syev( + byte jobz, + byte uplo, + int n, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> w, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // Non-sym eigenvals + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geev)( + // char jobvl, char jobvr, int n, scalar_t *a, int lda, + // scalar_t *wr, scalar_t *wi, scalar_t* vl, int ldvl, + // scalar_t *vr, int ldvr, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_geev( + byte jobvl, + byte jobvr, + int n, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> wr, + <#=type.Ptr#> wi, + <#=type.Ptr#> vl, + int ldvl, + <#=type.Ptr#> vr, + int ldvr, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // SVD + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(gesdd)( + // char jobz, int m, int n, scalar_t *a, int lda, scalar_t *s, + // scalar_t *u, int ldu, scalar_t *vt, int ldvt, + // scalar_t *work, int lwork, int *iwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_gesdd( + byte jobz, + int m, + int n, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> s, + <#=type.Ptr#> u, + int ldu, + <#=type.Ptr#> vt, + int ldvt, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> iwork, + <#=tIntPtr#> info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrf)( + // int m, int n, scalar_t *a, int lda, int *ipiv, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_getrf( + int m, + int n, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> ipiv, + <#=tIntPtr#> info); + + // LU decomposition + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getrs)( + // char trans, int n, int nrhs, scalar_t *a, int lda, + // int *ipiv, scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_getrs( + byte trans, + int n, + int nrhs, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> ipiv, + <#=type.Ptr#> b, + int ldb, + <#=tIntPtr#> info); + + // Matrix Inverse + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(getri)( + // int n, scalar_t *a, int lda, int *ipiv, + // scalar_t *work, int lwork, int* info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_getri( + int n, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> ipiv, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // *** Positive Definite matrices + + // Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrf)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_potrf( + byte uplo, + int n, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> info); + + // Matrix inverse based on Cholesky factorization + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potri)( + // char uplo, int n, scalar_t *a, int lda, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_potri( + byte uplo, + int n, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> info); + + // Solve A*X = B with a symmetric positive definite matrix A + // using the Cholesky factorization. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(potrs)( + // char uplo, int n, int nrhs, scalar_t *a, int lda, + // scalar_t *b, int ldb, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_potrs( + char uplo, + int n, + int nrhs, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> b, + int ldb, + <#=tIntPtr#> info); + + // Cholesky factorization with complete pivoting. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(pstrf)( + // char uplo, int n, scalar_t *a, int lda, int *piv, + // int *rank, scalar_t tol, scalar_t *work, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_pstrf( + byte uplo, + int n, + <#=type.Ptr#> a, + int lda, + <#=tIntPtr#> piv, + <#=tIntPtr#> rank, + <#=type.Storage#> tol, + <#=type.Ptr#> work, + <#=tIntPtr#> info); + + // QR decomposition. + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(geqrf)( + // int m, int n, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_geqrf( + int m, + int n, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> tau, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // Build Q from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(orgqr)( + // int m, int n, int k, scalar_t *a, int lda, + // scalar_t *tau, scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_orgqr( + int m, + int n, + int k, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> tau, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); + + // Multiply Q with a matrix from output of geqrf + // + // Corresponds to the following TH definition: + // + // TH_API void THLapack_(ormqr)( + // char side, char trans, int m, int n, int k, + // scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, + // scalar_t *work, int lwork, int *info); + [DllImport ("caffe2")] + internal extern static void TH<#=type.Name#>Lapack_ormqr( + byte side, + byte trans, + int m, + int n, + int k, + <#=type.Ptr#> a, + int lda, + <#=type.Ptr#> tau, + <#=type.Ptr#> c, + int ldc, + <#=type.Ptr#> work, + int lwork, + <#=tIntPtr#> info); +<# } #> + } +} diff --git a/TorchSharp/TorchSharp.csproj b/TorchSharp/TorchSharp.csproj index d940721a7..3cbc91fe1 100644 --- a/TorchSharp/TorchSharp.csproj +++ b/TorchSharp/TorchSharp.csproj @@ -38,6 +38,10 @@ TextTemplatingFileGenerator Raw/Blas.generated.cs + + TextTemplatingFileGenerator + Raw/Lapack.generated.cs + TextTemplatingFileGenerator FileOperations.cs @@ -62,6 +66,10 @@ Raw/Types.ttinclude Raw/Blas.tt + + Raw/Types.ttinclude + Raw/Lapack.tt + FileOperations.tt True From 164b4ee4b26f72dce75eb2ee6342daa177884ba9 Mon Sep 17 00:00:00 2001 From: Sergiy Matusevych Date: Fri, 9 Nov 2018 17:07:54 -0800 Subject: [PATCH 2/2] minor update to trigger a CI build --- TorchSharp/Raw/Lapack.generated.cs | 1 + TorchSharp/Raw/Lapack.tt | 1 + 2 files changed, 2 insertions(+) diff --git a/TorchSharp/Raw/Lapack.generated.cs b/TorchSharp/Raw/Lapack.generated.cs index 28ba533ae..e50a49664 100644 --- a/TorchSharp/Raw/Lapack.generated.cs +++ b/TorchSharp/Raw/Lapack.generated.cs @@ -4,6 +4,7 @@ namespace TorchSharp.Raw { + // High-performance linear algebra operations. internal static class Lapack { // Solve AX=B diff --git a/TorchSharp/Raw/Lapack.tt b/TorchSharp/Raw/Lapack.tt index f191a24cc..a93537976 100644 --- a/TorchSharp/Raw/Lapack.tt +++ b/TorchSharp/Raw/Lapack.tt @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; namespace TorchSharp.Raw { + // High-performance linear algebra operations. internal static class Lapack { <# foreach (var type in TorchTypeDef.Types) {