Skip to content

Commit

Permalink
Drops support for int arrays #1
Browse files Browse the repository at this point in the history
Appears to remedy issues mentioned in #4
  • Loading branch information
chrisk314 committed Jun 27, 2018
1 parent e9fc7a7 commit aa051fa
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 100 deletions.
31 changes: 0 additions & 31 deletions pystreamline/src/streamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,6 @@ int StreamlineIntegrator::interpolate_vec_at_point(double *pos, double *vec)
}


int StreamlineIntegrator::add_int_array(std::string name, int *arr)
{
if ( var_store_int.find(name) == var_store_int.end() )
var_store_int.insert({name, arr});
else
var_store_int[name] = arr;
return 0;
}


int* StreamlineIntegrator::get_int_array_with_name(std::string name)
{
if ( var_store_int.find(name) == var_store_int.end() )
{
char message[100];
sprintf(message, "key: %s not in int store", name.c_str());
throw std::invalid_argument(message);
}
else
{
return var_store_int[name];
}
}


std::vector<std::string> StreamlineIntegrator::get_int_array_names()
{
return extract_keys_from_unordered_map(var_store_int);
}


int StreamlineIntegrator::add_double_array(std::string name, double *arr)
{
if ( var_store_double.find(name) == var_store_double.end() )
Expand Down
4 changes: 0 additions & 4 deletions pystreamline/src/streamline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class StreamlineIntegrator
double bounds[6];
struct kdtree *tree;

std::unordered_map<std::string, int*> var_store_int;
std::unordered_map<std::string, double*> var_store_double;

double interp_lscale = 0., neg_inv_interp_lscale_sq = 0.;
Expand All @@ -39,9 +38,6 @@ class StreamlineIntegrator
int get_points_in_range(double, double, double, double, int*, int**, double**);
int interpolate_vec_at_point(double*, double*);

int add_int_array(std::string, int*);
std::vector<std::string> get_int_array_names();
int* get_int_array_with_name(std::string);
int add_double_array(std::string, double*);
std::vector<std::string> get_double_array_names();
double* get_double_array_with_name(std::string);
Expand Down
26 changes: 0 additions & 26 deletions pystreamline/streamline_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ cdef extern from "src/streamline.hpp" namespace "PyStreamline":
int set_interp_lscale(double);
int get_points_in_range(double, double, double, double, int*, int**, double**);
int interpolate_vec_at_point(double*, double*);
int add_int_array(string, int*);
int* get_int_array_with_name(string);
vector[string] get_int_array_names();
int add_double_array(string, double*);
double* get_double_array_with_name(string);
vector[string] get_double_array_names();
Expand Down Expand Up @@ -89,29 +86,6 @@ cdef class _StreamlineIntegrator__wrapper:
cdef np.float64_t[:] view = <np.float64_t[:6]> self.thisptr.get_bounds()
return np.asarray(view).reshape((3,2))

def add_int_array(self, name, np.ndarray[np.int32_t, ndim=1, mode='c'] arr):
cdef c_name = <string> name.encode('utf-8')
arr = np.ascontiguousarray(arr, dtype=np.int32)
self.thisptr.add_int_array(c_name, <int*> arr.data)

def add_int_arrays(self, arr_list):
for name, arr in arr_list:
self.add_int_array(name, arr)

@property
def int_array_names(self):
c_str_vector = self.thisptr.get_int_array_names()
return [b.decode('utf-8') for b in c_str_vector]

def get_int_array_with_name(self, name):
try:
assert name in self.int_array_names
except AssertionError:
raise ValueError('No int array with name: {:s}'.format(name))
cdef string c_name = <string> name.encode('utf-8')
cdef int* c_arr_ptr = <int*> self.thisptr.get_int_array_with_name(c_name)
return data_to_numpy_int_array_with_spec(c_arr_ptr, self.n_points)

def add_double_array(self, name, np.ndarray[np.float64_t, ndim=1, mode='c'] arr):
cdef c_name = <string> name.encode('utf-8')
arr = np.ascontiguousarray(arr, dtype=np.double)
Expand Down
39 changes: 0 additions & 39 deletions pystreamline/tests/test_streamlineintegrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,6 @@ def test_StreamlineIntegrator_ctor(self):
self.streamline_integrator.get_bounds()
)

def test_StreamlineIntegrator_var_store_int(self):
# Tests ``arr1`` data can be set correctly
arr1 = npr.randint(0, 100, self.n_points, dtype=np.int32)
self.streamline_integrator.add_int_array('arr1', arr1)
np.testing.assert_allclose(
arr1, self.streamline_integrator.get_int_array_with_name('arr1')
)

# Tests ``arr1`` data can be overwritten correctly
arr1 = npr.randint(0, 100, self.n_points, dtype=np.int32)
self.streamline_integrator.add_int_array('arr1', arr1)
np.testing.assert_allclose(
arr1, self.streamline_integrator.get_int_array_with_name('arr1')
)

# Tests setting multiple data arrays at once
arrs = [
('arr2', npr.randint(0, 100, self.n_points, dtype=np.int32)),
('arr3', npr.randint(0, 100, self.n_points, dtype=np.int32))
]
self.streamline_integrator.add_int_arrays(arrs)
np.testing.assert_allclose(
arrs[0][1], self.streamline_integrator.get_int_array_with_name('arr2')
)
np.testing.assert_allclose(
arrs[1][1], self.streamline_integrator.get_int_array_with_name('arr3')
)

# Tests array names are stored and recovered correctly
assert set(('arr1', 'arr2', 'arr3')) == set(self.streamline_integrator.int_array_names)

# Tests exception is raised when array name is not present
with self.assertRaises(ValueError):
self.streamline_integrator.get_int_array_with_name('arr4')

def test_StreamlineIntegrator_var_store_double(self):
"""Tests that double arrays are passed correctly between Python and C++,
and stored correctly.
Expand All @@ -79,9 +44,6 @@ def test_StreamlineIntegrator_var_store_double(self):
arr1, self.streamline_integrator.get_double_array_with_name('arr1')
)

# TODO : running with this code causes segfault.
# -->
# Tests setting multiple data arrays at once
arrs = [
('arr2', npr.random(self.n_points)),
('arr3', npr.random(self.n_points))
Expand All @@ -93,7 +55,6 @@ def test_StreamlineIntegrator_var_store_double(self):
np.testing.assert_allclose(
arrs[1][1], self.streamline_integrator.get_double_array_with_name('arr3')
)
# <--

# Tests array names are stored and recovered correctly
assert set(('arr1', 'arr2', 'arr3')) == set(self.streamline_integrator.double_array_names)
Expand Down

0 comments on commit aa051fa

Please sign in to comment.