Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
InvincibleRMC committed Jun 29, 2024
1 parent 4d8b376 commit 0645585
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 7 additions & 6 deletions include/pybind11/eigen/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,17 @@ struct EigenProps {
= !show_c_contiguous && show_order && requires_col_major;

static constexpr auto descriptor
= const_name("numpy.typing.NDArray[") + npy_format_descriptor<Scalar>::name + const_name("[")
+ const_name<fixed_rows>(const_name<(size_t) rows>(), const_name("m")) + const_name(", ")
+ const_name<fixed_cols>(const_name<(size_t) cols>(), const_name("n")) + const_name("]")
+
= const_name("numpy.typing.NDArray[") + npy_format_descriptor<Scalar>::name
+ const_name("[") + const_name<fixed_rows>(const_name<(size_t) rows>(), const_name("m"))
+ const_name(", ") + const_name<fixed_cols>(const_name<(size_t) cols>(), const_name("n"))
+ const_name("]") +
// For a reference type (e.g. Ref<MatrixXd>) we have other constraints that might need to
// be satisfied: writeable=True (for a mutable reference), and, depending on the map's
// stride options, possibly f_contiguous or c_contiguous. We include them in the
// descriptor output to provide some hint as to why a TypeError is occurring (otherwise
// it can be confusing to see that a function accepts a 'numpy.typing.NDArray[float64[3,2]]' and
// an error message that you *gave* a numpy.ndarray of the right type and dimensions.
// it can be confusing to see that a function accepts a
// 'numpy.typing.NDArray[float64[3,2]]' and an error message that you *gave* a
// numpy.ndarray of the right type and dimensions.
const_name<show_writeable>(", flags.writeable", "")
+ const_name<show_c_contiguous>(", flags.c_contiguous", "")
+ const_name<show_f_contiguous>(", flags.f_contiguous", "") + const_name("]");
Expand Down
5 changes: 3 additions & 2 deletions tests/test_eigen_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ def test_mutator_descriptors():
)
with pytest.raises(TypeError) as excinfo:
m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype="float32"))
assert "(arg0: numpy.typing.NDArray[numpy.float32[5, 6], flags.writeable]) -> None" in str(
excinfo.value
assert (
"(arg0: numpy.typing.NDArray[numpy.float32[5, 6], flags.writeable]) -> None"
in str(excinfo.value)
)
zr.flags.writeable = False
with pytest.raises(TypeError):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_eigen_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def test_round_trip_references_actually_refer(m):
@pytest.mark.parametrize("m", submodules)
def test_doc_string(m, doc):
assert (
doc(m.copy_tensor) == "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]"
doc(m.copy_tensor)
== "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]"
)
assert (
doc(m.copy_fixed_tensor)
Expand Down

0 comments on commit 0645585

Please sign in to comment.