Skip to content

Commit e7474d9

Browse files
Add proper support for constants
1 parent 2705447 commit e7474d9

File tree

6 files changed

+327
-72
lines changed

6 files changed

+327
-72
lines changed

libsemigroups_pybind11/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2021, J. D. Mitchell
3+
# Copyright (c) 2021-2022, J. D. Mitchell
44
#
55
# Distributed under the terms of the GPL license version 3.
66
#
@@ -9,11 +9,12 @@
99
# pylint: disable=no-name-in-module
1010

1111
"""
12-
This package provides a the user-facing python part of libsemigroups_pybind11
12+
This package provides the user-facing python part of libsemigroups_pybind11
1313
"""
1414

1515
from _libsemigroups_pybind11 import (
1616
PBR,
17+
NEGATIVE_INFINITY,
1718
POSITIVE_INFINITY,
1819
UNDEFINED,
1920
ActionDigraph,

libsemigroups_pybind11/matrix.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,34 @@ class MatrixKind(Enum):
5555
}
5656

5757

58+
def _convert_matrix_args(*args):
59+
if not (len(args) == 1 and isinstance(*args, list)):
60+
return args
61+
# Convert POSITIVE_INFINITY and NEGATIVE_INFINITY to integers
62+
return (
63+
[[z if isinstance(z, int) else z.to_int() for z in y] for y in args[0]],
64+
)
65+
66+
5867
def Matrix(kind: MatrixKind, *args):
5968
"""
6069
Constructs a matrix, basically just delegates to
6170
_libsemigroups_pybind11
6271
"""
6372
if not isinstance(kind, MatrixKind):
6473
raise TypeError("the 1st argument must be a MatrixKind")
65-
return _Matrix[kind](*args)
74+
return _Matrix[kind](*_convert_matrix_args(*args))
6675

6776

6877
def make_identity(kind: MatrixKind, *args) -> Matrix:
6978
"""
7079
Construct the identity matrix of the appropriate type.
7180
"""
72-
return _Matrix[kind].make_identity(*args)
81+
return _Matrix[kind].make_identity(*_convert_matrix_args(*args))
7382

7483

7584
def make(kind: MatrixKind, *args) -> Matrix:
7685
"""
7786
Construct a matrix of the appropriate type.
7887
"""
79-
return _Matrix[kind].make(*args)
88+
return _Matrix[kind].make(*_convert_matrix_args(*args))

0 commit comments

Comments
 (0)