Skip to content

Commit

Permalink
Cast to c_long in RxD on Python side before passing to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
kbvw committed Aug 22, 2024
1 parent 879d2e4 commit 7b9e1be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions share/lib/python/neuron/rxd/rxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
setup_solver.argtypes = [
ndpointer(ctypes.c_double),
ctypes.c_int,
numpy.ctypeslib.ndpointer(numpy.int_, flags="contiguous"),
numpy.ctypeslib.ndpointer(ctypes.c_long, flags="contiguous"),
ctypes.c_int,
]

Expand Down Expand Up @@ -630,8 +630,8 @@ def _matrix_to_rxd_sparse(m):
return (
n,
len(nonzero_i),
numpy.ascontiguousarray(nonzero_i, dtype=numpy.int_),
numpy.ascontiguousarray(nonzero_j, dtype=numpy.int_),
numpy.ascontiguousarray(nonzero_i, dtype=ctypes.c_long),
numpy.ascontiguousarray(nonzero_j, dtype=ctypes.c_long),
nonzero_values,
)

Expand Down Expand Up @@ -709,7 +709,7 @@ def _setup_matrices():
n = len(_node_get_states())

volumes = node._get_data()[0]
zero_volume_indices = (numpy.where(volumes == 0)[0]).astype(numpy.int_)
zero_volume_indices = (numpy.where(volumes == 0)[0]).astype(ctypes.c_long)
if species._has_1d:
# TODO: initialization is slow. track down why
for sr in _species_get_all_species():
Expand Down Expand Up @@ -1896,7 +1896,7 @@ def _init():
_setup_matrices()
# if species._has_1d and species._1d_submatrix_n():
# volumes = node._get_data()[0]
# zero_volume_indices = (numpy.where(volumes == 0)[0]).astype(numpy.int_)
# zero_volume_indices = (numpy.where(volumes == 0)[0]).astype(ctypes.c_long)
# setup_solver(_node_get_states(), len(_node_get_states()), zero_volume_indices, len(zero_volume_indices), h._ref_t, h._ref_dt)
clear_rates()
_setup_memb_currents()
Expand Down
12 changes: 6 additions & 6 deletions share/lib/python/neuron/rxd/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
ctypes.c_int,
ctypes.py_object,
ctypes.c_long,
numpy.ctypeslib.ndpointer(dtype=int),
numpy.ctypeslib.ndpointer(dtype=int),
numpy.ctypeslib.ndpointer(dtype=ctypes.c_long),
numpy.ctypeslib.ndpointer(dtype=ctypes.c_long),
ctypes.c_long,
numpy.ctypeslib.ndpointer(dtype=int),
numpy.ctypeslib.ndpointer(dtype=ctypes.c_long),
ctypes.c_long,
numpy.ctypeslib.ndpointer(dtype=int),
numpy.ctypeslib.ndpointer(dtype=ctypes.c_long),
ctypes.c_long,
numpy.ctypeslib.ndpointer(dtype=float),
ctypes.c_double,
Expand Down Expand Up @@ -842,7 +842,7 @@ def line_defs(self, nodes, direction, nodes_length):

# sort list for parallelization
line_defs.sort(key=lambda x: x[1], reverse=True)
line_defs = numpy.asarray(line_defs, dtype=int)
line_defs = numpy.asarray(line_defs, dtype=ctypes.c_long)
line_defs = line_defs.reshape(2 * len(line_defs))
return line_defs

Expand All @@ -862,7 +862,7 @@ def ordered_nodes(self, p_line_defs, direction, neighbors):

def create_neighbors_array(self, nodes, nodes_length):
self._isalive()
my_array = numpy.zeros((nodes_length, 3), dtype=int)
my_array = numpy.zeros((nodes_length, 3), dtype=ctypes.c_long)
for n in nodes:
for i, ele in enumerate(n.neighbors[::2]):
my_array[n._index, i] = ele if ele is not None else -1
Expand Down
3 changes: 2 additions & 1 deletion test/rxd/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path as osp
import numpy
import ctypes
import pytest
import gc

Expand Down Expand Up @@ -81,7 +82,7 @@ def neuron_nosave_instance(neuron_import):
rxd.rxd.rxd_include_node_flux1D(0, None, None, None)
rxd.species._has_1d = False
rxd.species._has_3d = False
rxd.rxd._zero_volume_indices = numpy.ndarray(0, dtype=numpy.int_)
rxd.rxd._zero_volume_indices = numpy.ndarray(0, dtype=ctypes.c_long)
rxd.set_solve_type(dimension=1)


Expand Down

0 comments on commit 7b9e1be

Please sign in to comment.