Skip to content

Commit c8c6813

Browse files
Finalize
1 parent 29b1c04 commit c8c6813

3 files changed

Lines changed: 49 additions & 24 deletions

File tree

docs/source/data-structures/elements/matrix/matrix.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The Matrix class
1717
MatrixKind
1818
----------
1919

20+
.. TODO move MatrixKind to the "enums" page when it exists
21+
2022
.. autoclass:: MatrixKind
2123
:show-inheritance:
2224

@@ -26,9 +28,19 @@ Contents
2628
.. autosummary::
2729
:signatures: short
2830

29-
~Matrix
30-
31-
.. TODO complete
31+
Matrix.__init__
32+
Matrix.copy
33+
Matrix.degree
34+
Matrix.number_of_cols
35+
Matrix.number_of_rows
36+
Matrix.one
37+
Matrix.product_inplace
38+
Matrix.row
39+
Matrix.rows
40+
Matrix.scalar_one
41+
Matrix.scalar_zero
42+
Matrix.swap
43+
Matrix.transpose
3244

3345
Full API
3446
--------

src/libsemigroups_pybind11/matrix.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,40 +148,54 @@ def __init__(self: _Self, kind: MatrixKind, *args) -> None:
148148
self.py_template_params = (kind,)
149149
self.init_cxx_obj(*args)
150150

151-
def __getitem__(self: _Self, *args) -> _Union[int, _Self]:
151+
def __getitem__(
152+
self: _Self, *args
153+
) -> _Union[int, _Self, _PositiveInfinity, _NegativeInfinity]:
152154
return _to_cxx(self).__getitem__(*args)
153155

154156
def __setitem__(self: _Self, *args):
155157
return _to_cxx(self).__setitem__(*args)
156158

157-
def __imul__(self: _Self, that: _Self | int) -> _Self:
159+
def __imul__(
160+
self: _Self,
161+
that: _Union[_Self, int, _PositiveInfinity, _NegativeInfinity],
162+
) -> _Self:
158163
return _to_cxx(self).__imul__(that)
159164

160-
def __mul__(self: _Self, that: _Self | int) -> _Self:
165+
def __mul__(
166+
self: _Self,
167+
that: _Union[_Self, int, _PositiveInfinity, _NegativeInfinity],
168+
) -> _Self:
161169
return _to_cxx(self).__mul__(that)
162170

163-
def __iadd__(self: _Self, that: _Self | int) -> _Self:
171+
def __iadd__(
172+
self: _Self,
173+
that: _Union[_Self, int, _PositiveInfinity, _NegativeInfinity],
174+
) -> _Self:
164175
return _to_cxx(self).__iadd__(that)
165176

166-
def __add__(self: _Self, that: _Self | int) -> _Self:
177+
def __add__(
178+
self: _Self,
179+
that: _Union[_Self, int, _PositiveInfinity, _NegativeInfinity],
180+
) -> _Self:
167181
return _to_cxx(self).__add__(that)
168182

169-
def __gt__(self: _Self, that: _Self | int) -> bool:
183+
def __gt__(self: _Self, that: _Union[_Self, int]) -> bool:
170184
return _to_cxx(self).__gt__(that)
171185

172-
def __ge__(self: _Self, that: _Self | int) -> bool:
186+
def __ge__(self: _Self, that: _Union[_Self, int]) -> bool:
173187
return _to_cxx(self).__ge__(that)
174188

175-
def __ne__(self: _Self, that: _Self | int) -> bool:
189+
def __ne__(self: _Self, that: _Union[_Self, int]) -> bool:
176190
return _to_cxx(self).__ne__(that)
177191

178-
def __eq__(self: _Self, that: _Self | int) -> bool:
192+
def __eq__(self: _Self, that: _Union[_Self, int]) -> bool:
179193
return _to_cxx(self).__eq__(that)
180194

181-
def __lt__(self: _Self, that: _Self | int) -> bool:
195+
def __lt__(self: _Self, that: _Union[_Self, int]) -> bool:
182196
return _to_cxx(self).__lt__(that)
183197

184-
def __le__(self: _Self, that: _Self | int) -> bool:
198+
def __le__(self: _Self, that: _Union[_Self, int]) -> bool:
185199
return _to_cxx(self).__le__(that)
186200

187201
def __len__(self: _Self) -> int:

src/matrix.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,12 @@ Construct an uninitialized `r` by `c` matrix.
764764
py::init(
765765
[](size_t threshold,
766766
std::vector<std::vector<int_or_constant<scalar_type>>> const&
767-
entries) {
767+
rows) {
768768
return make<Mat>(semiring<semiring_type>(threshold),
769-
to_ints<scalar_type>(entries));
769+
to_ints<scalar_type>(rows));
770770
}),
771771
R"pbdoc(
772-
:sig=(self: Matrix, kind: MatrixKind, threshold: int, period: int, rows: list[list[int | PositiveInfinity | NegativeInfinity]]) -> None
772+
:sig=(self: Matrix, kind: MatrixKind, threshold: int, rows: list[list[int | PositiveInfinity | NegativeInfinity]]) -> None:
773773
774774
Construct a matrix from threshold and rows.
775775
@@ -779,13 +779,12 @@ Construct a matrix from threshold and rows.
779779
:param threshold: the threshold of the underlying semiring.
780780
:type threshold: int
781781
782-
:param period: the period of the underlying semiring.
783-
:type period: int
784-
785782
:param rows: the rows of the matrix.
786783
:type rows: list[list[int | PositiveInfinity | NegativeInfinity]]
787784
788-
:raise RunTimeError: if *kind* is not :py:attr:`MatrixKind.NTP`.
785+
:raise RunTimeError:
786+
if *kind* is not :py:attr:`MatrixKind.MaxPlusTrunc` or
787+
:py:attr:`MatrixKind.MinPlusTrunc`.
789788
790789
:raise LibsemigroupsError:
791790
if the entries in *rows* are not of equal length.
@@ -841,7 +840,7 @@ that is a matrix whose kind is any of:
841840
to_ints<scalar_type>(entries));
842841
}),
843842
R"pbdoc(
844-
:sig=(self: Matrix, kind: MatrixKind, threshold: int, period: int, rows: list[list[int | PositiveInfinity | NegativeInfinity]]) -> None:
843+
:sig=(self: Matrix, kind: MatrixKind, threshold: int, period: int, rows: list[list[int]]) -> None:
845844
846845
Construct a matrix from threshold, period, and rows.
847846
@@ -855,7 +854,7 @@ Construct a matrix from threshold, period, and rows.
855854
:type period: int
856855
857856
:param rows: the rows of the matrix.
858-
:type rows: list[list[int | PositiveInfinity | NegativeInfinity]]
857+
:type rows: list[list[int]]
859858
860859
:raise RunTimeError: if *kind* is not :py:attr:`MatrixKind.NTP`.
861860
@@ -872,7 +871,7 @@ Construct a matrix from threshold, period, and rows.
872871
R"pbdoc(
873872
:sig=(self: Matrix, kind: MatrixKind, threshold: int, period: int, r: int, c: int) -> None:
874873
875-
Construct an uninitialized `r` by `c` matrix.
874+
Construct an uninitialized `r` by `c` matrix with threshold and period.
876875
877876
:param kind: specifies the underlying semiring.
878877
:type kind: MatrixKind

0 commit comments

Comments
 (0)