Skip to content

Commit

Permalink
Fixed bugs in the C code; fixed name of the module in setup.cfg and i…
Browse files Browse the repository at this point in the history
…n funcoitn that loads modules in C.
  • Loading branch information
droodev committed Nov 11, 2024
1 parent 1bea10a commit fe40498
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var/
pip-log.txt
pip-delete-this-directory.txt

# VIM swp files
*.swp

# Unit test / coverage reports
htmlcov/
.tox/
Expand Down
1 change: 0 additions & 1 deletion permanentbis/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
ext_modules=[
Extension(
'permanentbis.permanent', ['./src/permanent.c'],
'permanentbis', ['./src/permanent.c'],
extra_compile_args=["-Ofast", "-march=native"],
include_dirs=[numpy.get_include()]),
],
Expand Down
2 changes: 1 addition & 1 deletion src/npy_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void complex_inc(npy_complex128 *a, npy_complex128 b) {
((double *)a)[1] = cimag(tmp);
return;
#else /* !defined(_MSC_VER) */
*a *= b;
*a += b;
#endif
return;
}
Expand Down
16 changes: 8 additions & 8 deletions src/permanent.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ static PyObject *permanent(PyObject *self, PyObject *args);

// Method list
static PyMethodDef methods[] = {
{ "permanentbis", permanent, METH_VARARGS, "Computes the permanent of a numpy using the most appropriate method available"},
{ "permanent", permanent, METH_VARARGS, "Computes the permanent of a numpy using the most appropriate method available"},
{ NULL, NULL, 0, NULL } // Sentinel
};


#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef cModPyDem =
{
PyModuleDef_HEAD_INIT,
"permanentbis", "Computes the permanent of a numpy using the most appropriate method available",
-1,
methods
PyModuleDef_HEAD_INIT,
"permanentbis", "Computes the permanent of a numpy using the most appropriate method available",
-1,
methods
};

PyMODINIT_FUNC
PyInit_permanent(void)
PyInit_permanentbis(void)
{
import_array();
return PyModule_Create(&cModPyDem);
import_array();
return PyModule_Create(&cModPyDem);
}

#else
Expand Down
3 changes: 2 additions & 1 deletion tests/test_permanent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import numpy as np
from permanentbis.permanent import permanent
from permanentbis import permanent
import pytest


def test_permanent():
""" Test that basic functions work right """
m = np.eye(10, dtype=complex)
print(permanent(m))
assert permanent(m) == 1
m = np.zeros((10, 10), dtype=complex)
assert permanent(m) == 0
Expand Down

0 comments on commit fe40498

Please sign in to comment.