mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
PEP 465: a dedicated infix operator for matrix multiplication (closes #21176)
This commit is contained in:
parent
2aad6ef774
commit
d51374ed78
42 changed files with 803 additions and 442 deletions
|
@ -4469,6 +4469,8 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
|
|||
COPYNUM(nb_inplace_true_divide);
|
||||
COPYNUM(nb_inplace_floor_divide);
|
||||
COPYNUM(nb_index);
|
||||
COPYNUM(nb_matrix_multiply);
|
||||
COPYNUM(nb_inplace_matrix_multiply);
|
||||
}
|
||||
|
||||
if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
|
||||
|
@ -5605,6 +5607,7 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
|
|||
SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__")
|
||||
SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__")
|
||||
SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__")
|
||||
SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, "__matmul__", "__rmatmul__")
|
||||
SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__")
|
||||
SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__")
|
||||
|
||||
|
@ -5698,6 +5701,7 @@ SLOT0(slot_nb_float, "__float__")
|
|||
SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
|
||||
SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
|
||||
SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
|
||||
SLOT1(slot_nb_inplace_matrix_multiply, "__imatmul__", PyObject *, "O")
|
||||
SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *, "O")
|
||||
/* Can't use SLOT1 here, because nb_inplace_power is ternary */
|
||||
static PyObject *
|
||||
|
@ -6278,6 +6282,12 @@ static slotdef slotdefs[] = {
|
|||
"__index__($self, /)\n--\n\n"
|
||||
"Return self converted to an integer, if self is suitable"
|
||||
"for use as an index into a list."),
|
||||
BINSLOT("__matmul__", nb_matrix_multiply, slot_nb_matrix_multiply,
|
||||
"@"),
|
||||
RBINSLOT("__rmatmul__", nb_matrix_multiply, slot_nb_matrix_multiply,
|
||||
"@"),
|
||||
IBSLOT("__imatmul__", nb_inplace_matrix_multiply, slot_nb_inplace_matrix_multiply,
|
||||
wrap_binaryfunc, "@="),
|
||||
MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc,
|
||||
"__len__($self, /)\n--\n\nReturn len(self)."),
|
||||
MPSLOT("__getitem__", mp_subscript, slot_mp_subscript,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue