Skip to content

Commit

Permalink
add test for longlong
Browse files Browse the repository at this point in the history
  • Loading branch information
fbordeu committed Nov 29, 2024
1 parent 9c2fc83 commit b379725
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/eigency_tests/eigency_tests.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ cdef extern from "eigency_tests/eigency_tests_cpp.h":
cdef PlainObjectBase _function_type_double "function_type_double" (Map[ArrayXXd] &)
cdef PlainObjectBase _function_type_float "function_type_float" (Map[ArrayXXf] &)
cdef PlainObjectBase _function_type_long "function_type_long" (FlattenedMap[Array, long, Dynamic, Dynamic] &)
cdef PlainObjectBase _function_type_long_long "function_type_long_long" (FlattenedMap[Array, long long, Dynamic, Dynamic] &)
cdef PlainObjectBase _function_type_ulong "function_type_ulong" (FlattenedMap[Array, unsigned long, Dynamic, Dynamic] &)
cdef PlainObjectBase _function_type_ulong_long "function_type_ulong_long" (FlattenedMap[Array, unsigned long long, Dynamic, Dynamic] &)
cdef PlainObjectBase _function_type_int "function_type_int" (Map[ArrayXXi] &)
cdef PlainObjectBase _function_type_uint "function_type_uint" (FlattenedMap[Array, unsigned int, Dynamic, Dynamic] &)
cdef PlainObjectBase _function_type_short "function_type_short" (FlattenedMap[Array, short, Dynamic, Dynamic] &)
Expand Down Expand Up @@ -151,10 +153,18 @@ def function_type_float32(np.ndarray[np.float32_t, ndim=2] array):
def function_type_long(np.ndarray[long, ndim=2] array):
return ndarray(_function_type_long(FlattenedMap[Array, long, Dynamic, Dynamic](array)))

# Functions with different matrix types: long long
def function_type_long_long(np.ndarray[long long, ndim=2] array):
return ndarray(_function_type_long_long(FlattenedMap[Array, longlong, Dynamic, Dynamic](array)))

# Functions with different matrix types: ulong
def function_type_ulong(np.ndarray[unsigned long, ndim=2] array):
return ndarray(_function_type_ulong(FlattenedMap[Array, ulong, Dynamic, Dynamic](array)))

# Functions with different matrix types: ulong long
def function_type_ulong_long(np.ndarray[unsigned long long, ndim=2] array):
return ndarray(_function_type_ulong_long(FlattenedMap[Array, ulonglong, Dynamic, Dynamic](array)))

# Functions with different matrix types: int
def function_type_intc(np.ndarray[np.int32_t, ndim=2] array):
return ndarray(_function_type_int(Map[ArrayXXi](array)))
Expand Down
11 changes: 11 additions & 0 deletions tests/eigency_tests/eigency_tests_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ Eigen::Array<long, Eigen::Dynamic, Eigen::Dynamic> function_type_long(Eigen::Map
return output;
}

Eigen::Array<long long, Eigen::Dynamic, Eigen::Dynamic> function_type_long_long(Eigen::Map<Eigen::Array<long long, Eigen::Dynamic, Eigen::Dynamic> > &mat) {
Eigen::Array<long long, Eigen::Dynamic, Eigen::Dynamic> output = mat;
return output;
}

Eigen::Array<unsigned long, Eigen::Dynamic, Eigen::Dynamic> function_type_ulong(Eigen::Map<Eigen::Array<unsigned long, Eigen::Dynamic, Eigen::Dynamic> > &mat) {
Eigen::Array<unsigned long, Eigen::Dynamic, Eigen::Dynamic> output = mat;
return output;
}

Eigen::Array<unsigned long long, Eigen::Dynamic, Eigen::Dynamic> function_type_ulong_long(Eigen::Map<Eigen::Array<unsigned long long, Eigen::Dynamic, Eigen::Dynamic> > &mat) {
Eigen::Array<unsigned long long, Eigen::Dynamic, Eigen::Dynamic> output = mat;
return output;
}


Eigen::ArrayXXi function_type_int(Eigen::Map<Eigen::ArrayXXi> &mat) {
Eigen::ArrayXXi output = mat;
return output;
Expand Down
2 changes: 2 additions & 0 deletions tests/eigency_tests/eigency_tests_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ CustomStrideMap &function_filter3(CustomStrideMap &);
Eigen::ArrayXXd function_type_double(Eigen::Map<Eigen::ArrayXXd> &array);
Eigen::ArrayXXf function_type_float(Eigen::Map<Eigen::ArrayXXf> &array);
Eigen::Array<long, Eigen::Dynamic, Eigen::Dynamic> function_type_long(Eigen::Map<Eigen::Array<long, Eigen::Dynamic, Eigen::Dynamic> > &mat);
Eigen::Array<long long, Eigen::Dynamic, Eigen::Dynamic> function_type_long_long(Eigen::Map<Eigen::Array<long long, Eigen::Dynamic, Eigen::Dynamic> > &mat);
Eigen::Array<unsigned long, Eigen::Dynamic, Eigen::Dynamic> function_type_ulong(Eigen::Map<Eigen::Array<unsigned long, Eigen::Dynamic, Eigen::Dynamic> > &mat);
Eigen::Array<unsigned long long, Eigen::Dynamic, Eigen::Dynamic> function_type_ulong_long(Eigen::Map<Eigen::Array<unsigned long long, Eigen::Dynamic, Eigen::Dynamic> > &mat);
Eigen::ArrayXXi function_type_int(Eigen::Map<Eigen::ArrayXXi> &array);
Eigen::Array<unsigned int, Eigen::Dynamic, Eigen::Dynamic> function_type_uint(Eigen::Map<Eigen::Array<unsigned int, Eigen::Dynamic, Eigen::Dynamic> > &array);
Eigen::Array<short, Eigen::Dynamic, Eigen::Dynamic> function_type_short(Eigen::Map<Eigen::Array<short, Eigen::Dynamic, Eigen::Dynamic> > &mat);
Expand Down
16 changes: 13 additions & 3 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,30 @@ def test_function_type_float32(self):

def test_function_type_int(self):
# C++ long - Note that this is the standard Python integer
# with numpy 1 int is 32 in numpy 2 int is 64, so we need to be more specific
mat_in = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], order="F")
mat_out = eigency_tests.function_type_long(mat_in)
if mat_in.dtype == np.dtype('long'):
mat_out = eigency_tests.function_type_long(mat_in)
else:
mat_out = eigency_tests.function_type_long_long(mat_in)
assert_array_equal(mat_in, mat_out)

def test_function_type_long(self):
# C++ long - Note that this is the standard Python integer
mat_in = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], order="F", dtype=int)
mat_out = eigency_tests.function_type_long(mat_in)
if mat_in.dtype == np.dtype('long'):
mat_out = eigency_tests.function_type_long(mat_in)
else:
mat_out = eigency_tests.function_type_long_long(mat_in)
assert_array_equal(mat_in, mat_out)

def test_function_type_ulong(self):
# C++ ulong
mat_in = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], order="F", dtype=np.uint)
mat_out = eigency_tests.function_type_ulong(mat_in)
if mat_in.dtype == np.dtype('ulong'):
mat_out = eigency_tests.function_type_ulong(mat_in)
else:
mat_out = eigency_tests.function_type_ulong_long(mat_in)
assert_array_equal(mat_in, mat_out)

def test_function_type_intc(self):
Expand Down

0 comments on commit b379725

Please sign in to comment.