Skip to content

Commit

Permalink
easier typecheck and TypeError thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
Kramer84 committed Oct 22, 2024
1 parent 2519b67 commit f4b6768
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions pyfqmr/Simplify.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ cdef class Simplify :
self.normals_cpp.clear()

# Here we will need some checks, just to make sure the right objets are passed
# Only checks on the faces is possible, as they are necessarily integers.
# Maybe other checks like max(faces)==len(vertices) could be added
assert is_integer_array(faces), "Faces must contain only integers, check function argument order"
if not np.issubdtype(faces.dtype, np.integer):
raise TypeError("faces array must be of integer type")

self.faces_mv = faces.astype(dtype="int32", subok=False, copy=False)
self.vertices_mv = vertices.astype(dtype="float64", subok=False, copy=False)
Expand Down Expand Up @@ -244,25 +244,3 @@ cdef vector[vector[int]] setFacesNogil(int[:,:] faces, vector[vector[int]] vecto
triangle.push_back(faces[i,j])
vector_faces.push_back(triangle)
return vector_faces


# For faster type checking
def is_integer_array(arr):
# Check if the dtype is integer before calling Cython function
if np.issubdtype(arr.dtype, np.integer):
return True
return is_integer_array_cython(arr)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.nonecheck(False)
def is_integer_array_cython(np.ndarray arr):
cdef Py_ssize_t i, j
cdef Py_ssize_t n_rows = arr.shape[0]
cdef Py_ssize_t n_cols = arr.shape[1]

for i in range(n_rows):
for j in range(n_cols):
if arr[i, j] % 1 != 0:
return False
return True

0 comments on commit f4b6768

Please sign in to comment.