This commit is contained in:
Michael Carlstrom 2024-06-29 11:58:34 -04:00
parent 4d8b37688c
commit 0645585d2d
3 changed files with 12 additions and 9 deletions

View File

@ -224,16 +224,17 @@ struct EigenProps {
= !show_c_contiguous && show_order && requires_col_major; = !show_c_contiguous && show_order && requires_col_major;
static constexpr auto descriptor static constexpr auto descriptor
= const_name("numpy.typing.NDArray[") + npy_format_descriptor<Scalar>::name + const_name("[") = const_name("numpy.typing.NDArray[") + npy_format_descriptor<Scalar>::name
+ const_name<fixed_rows>(const_name<(size_t) rows>(), const_name("m")) + const_name(", ") + const_name("[") + const_name<fixed_rows>(const_name<(size_t) rows>(), const_name("m"))
+ const_name<fixed_cols>(const_name<(size_t) cols>(), const_name("n")) + const_name("]") + 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 // 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 // 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 // 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 // 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 // it can be confusing to see that a function accepts a
// an error message that you *gave* a numpy.ndarray of the right type and dimensions. // '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_writeable>(", flags.writeable", "")
+ const_name<show_c_contiguous>(", flags.c_contiguous", "") + const_name<show_c_contiguous>(", flags.c_contiguous", "")
+ const_name<show_f_contiguous>(", flags.f_contiguous", "") + const_name("]"); + const_name<show_f_contiguous>(", flags.f_contiguous", "") + const_name("]");

View File

@ -105,8 +105,9 @@ def test_mutator_descriptors():
) )
with pytest.raises(TypeError) as excinfo: with pytest.raises(TypeError) as excinfo:
m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype="float32")) 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( assert (
excinfo.value "(arg0: numpy.typing.NDArray[numpy.float32[5, 6], flags.writeable]) -> None"
in str(excinfo.value)
) )
zr.flags.writeable = False zr.flags.writeable = False
with pytest.raises(TypeError): with pytest.raises(TypeError):

View File

@ -268,7 +268,8 @@ def test_round_trip_references_actually_refer(m):
@pytest.mark.parametrize("m", submodules) @pytest.mark.parametrize("m", submodules)
def test_doc_string(m, doc): def test_doc_string(m, doc):
assert ( assert (
doc(m.copy_tensor) == "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]" doc(m.copy_tensor)
== "copy_tensor() -> numpy.typing.NDArray[numpy.float64[?, ?, ?]]"
) )
assert ( assert (
doc(m.copy_fixed_tensor) doc(m.copy_fixed_tensor)