Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use numba implementation of multidimensional Hermite polynomials #295

Merged
merged 30 commits into from
Nov 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aca149d
refactor [hermite_multidimensional] - use numba implementation instea…
sduquemesa Nov 4, 2021
582b336
refactor [hermite_multidimensional] - remove libwalrus dependency
sduquemesa Nov 4, 2021
e3c8d67
remove unused imports
sduquemesa Nov 4, 2021
cf9b447
fix [hermite_multidimensiona] - make_tensor
sduquemesa Nov 4, 2021
bbe827e
refactor [test_hermite_multidimensional] - use numba impl
sduquemesa Nov 4, 2021
a23b398
fix [hermite_multidimensional] - missing param on un-modified case
sduquemesa Nov 4, 2021
09f6b36
remove [test_hermite_multidimensional] - numba vs c++ check
sduquemesa Nov 4, 2021
57f4af7
refactor [test_hermite_multidimensional] - test_auto_dtype: use hermi…
sduquemesa Nov 4, 2021
76d736a
refactor [tests/test_grad_...] - remove reference to `hermite_multidi…
sduquemesa Nov 4, 2021
0d1c90a
refactor [thewalrus] - remove references to `_hermite_multidimensiona…
sduquemesa Nov 4, 2021
0bdf662
impl+test [_hermite_multidimension] - interferometer
sduquemesa Nov 5, 2021
a02cd1a
refactor [quantum/fock_tensor] - use numba impl of interferometer
sduquemesa Nov 5, 2021
2172393
refactor [hermite_multidimensional] - rename grad(...)_numba to grad(…
sduquemesa Nov 5, 2021
d87134e
refactor [test_hermite_...] - parametrize interferometer_vs_hermite
sduquemesa Nov 5, 2021
3875f70
impl [hermite_multd...] - grad_hermite for normalized and regular polys
sduquemesa Nov 5, 2021
ba7795f
fix [tw/__init__] - rename variable
sduquemesa Nov 5, 2021
134aacf
test [_hermite_multidimension] - interferometer: renorm True and False
sduquemesa Nov 9, 2021
fe5e6d9
refactor [_hermite_multidimension] - rename `array to `G` to match eq…
sduquemesa Nov 9, 2021
5d45c81
test [hermite_mult] - interferometer: add test case for array input
sduquemesa Nov 9, 2021
339fb8a
fix [test_hermite_...] - test_grad_..._vs_finite_differences: add mis…
sduquemesa Nov 9, 2021
e689a86
fix [test_hermite_...] - interferometer_vs_hermite: fix parametrization
sduquemesa Nov 9, 2021
e4c55b3
doc [_hermite_multi] - hermite_multidimensional: improve docstring us…
sduquemesa Nov 9, 2021
1c61820
test [hermite_mult] - interferometer: fix test parametrization for fu…
sduquemesa Nov 9, 2021
0ce437f
fix [docs] - hyperlinks
sduquemesa Nov 9, 2021
3f16655
delete [hermite_mult...hpp] - plus related references and tests
sduquemesa Nov 11, 2021
aecdd2f
removes imports in libwalrus.pyx
Nov 11, 2021
5120e20
Removes unused classes
Nov 12, 2021
3882112
Update thewalrus/libwalrus.pyx
nquesada Nov 12, 2021
a0b98e9
update [github] - acknowledgments and changelog
sduquemesa Nov 12, 2021
1e8f65c
Merge branch 'numba-hermite-multidimensional' of https://github.com/X…
sduquemesa Nov 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removes unused classes
  • Loading branch information
Nicolas Quesada committed Nov 12, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5120e20d3011586787dd71254f0a7bc42c316ce0
89 changes: 0 additions & 89 deletions thewalrus/libwalrus.pyx
Original file line number Diff line number Diff line change
@@ -23,95 +23,6 @@ from libcpp.vector cimport vector
np.import_array()


cdef class ArrayWrapper:
"""Wrapper class to pass arrays of complex doubles transparently between
C++ and python.
Modified from:
https://stackoverflow.com/questions/45133276/passing-c-vector-to-numpy-through-cython-without-copying-and-taking-care-of-me
"""
cdef void* data_ptr
cdef int size

cdef set_data(self, int size, void* data_ptr):
self.data_ptr = data_ptr
self.size = size

def __array__(self):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> self.size
ndarray = np.PyArray_SimpleNewFromData(1, shape,
np.NPY_COMPLEX128, self.data_ptr)
return ndarray

def __dealloc__(self):
free(<void*>self.data_ptr)


cdef class ArrayWrapperFloat:
"""Wrapper class to pass arrays of doubles transparently between
C++ and python.
Modified from:
https://stackoverflow.com/questions/45133276/passing-c-vector-to-numpy-through-cython-without-copying-and-taking-care-of-me
"""
cdef void* data_ptr
cdef int size

cdef set_data(self, int size, void* data_ptr):
self.data_ptr = data_ptr
self.size = size

def __array__(self):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> self.size
ndarray = np.PyArray_SimpleNewFromData(1, shape,
np.NPY_FLOAT64, self.data_ptr)
return ndarray

def __dealloc__(self):
free(<void*>self.data_ptr)


cdef double_pointer_to_array(double *array, int length):
"""Converts a pointer of C doubles into a numpy array.

Args:
array (double*): pointer of double
length (int): size of the array

Returns:
array[float64]: a numpy array with the contents of the input array
"""

cdef np.ndarray ndarray
array_wrapper = ArrayWrapperFloat()
array_wrapper.set_data(length, <void*> array)
ndarray = np.array(array_wrapper, copy=False)
ndarray.base = <PyObject*> array_wrapper
Py_INCREF(array_wrapper)
return ndarray


cdef complex_pointer_to_array(double complex *array, int length):
"""Converts a pointer of C complex doubles into a numpy array.

Args:
array (double complex*): pointer of double
length (int): size of the array

Returns:
array[complex128]: a numpy array with the contents of the input array
"""

cdef np.ndarray ndarray
array_wrapper = ArrayWrapper()
array_wrapper.set_data(length, <void*> array)
ndarray = np.array(array_wrapper, copy=False)
ndarray.base = <PyObject*> array_wrapper
Py_INCREF(array_wrapper)
return ndarray



cdef extern from "../include/libwalrus.hpp" namespace "libwalrus":
T hafnian[T](vector[T] &mat)
T hafnian_recursive[T](vector[T] &mat)