CKTIS / Python
Operator @
Requests matrix multiplication through the operand protocol.
Version: Python 3.14; repository image, production runtime not attested
Syntax
left @ rightRequests matrix multiplication through the operand protocol.
Use matrix multiplication to compose linear transformations when the operand types implement the operation. Python supplies the operator syntax while the classes determine the dimensions, computation and result type.
In the row class shown here, matching positions are multiplied and their products are added. Pairing with strict length checking rejects unequal dimensions. With built-in numeric or tuple operands alone, matrix multiplication raises a type error.
Built-in tuples supply no matrix product. This row class implements a dot product and requires equal dimensions; its empty dot product is zero.
Syntax
left @ right
__matmul__, __rmatmul__ · TypeError
Worked example
(2, 5) @ (3, 4) → TypeError
Row((2, 5)) @ (3, 4) → 2*3 + 5*4 → 26
Row((2, 5)) @ (3,) → ValueError
Examples
class Row(tuple):
def __matmul__(self, column):
return sum(x * y for x, y in zip(self, column, strict=True))
row = Row((2, 5))
column = (3, 4)
print(row @ column)
print(Row(()) @ ())
Result
26 0
Built-in tuples supply no matrix product. This row class implements a dot product and requires equal dimensions; its empty dot product is zero.