Skip to content

Commit

Permalink
builds well cython 3 + numpy > 2 + removed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Dec 6, 2024
1 parent 2d6e7b4 commit 3a1f8ef
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 36 deletions.
6 changes: 2 additions & 4 deletions liboptv/include/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ typedef struct {



int write_ori(Exterior Ex, Interior I, Glass G, ap_52 ap, char *filename,
char *add_file);
int read_ori (Exterior Ex[], Interior I[], Glass G[], char *ori_file,
ap_52 addp[], char *add_file, char *add_fallback);
int write_ori(Exterior ext_par, Interior int_par, Glass glass_par, ap_52 added_par, char *filename, char *add_file);
int read_ori (Exterior ext_par[], Interior int_par[], Glass glass_par[], char *ori_file, ap_52 added_par[], char *add_file, char *add_fallback);
int compare_exterior(Exterior *e1, Exterior *e2);
int compare_interior(Interior *i1, Interior *i2);
int compare_glass(Glass *g1, Glass *g2);
Expand Down
2 changes: 1 addition & 1 deletion liboptv/include/ray_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ray_tracing (double x
, double X[3]
, double a[3]);

void old_ray_tracing (double x, double y, Exterior Ex, Interior I, Glass G,\
void old_ray_tracing (double x, double y, Exterior ext_par, Interior int_par, Glass glass_par,\
mm_np mm, double *Xb2, double *Yb2, double *Zb2, \
double *a3, double *b3,double *c3);

Expand Down
17 changes: 13 additions & 4 deletions liboptv/src/orientation.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,19 @@ int read_man_ori_fix(vec3d fix4[4], char* calblock_filename,
goto handle_error;
}

for (i=0; i<cam; i++)
fscanf (fpp, "%d %d %d %d \n", &dummy, &dummy, &dummy, &dummy);
fscanf (fpp, "%d %d %d %d \n", &nr[0], &nr[1], &nr[2], &nr[3]);
fclose (fpp);
for (i=0; i<cam; i++) {
if (fscanf(fpp, "%d %d %d %d \n", &dummy, &dummy, &dummy, &dummy) != 4) {
printf("Error reading manual orientation file %s\n", man_ori_filename);
fclose(fpp);
return 0;
}
}
if (fscanf(fpp, "%d %d %d %d \n", &nr[0], &nr[1], &nr[2], &nr[3]) != 4) {
printf("Error reading manual orientation file %s\n", man_ori_filename);
fclose(fpp);
return 0;
}
fclose(fpp);

/* read the id and positions of the fixed points, assign the pre-defined to fix4 */
fix = read_calblock(&num_fix, calblock_filename);
Expand Down
1 change: 1 addition & 0 deletions liboptv/src/tracking_frame_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ reading targets, correspondences, etc.
#include <stdio.h>
#include <stdlib.h>
#include "tracking_frame_buf.h"
#include "calibration.h"

/* Check that target t1 is equal to target t2, i.e. all their fields are equal.
*
Expand Down
8 changes: 4 additions & 4 deletions py_bind/optv/correspondences.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ cdef class MatchedCoords:
"""
cdef:
np.ndarray[ndim=2, dtype=np.float64_t] pos
np.ndarray[ndim=1, dtype=np.int_t] pnr
np.ndarray[ndim=1, dtype=np.int32_t] pnr
int pt

pos = np.empty((self._num_pts, 2))
pnr = np.empty(self._num_pts, dtype=np.int_)
pnr = np.empty(self._num_pts, dtype=np.int32)

for pt in range(self._num_pts):
pos[pt,0] = self.buf[pt].x
Expand All @@ -97,7 +97,7 @@ cdef class MatchedCoords:

return pos, pnr

def get_by_pnrs(self, np.ndarray[ndim=1, dtype=np.int_t] pnrs):
def get_by_pnrs(self, np.ndarray[ndim=1, dtype=np.int32_t] pnrs):
"""
Return the flat positions of points whose pnr property is given, as an
(n,2) flat position array. Assumes all pnrs are to be found, otherwise
Expand Down Expand Up @@ -160,7 +160,7 @@ def correspondences(list img_pts, list flat_coords, list cals,
num_cams * sizeof(coord_2d *))
frame frm

np.ndarray[ndim=2, dtype=np.int_t] clique_ids
np.ndarray[ndim=2, dtype=np.int32_t] clique_ids
np.ndarray[ndim=3, dtype=np.float64_t] clique_targs

# Return buffers:
Expand Down
2 changes: 1 addition & 1 deletion py_bind/optv/orientation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def full_calibration(Calibration cal,
cdef:
vec3d *ref_coord
np.ndarray[ndim=2, dtype=pos_t] ret
np.ndarray[ndim=1, dtype=np.int_t] used
np.ndarray[ndim=1, dtype=np.int32_t] used
np.ndarray[ndim=1, dtype=pos_t] err_est
orient_par *orip
double *residuals
Expand Down
2 changes: 1 addition & 1 deletion py_bind/optv/parameters.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ cdef class SequenceParams:
cdef char * c_str = self._sequence_par[0].img_base_name[cam]
# FILEPATH: /home/user/Documents/repos/openptv/py_bind/optv/parameters.pyx
# BEGIN: ed8c6549bwf9
cdef char* c_str = ...
# cdef char* c_str = ...
py_str = c_str
return py_str
# END: ed8c6549bwf9
Expand Down
2 changes: 1 addition & 1 deletion py_bind/optv/segmentation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DTYPE = np.uint8
# "ctypedef" assigns a corresponding compile-time type to DTYPE_t. For
# every type in the numpy module there's a corresponding compile-time
# type with a _t-suffix.
ctypedef np.int_t DTYPE_t
ctypedef np.uint8_t DTYPE_t

from optv.parameters cimport TargetParams, ControlParams
from optv.tracking_framebuf cimport TargetArray
Expand Down
8 changes: 4 additions & 4 deletions py_bind/optv/transforms.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ cdef extern from "optv/trafo.h":
, double * y_metric
, double x_pixel
, double y_pixel
, control_par * parameters)
, control_par * parameters) noexcept
void metric_to_pixel(double * x_pixel
, double * y_pixel
, double x_metric
, double y_metric
, control_par * parameters)
, control_par * parameters) noexcept
void correct_brown_affin (double x
, double y
, ap_52 ap
, double * x1
, double * y1)
, double * y1) noexcept
void distort_brown_affin (double x
, double y
, ap_52 ap
, double * x1
, double * y1)
, double * y1) noexcept

void correct_brown_affine_exact(double x, double y, ap_52 ap,
double *x1, double *y1, double tol)
Expand Down
26 changes: 16 additions & 10 deletions py_bind/optv/transforms.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,24 @@ def convert_arr_metric_to_pixel(np.ndarray[np.float_t, ndim=2] input,
'''
return convert_generic(input, control._control_par, out, metric_to_pixel)

cdef convert_generic(np.ndarray[np.float_t, ndim=2] input,
control_par * c_control,
np.ndarray[np.float_t, ndim=2] out,
void convert_function(double * , double * , double, double , control_par *)) noexcept nogil:
cdef convert_generic(
np.ndarray[np.float_t, ndim=2] input,
control_par * c_control,
np.ndarray[np.float_t, ndim=2] out,
void (*convert_function)(double *, double *, double, double, control_par *)
noexcept ):
# Acquire GIL before calling any GIL-requiring functions
out = check_inputs(input, out)

for i in range(input.shape[0]):
convert_function(< double *> np.PyArray_GETPTR2(out, i, 0)
, < double *> np.PyArray_GETPTR2(out, i, 1)
, (< double *> np.PyArray_GETPTR2(input, i, 0))[0]
, (< double *> np.PyArray_GETPTR2(input, i, 1))[0]
, c_control)
convert_function(<double *> np.PyArray_GETPTR2(out, i, 0),
<double *> np.PyArray_GETPTR2(out, i, 1),
(<double *> np.PyArray_GETPTR2(input, i, 0))[0],
(<double *> np.PyArray_GETPTR2(input, i, 1))[0],
c_control)

# Acquire GIL before returning the Python object

return out

# Affine #
Expand Down Expand Up @@ -103,7 +109,7 @@ def distort_arr_brown_affine(np.ndarray[np.float_t, ndim=2] input,
cdef brown_affine_generic(np.ndarray[np.float_t, ndim=2] input,
ap_52 c_ap_52,
np.ndarray[np.float_t, ndim=2] out,
void affine_function(double, double, ap_52 , double * , double *)):
void (*affine_function)(double, double, ap_52, double *, double *) noexcept):
out = check_inputs(input, out)

for i in range(input.shape[0]):
Expand Down
4 changes: 2 additions & 2 deletions py_bind/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ requires = [
"packaging==20.5; platform_machine=='arm64'", # macos M1
"setuptools==59.2.0",
"wheel==0.37.0",
"Cython>=0.29.28,<3.0", # Note: keep in sync with tools/cythonize.py
"numpy>=1.17.3, <1.24",
"Cython", # Note: keep in sync with tools/cythonize.py
"numpy",
]

[tool.cibuildwheel]
Expand Down
8 changes: 4 additions & 4 deletions py_bind/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_numpy_include_dir():
del builtins.__NUMPY_SETUP__
import importlib
import numpy
importlib.reload(numpy)
# importlib.reload(numpy)
else:
import builtins
if hasattr(__builtin__, '__NUMPY_SETUP__'):
Expand Down Expand Up @@ -122,7 +122,7 @@ def get_liboptv_sources():

def mk_ext(name, files):
# Do not specify include dirs, as they require numpy to be installed. Add them in BuildExt
return Extension(name, files + get_liboptv_sources())
return Extension(name, files + get_liboptv_sources(), define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')])


ext_mods = [
Expand Down Expand Up @@ -154,9 +154,9 @@ def mk_ext(name, files):
package_data={
'optv': ['*.pxd', '*.c', '*.h'],
},
version='0.2.8',
version='0.3.0',
install_requires=[
'numpy<1.24',
'numpy',
'pyyaml',
],
setup_requires=['numpy'],
Expand Down

0 comments on commit 3a1f8ef

Please sign in to comment.