Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Commit 5d820d5

Browse files
author
James Mitchell
committed
py: initial python-bindings
0 parents  commit 5d820d5

9 files changed

+707
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
semigroups.cpp
2+
*.so
3+
build
4+
*.egg-info

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python bindings for libsemigroups
2+
3+
## Basic instructions
4+
5+
git clone ...
6+
7+
cd libsemigroups
8+
make
9+
sudo make install
10+
sudo ldconfig
11+
12+
cd python-bindings
13+
pip3 install --user . --upgrade
14+
15+
python3
16+
17+
>>> from semigroups import Semigroup, Transformation
18+
>>> S = Semigroup([Transformation([1,1,4,5,4,5]),Transformation([2,3,2,3,5,5])])
19+
>>> S.size()
20+
5
21+
22+
## Trick to debug segmentation faults
23+
24+
Install Sage
25+
26+
Install gdb in Sage:
27+
28+
sage -i gdb
29+
30+
Run sage as:
31+
32+
sage -gdb
33+
34+
and type the commands that trigger the segfault. Then gdb will be
35+
fired automatically, allowing for analysing the stack trace.
36+
37+
## [TODO list](TODO)

TODO

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# TODO
2+
3+
## Automatic generation of the .pxd file?
4+
5+
xdress maybe? did not manage to install: complaining when trying to
6+
link against clang libraries that are provided as static libraries.
7+
8+
## Automatic generation of the Python wrappers?
9+
10+
## Fetch features from Sage's experimental interface to Semigroupe
11+
12+
https://trac.sagemath.org/attachment/ticket/8360/trac_8360_semigroupe-interface-nt.patch
13+
14+
## Use pos_t rather than size_t everywhere relevant
15+
16+
Problem: pos_t is a private typedef in the Semigroup class; this makes
17+
it harder to use it elsewhere
18+
19+
## new_from_handle would naturally be a class method
20+
21+
Question: how to achieve this in Cython?
22+
23+
## libsemigroups configuration
24+
25+
- DEFAULT_REPORT_VALUE : is there a gain in making it a const?
26+
- DEFAULT_NR_THREADS : make a new default value? or an attribute of the semigroup?
27+
28+
## Fix memory management
29+
30+
Problem: when we get back a pointer to an Element from libsemigroup;
31+
when shall we consider that we own it or not?
32+
33+
At this stage when semigroups.pyx returns a wrapper around a
34+
libsemigroup element, it is always assumed that libsemigroup owns that
35+
element. Which is wrong when the element is part of the internal data
36+
structure for the semigroup. This quickly leads to segmentation faults
37+
with the following backtrace:
38+
39+
#1 0x00007ffef6343ef3 in __pyx_pf_10semigroups_7Element_2__dealloc__ (__pyx_v_self=0x7ffff011baf0) at semigroups.cpp:1382
40+
#2 __pyx_pw_10semigroups_7Element_3__dealloc__ (__pyx_v_self=) at semigroups.cpp:1354
41+
#3 __pyx_tp_dealloc_10semigroups_Element (o=) at semigroups.cpp:3240
42+
#4 0x00007ffff7a44711 in list_dealloc (op=) at Objects/listobject.c:309
43+
#5 0x00007ffff7a56c13 in PyDict_Clear (op=<optimized out>) at Objects/dictobject.c:946
44+
#6 0x00007ffff7a56c99 in dict_clear (mp=<optimized out>) at Objects/dictobject.c:2028
45+
#7 0x00007ffff7ac9ef2 in call_function (oparg=<optimized out>, pp_stack=0x7fffffffc370) at Python/ceval.c:4336
46+
47+
How to fix this?
48+
49+
Plausibly, we should
50+
51+
- have a parameter in new_from_handle to decide whether the instance
52+
owns the handle or is just a view on it.
53+
54+
- review all methods of Semigroup, and call new_from_handle appropriately

0 commit comments

Comments
 (0)