1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// Copyright (c) 2018-2024 www.open3d.org
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------
#include "open3d/core/linalg/AddMM.h"
#include "open3d/core/linalg/Det.h"
#include "open3d/core/linalg/Inverse.h"
#include "open3d/core/linalg/LU.h"
#include "open3d/core/linalg/LeastSquares.h"
#include "open3d/core/linalg/Matmul.h"
#include "open3d/core/linalg/SVD.h"
#include "open3d/core/linalg/Solve.h"
#include "open3d/core/linalg/Tri.h"
#include "pybind/core/core.h"
#include "pybind/docstring.h"
#include "pybind/open3d_pybind.h"
namespace open3d {
namespace core {
void pybind_core_linalg_definitions(py::module &m) {
m.def(
"matmul",
[](const Tensor &A, const Tensor &B) {
Tensor output;
Matmul(A, B, output);
return output;
},
"Function to perform matrix multiplication of two 2D tensors with "
"compatible shapes.",
"A"_a, "B"_a);
m.def(
"addmm",
[](const Tensor &input, const Tensor &A, const Tensor &B,
double alpha, double beta) {
Tensor output =
input.Expand({A.GetShape(0), B.GetShape(1)}).Clone();
AddMM(A, B, output, alpha, beta);
return output;
},
"Function to perform addmm of two 2D tensors with compatible "
"shapes. Specifically this function returns output = alpha * A @ B "
"+ beta * input.",
"input"_a, "A"_a, "B"_a, "alpha"_a, "beta"_a);
m.def(
"det",
[](Tensor &A) {
double det;
det = Det(A);
return det;
},
"Function to compute determinant of a 2D square tensor.", "A"_a);
m.def(
"lu",
[](const Tensor &A, bool permute_l) {
Tensor permutation, lower, upper;
LU(A, permutation, lower, upper, permute_l);
return py::make_tuple(permutation, lower, upper);
},
"Function to compute LU factorisation of a square 2D tensor.",
"A"_a, "permute_l"_a = false);
m.def(
"lu_ipiv",
[](const Tensor &A) {
Tensor ipiv, output;
LUIpiv(A, ipiv, output);
return py::make_tuple(ipiv, output);
},
"Function to compute LU factorisation of a square 2D tensor.",
"A"_a);
m.def(
"inv",
[](const Tensor &A) {
Tensor output;
Inverse(A, output);
return output;
},
"Function to inverse a square 2D tensor.", "A"_a);
m.def(
"solve",
[](const Tensor &A, const Tensor &B) {
Tensor output;
Solve(A, B, output);
return output;
},
"Function to solve X for a linear system AX = B where A is a "
"square "
"matrix",
"A"_a, "B"_a);
m.def(
"lstsq",
[](const Tensor &A, const Tensor &B) {
Tensor output;
LeastSquares(A, B, output);
return output;
},
"Function to solve X for a linear system AX = B where A is a full "
"rank matrix.",
"A"_a, "B"_a);
m.def(
"svd",
[](const Tensor &A) {
Tensor U, S, VT;
SVD(A, U, S, VT);
return py::make_tuple(U, S, VT);
},
"Function to decompose A with A = U S VT.", "A"_a);
m.def(
"triu",
[](const Tensor &A, const int diagonal) {
Tensor U;
Triu(A, U, diagonal);
return U;
},
"Function to get upper triangular matrix, above diagonal", "A"_a,
"diagonal"_a = 0);
m.def(
"tril",
[](const Tensor &A, const int diagonal) {
Tensor L;
Tril(A, L, diagonal);
return L;
},
"Function to get lower triangular matrix, below diagonal", "A"_a,
"diagonal"_a = 0);
m.def(
"triul",
[](const Tensor &A, const int diagonal = 0) {
Tensor U, L;
Triul(A, U, L, diagonal);
return py::make_tuple(U, L);
},
"Function to get both upper and lower triangular matrix", "A"_a,
"diagonal"_a = 0);
}
} // namespace core
} // namespace open3d
|