Skip to content

Commit 87f2e46

Browse files
committed
Use of nb::literals for arguments
1 parent 5d86fcd commit 87f2e46

23 files changed

+90
-87
lines changed

include/nanoeigenpy/decompositions/col-piv-householder-qr.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nanoeigenpy {
99
namespace nb = nanobind;
10+
using namespace nb::literals;
1011

1112
template <typename MatrixType, typename MatrixOrVector>
1213
MatrixOrVector solve(const Eigen::ColPivHouseholderQR<MatrixType> &c,
@@ -47,12 +48,11 @@ void exposeColPivHouseholderQR(nb::module_ m, const char *name) {
4748
"The default constructor is useful in cases in which the "
4849
"user intends to perform decompositions via "
4950
"HouseholderQR.compute(matrix).")
50-
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), nb::arg("rows"),
51-
nb::arg("cols"),
51+
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), "rows"_a, "cols"_a,
5252
"Default constructor with memory preallocation.\n"
5353
"Like the default constructor but with preallocation of the "
5454
"internal data according to the specified problem size. ")
55-
.def(nb::init<const MatrixType &>(), nb::arg("matrix"),
55+
.def(nb::init<const MatrixType &>(), "matrix"_a,
5656
"Constructs a QR factorization from a given matrix.\n"
5757
"This constructor computes the QR factorization of the matrix "
5858
"matrix by calling the method compute().")
@@ -130,7 +130,7 @@ void exposeColPivHouseholderQR(nb::module_ m, const char *name) {
130130
[](Solver &c, RealScalar const &threshold) {
131131
return c.setThreshold(threshold);
132132
},
133-
nb::arg("threshold"),
133+
"threshold"_a,
134134
"Allows to prescribe a threshold to be used by certain methods, "
135135
"such as rank(), who need to determine when pivots are to be "
136136
"considered nonzero. This is not used for the QR decomposition "
@@ -169,7 +169,7 @@ void exposeColPivHouseholderQR(nb::module_ m, const char *name) {
169169
[](Solver &c, MatrixType const &matrix) -> Solver & {
170170
return c.compute(matrix);
171171
},
172-
nb::arg("matrix"), "Computes the QR factorization of given matrix.",
172+
"matrix"_a, "Computes the QR factorization of given matrix.",
173173
nb::rv_policy::reference)
174174

175175
.def(
@@ -182,15 +182,15 @@ void exposeColPivHouseholderQR(nb::module_ m, const char *name) {
182182
[](Solver const &c, VectorType const &b) -> VectorType {
183183
return solve(c, b);
184184
},
185-
nb::arg("b"),
185+
"b"_a,
186186
"Returns the solution x of A x = B using the current "
187187
"decomposition of A where b is a right hand side vector.")
188188
.def(
189189
"solve",
190190
[](Solver const &c, MatrixType const &B) -> MatrixType {
191191
return solve(c, B);
192192
},
193-
nb::arg("B"),
193+
"B"_a,
194194
"Returns the solution X of A X = B using the current "
195195
"decomposition of A where B is a right hand side matrix.")
196196

include/nanoeigenpy/decompositions/complete-orthogonal-decomposition.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nanoeigenpy {
99
namespace nb = nanobind;
10+
using namespace nb::literals;
1011

1112
template <typename MatrixType, typename MatrixOrVector>
1213
MatrixOrVector solve(
@@ -48,12 +49,11 @@ void exposeCompleteOrthogonalDecomposition(nb::module_ m, const char *name) {
4849
"The default constructor is useful in cases in which the "
4950
"user intends to perform decompositions via "
5051
"HouseholderQR.compute(matrix).")
51-
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), nb::arg("rows"),
52-
nb::arg("cols"),
52+
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), "rows"_a, "cols"_a,
5353
"Default constructor with memory preallocation.\n"
5454
"Like the default constructor but with preallocation of the "
5555
"internal data according to the specified problem size. ")
56-
.def(nb::init<const MatrixType &>(), nb::arg("matrix"),
56+
.def(nb::init<const MatrixType &>(), "matrix"_a,
5757
"Constructs a QR factorization from a given matrix.\n"
5858
"This constructor computes the QR factorization of the matrix "
5959
"matrix by calling the method compute().")
@@ -138,7 +138,7 @@ void exposeCompleteOrthogonalDecomposition(nb::module_ m, const char *name) {
138138
[](Solver &c, RealScalar const &threshold) {
139139
return c.setThreshold(threshold);
140140
},
141-
nb::arg("threshold"),
141+
"threshold"_a,
142142
"Allows to prescribe a threshold to be used by certain methods, "
143143
"such as rank(), who need to determine when pivots are to be "
144144
"considered nonzero. This is not used for the complete "
@@ -179,7 +179,7 @@ void exposeCompleteOrthogonalDecomposition(nb::module_ m, const char *name) {
179179
.def(
180180
"compute",
181181
[](Solver &c, MatrixType const &matrix) { return c.compute(matrix); },
182-
nb::arg("matrix"),
182+
"matrix"_a,
183183
"Computes the complete orthogonal factorization of given matrix.",
184184
nb::rv_policy::reference)
185185

@@ -195,15 +195,15 @@ void exposeCompleteOrthogonalDecomposition(nb::module_ m, const char *name) {
195195
[](Solver const &c, VectorType const &b) -> VectorType {
196196
return solve(c, b);
197197
},
198-
nb::arg("b"),
198+
"b"_a,
199199
"Returns the solution x of A x = B using the current "
200200
"decomposition of A where b is a right hand side vector.")
201201
.def(
202202
"solve",
203203
[](Solver const &c, MatrixType const &B) -> MatrixType {
204204
return solve(c, B);
205205
},
206-
nb::arg("B"),
206+
"B"_a,
207207
"Returns the solution X of A X = B using the current "
208208
"decomposition of A where B is a right hand side matrix.")
209209

include/nanoeigenpy/decompositions/eigen-solver.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nanoeigenpy {
99
namespace nb = nanobind;
10+
using namespace nb::literals;
1011

1112
template <typename _MatrixType>
1213
void exposeEigenSolver(nb::module_ m, const char *name) {
@@ -18,10 +19,10 @@ void exposeEigenSolver(nb::module_ m, const char *name) {
1819
}
1920
nb::class_<Solver>(m, name, "Eigen solver.")
2021
.def(nb::init<>(), "Default constructor.")
21-
.def(nb::init<Eigen::DenseIndex>(), nb::arg("size"),
22+
.def(nb::init<Eigen::DenseIndex>(), "size"_a,
2223
"Default constructor with memory preallocation.")
23-
.def(nb::init<const MatrixType &, bool>(), nb::arg("matrix"),
24-
nb::arg("compute_eigen_vectors") = true,
24+
.def(nb::init<const MatrixType &, bool>(), "matrix"_a,
25+
"compute_eigen_vectors"_a = true,
2526
"Computes eigendecomposition of given matrix")
2627

2728
.def("eigenvalues", &Solver::eigenvalues,
@@ -35,13 +36,13 @@ void exposeEigenSolver(nb::module_ m, const char *name) {
3536
[](Solver &c, MatrixType const &matrix) -> Solver & {
3637
return c.compute(matrix);
3738
},
38-
nb::arg("matrix"), "Computes the eigendecomposition of given matrix.",
39+
"matrix"_a, "Computes the eigendecomposition of given matrix.",
3940
nb::rv_policy::reference)
4041
.def(
4142
"compute",
4243
[](Solver &c, MatrixType const &matrix, bool compute_eigen_vectors)
4344
-> Solver & { return c.compute(matrix, compute_eigen_vectors); },
44-
nb::arg("matrix"), nb::arg("compute_eigen_vectors"),
45+
"matrix"_a, "compute_eigen_vectors"_a,
4546
"Computes the eigendecomposition of given matrix.",
4647
nb::rv_policy::reference)
4748

include/nanoeigenpy/decompositions/full-piv-householder-qr.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nanoeigenpy {
99
namespace nb = nanobind;
10+
using namespace nb::literals;
1011

1112
template <typename MatrixType, typename MatrixOrVector>
1213
MatrixOrVector solve(const Eigen::FullPivHouseholderQR<MatrixType> &c,
@@ -50,12 +51,11 @@ void exposeFullPivHouseholderQR(nb::module_ m, const char *name) {
5051
"The default constructor is useful in cases in which the "
5152
"user intends to perform decompositions via "
5253
"HouseholderQR.compute(matrix).")
53-
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), nb::arg("rows"),
54-
nb::arg("cols"),
54+
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), "rows"_a, "cols"_a,
5555
"Default constructor with memory preallocation.\n"
5656
"Like the default constructor but with preallocation of the "
5757
"internal data according to the specified problem size. ")
58-
.def(nb::init<const MatrixType &>(), nb::arg("matrix"),
58+
.def(nb::init<const MatrixType &>(), "matrix"_a,
5959
"Constructs a QR factorization from a given matrix.\n"
6060
"This constructor computes the QR factorization of the matrix "
6161
"matrix by calling the method compute().")
@@ -128,7 +128,7 @@ void exposeFullPivHouseholderQR(nb::module_ m, const char *name) {
128128
[](Solver &c, RealScalar const &threshold) {
129129
return c.setThreshold(threshold);
130130
},
131-
nb::arg("threshold"),
131+
"threshold"_a,
132132
"Allows to prescribe a threshold to be used by certain methods, "
133133
"such as rank(), who need to determine when pivots are to be "
134134
"considered nonzero. This is not used for the QR decomposition "
@@ -164,7 +164,7 @@ void exposeFullPivHouseholderQR(nb::module_ m, const char *name) {
164164
[](Solver &c, MatrixType const &matrix) -> Solver & {
165165
return c.compute(matrix);
166166
},
167-
nb::arg("matrix"), "Computes the QR factorization of given matrix.",
167+
"matrix"_a, "Computes the QR factorization of given matrix.",
168168
nb::rv_policy::reference)
169169

170170
.def(
@@ -177,15 +177,15 @@ void exposeFullPivHouseholderQR(nb::module_ m, const char *name) {
177177
[](Solver const &c, VectorType const &b) -> VectorType {
178178
return solve(c, b);
179179
},
180-
nb::arg("b"),
180+
"b"_a,
181181
"Returns the solution x of A x = B using the current "
182182
"decomposition of A where b is a right hand side vector.")
183183
.def(
184184
"solve",
185185
[](Solver const &c, MatrixType const &B) -> MatrixType {
186186
return solve(c, B);
187187
},
188-
nb::arg("B"),
188+
"B"_a,
189189
"Returns the solution X of A X = B using the current "
190190
"decomposition of A where B is a right hand side matrix.")
191191

include/nanoeigenpy/decompositions/generalized-self-adjoint-eigen-solver.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void exposeGeneralizedSelfAdjointEigenSolver(nb::module_ m, const char *name) {
2020
nb::class_<Solver>(m, name, "Generalized self adjoint Eigen Solver")
2121

2222
.def(nb::init<>(), "Default constructor.")
23-
.def(nb::init<Eigen::DenseIndex>(), nb::arg("size"),
23+
.def(nb::init<Eigen::DenseIndex>(), "size"_a,
2424
"Default constructor with memory preallocation.")
2525
.def(nb::init<const MatrixType &, const MatrixType &, int>(), "matA"_a,
2626
"matB"_a, "options"_a = Eigen::ComputeEigenvectors | Eigen::Ax_lBx,
@@ -55,7 +55,7 @@ void exposeGeneralizedSelfAdjointEigenSolver(nb::module_ m, const char *name) {
5555
[](Solver &c, MatrixType const &matrix) -> Solver & {
5656
return static_cast<Solver &>(c.computeDirect(matrix));
5757
},
58-
nb::arg("matrix"),
58+
"matrix"_a,
5959
"Computes eigendecomposition of given matrix using a closed-form "
6060
"algorithm.",
6161
nb::rv_policy::reference)
@@ -64,7 +64,7 @@ void exposeGeneralizedSelfAdjointEigenSolver(nb::module_ m, const char *name) {
6464
[](Solver &c, MatrixType const &matrix, int options) -> Solver & {
6565
return static_cast<Solver &>(c.computeDirect(matrix, options));
6666
},
67-
nb::arg("matrix"), nb::arg("options"),
67+
"matrix"_a, "options"_a,
6868
"Computes eigendecomposition of given matrix using a closed-form "
6969
"algorithm.",
7070
nb::rv_policy::reference)

include/nanoeigenpy/decompositions/householder-qr.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nanoeigenpy {
99
namespace nb = nanobind;
10+
using namespace nb::literals;
1011

1112
template <typename MatrixType, typename MatrixOrVector>
1213
MatrixOrVector solve(const Eigen::HouseholderQR<MatrixType> &c,
@@ -47,12 +48,11 @@ void exposeHouseholderQR(nb::module_ m, const char *name) {
4748
"The default constructor is useful in cases in which the "
4849
"user intends to perform decompositions via "
4950
"HouseholderQR.compute(matrix).")
50-
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), nb::arg("rows"),
51-
nb::arg("cols"),
51+
.def(nb::init<Eigen::DenseIndex, Eigen::DenseIndex>(), "rows"_a, "cols"_a,
5252
"Default constructor with memory preallocation.\n"
5353
"Like the default constructor but with preallocation of the "
5454
"internal data according to the specified problem size. ")
55-
.def(nb::init<const MatrixType &>(), nb::arg("matrix"),
55+
.def(nb::init<const MatrixType &>(), "matrix"_a,
5656
"Constructs a QR factorization from a given matrix.\n"
5757
"This constructor computes the QR factorization of the matrix "
5858
"matrix by calling the method compute().")
@@ -91,23 +91,23 @@ void exposeHouseholderQR(nb::module_ m, const char *name) {
9191
[](Solver &c, MatrixType const &matrix) -> Solver & {
9292
return c.compute(matrix);
9393
},
94-
nb::arg("matrix"), "Computes the QR factorization of given matrix.",
94+
"matrix"_a, "Computes the QR factorization of given matrix.",
9595
nb::rv_policy::reference)
9696

9797
.def(
9898
"solve",
9999
[](Solver const &c, VectorType const &b) -> VectorType {
100100
return solve(c, b);
101101
},
102-
nb::arg("b"),
102+
"b"_a,
103103
"Returns the solution x of A x = B using the current "
104104
"decomposition of A where b is a right hand side vector.")
105105
.def(
106106
"solve",
107107
[](Solver const &c, MatrixType const &B) -> MatrixType {
108108
return solve(c, B);
109109
},
110-
nb::arg("B"),
110+
"B"_a,
111111
"Returns the solution X of A X = B using the current "
112112
"decomposition of A where B is a right hand side matrix.")
113113

include/nanoeigenpy/decompositions/ldlt.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace nanoeigenpy {
1010
namespace nb = nanobind;
11+
using namespace nb::literals;
1112

1213
template <typename MatrixType, typename MatrixOrVector>
1314
MatrixOrVector solve(const Eigen::LDLT<MatrixType> &c,
@@ -40,9 +41,9 @@ void exposeLDLT(nb::module_ m, const char *name) {
4041
"square root on D also stabilizes the computation.")
4142

4243
.def(nb::init<>(), "Default constructor.")
43-
.def(nb::init<Eigen::DenseIndex>(), nb::arg("size"),
44+
.def(nb::init<Eigen::DenseIndex>(), "size"_a,
4445
"Default constructor with memory preallocation.")
45-
.def(nb::init<const MatrixType &>(), nb::arg("matrix"),
46+
.def(nb::init<const MatrixType &>(), "matrix"_a,
4647
"Constructs a LLT factorization from a given matrix.")
4748

4849
.def(EigenBaseVisitor())
@@ -80,8 +81,7 @@ void exposeLDLT(nb::module_ m, const char *name) {
8081
[](Solver &c, VectorType const &w, Scalar sigma) -> Solver & {
8182
return c.rankUpdate(w, sigma);
8283
},
83-
"If LDL^* = A, then it becomes A + sigma * v v^*", nb::arg("w"),
84-
nb::arg("sigma"))
84+
"If LDL^* = A, then it becomes A + sigma * v v^*", "w"_a, "sigma"_a)
8585

8686
.def("adjoint", &Solver::adjoint,
8787
"Returns the adjoint, that is, a reference to the decomposition "
@@ -93,7 +93,7 @@ void exposeLDLT(nb::module_ m, const char *name) {
9393
[](Solver &c, MatrixType const &matrix) -> Solver & {
9494
return c.compute(matrix);
9595
},
96-
nb::arg("matrix"), "Computes the LDLT of given matrix.",
96+
"matrix"_a, "Computes the LDLT of given matrix.",
9797
nb::rv_policy::reference)
9898
.def("info", &Solver::info,
9999
"NumericalIssue if the input contains INF or NaN values or "
@@ -113,15 +113,15 @@ void exposeLDLT(nb::module_ m, const char *name) {
113113
[](Solver const &c, VectorType const &b) -> VectorType {
114114
return solve(c, b);
115115
},
116-
nb::arg("b"),
116+
"b"_a,
117117
"Returns the solution x of A x = b using the current "
118118
"decomposition of A.")
119119
.def(
120120
"solve",
121121
[](Solver const &c, MatrixType const &B) -> MatrixType {
122122
return solve(c, B);
123123
},
124-
nb::arg("B"),
124+
"B"_a,
125125
"Returns the solution X of A X = B using the current "
126126
"decomposition of A where B is a right hand side matrix.")
127127

0 commit comments

Comments
 (0)