Skip to content

Commit

Permalink
cython: always use 64-bit integers for counts
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Apr 5, 2024
1 parent 7971261 commit 3b35caa
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/gstools/variogram/estimator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ IF OPENMP:

cimport numpy as np
from libc.math cimport M_PI, acos, atan2, cos, fabs, isnan, pow, sin, sqrt
from libc.stdint cimport int64_t


def set_num_threads(num_threads):
Expand Down Expand Up @@ -116,7 +117,7 @@ ctypedef double (*_estimator_func)(const double) nogil

cdef inline void normalization_matheron(
double[:] variogram,
int[:] counts,
int64_t[:] counts,
):
cdef int i
for i in range(variogram.shape[0]):
Expand All @@ -125,10 +126,10 @@ cdef inline void normalization_matheron(

cdef inline void normalization_cressie(
double[:] variogram,
int[:] counts,
int64_t[:] counts,
):
cdef int i
cdef int cnt
cdef int64_t cnt
for i in range(variogram.shape[0]):
# avoid division by zero
cnt = max(counts[i], 1)
Expand All @@ -139,28 +140,28 @@ cdef inline void normalization_cressie(

ctypedef void (*_normalization_func)(
double[:],
int[:],
int64_t[:],
)

cdef inline void normalization_matheron_vec(
double[:, :] variogram,
int[:, :] counts,
int64_t[:, :] counts,
):
cdef int d
for d in range(variogram.shape[0]):
normalization_matheron(variogram[d, :], counts[d, :])

cdef inline void normalization_cressie_vec(
double[:, :] variogram,
int[:, :] counts,
int64_t[:, :] counts,
):
cdef int d
for d in range(variogram.shape[0]):
normalization_cressie(variogram[d, :], counts[d, :])

ctypedef void (*_normalization_func_vec)(
double[:, :],
int[:, :],
int64_t[:, :],
)

cdef _estimator_func choose_estimator_func(str estimator_type):
Expand Down Expand Up @@ -221,7 +222,7 @@ def directional(
cdef int f_max = f.shape[0]

cdef double[:, :] variogram = np.zeros((d_max, len(bin_edges)-1))
cdef int[:, :] counts = np.zeros((d_max, len(bin_edges)-1), dtype=int)
cdef int64_t[:, :] counts = np.zeros((d_max, len(bin_edges)-1), dtype=np.int64)
cdef int i, j, k, m, d
cdef double dist

Expand Down Expand Up @@ -287,7 +288,7 @@ def unstructured(
cdef int f_max = f.shape[0]

cdef double[:] variogram = np.zeros(len(bin_edges)-1)
cdef int[:] counts = np.zeros(len(bin_edges)-1, dtype=int)
cdef int64_t[:] counts = np.zeros(len(bin_edges)-1, dtype=np.int64)
cdef int i, j, k, m
cdef double dist

Expand Down Expand Up @@ -324,7 +325,7 @@ def structured(
cdef int k_max = i_max + 1

cdef double[:] variogram = np.zeros(k_max)
cdef int[:] counts = np.zeros(k_max, dtype=int)
cdef int64_t[:] counts = np.zeros(k_max, dtype=np.int64)
cdef int i, j, k

cdef int num_threads_c = set_num_threads(num_threads)
Expand Down Expand Up @@ -356,7 +357,7 @@ def ma_structured(
cdef int k_max = i_max + 1

cdef double[:] variogram = np.zeros(k_max)
cdef int[:] counts = np.zeros(k_max, dtype=int)
cdef int64_t[:] counts = np.zeros(k_max, dtype=np.int64)
cdef int i, j, k

cdef int num_threads_c = set_num_threads(num_threads)
Expand Down

0 comments on commit 3b35caa

Please sign in to comment.