Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cython #51

Merged
merged 11 commits into from
Dec 12, 2019
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ All notable changes to **GSTools** will be documented in this file.
## [Unreleased]

### Enhancements
- different variogram estimator functions can now be used #51

### Changes
- Python versions 2.7 and 3.4 are no longer supported #40 #43

### Bugfixes
- a race condition in the structured variogram estimation has been fixed #51


## [1.1.1] - Reverberating Red - 2019-11-08
Expand Down
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,8 @@ running. Install the package by typing the following command in a command termin

pip install gstools

To get the latest development version you can install it directly from GitHub:

pip install https://github.com/GeoStat-Framework/GSTools/archive/develop.zip

To enable the OpenMP support, you have to provide a C compiler, Cython and OpenMP.
To get all other dependencies, it is recommended to first install gstools once
in the standard way just decribed.
Then use the following command:

pip install --global-option="--openmp" gstools

Or for the development version:

pip install --global-option="--openmp" https://github.com/GeoStat-Framework/GSTools/archive/develop.zip

If something went wrong during installation, try the [``-I`` flag from pip][pipiflag].
To install the latest development version via pip, see the
[documentation][doc_install_link].


## Citation
Expand Down Expand Up @@ -336,6 +322,7 @@ You can contact us via <info@geostat-framework.org>.
[cov_link]: https://geostat-framework.readthedocs.io/projects/gstools/en/latest/covmodel.base.html#gstools.covmodel.base.CovModel
[stable_link]: https://en.wikipedia.org/wiki/Stable_distribution
[doc_link]: https://geostat-framework.readthedocs.io/projects/gstools/en/latest/
[doc_install_link]: https://gstools.readthedocs.io/en/stable/#pip
[tut_link]: https://geostat-framework.readthedocs.io/projects/gstools/en/latest/tutorials.html
[tut1_link]: https://geostat-framework.readthedocs.io/projects/gstools/en/latest/tutorial_01_srf.html
[tut2_link]: https://geostat-framework.readthedocs.io/projects/gstools/en/latest/tutorial_02_cov.html
Expand Down
128 changes: 48 additions & 80 deletions gstools/field/summator.pyx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!python
#cython: language_level=2
#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
# -*- coding: utf-8 -*-
"""
This is the variogram estimater, implemented in cython.
"""
from __future__ import division, absolute_import, print_function

import numpy as np

Expand All @@ -18,14 +16,11 @@ DTYPE = np.double
ctypedef np.double_t DTYPE_t


@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_unstruct(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:,:] pos
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:,:] pos
):
cdef int i, j, d, X_len, N
cdef double phase
Expand All @@ -46,16 +41,13 @@ def summate_unstruct(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_struct(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y=None,
double[:] z=None,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y=None,
const double[:] z=None,
):
if y == None and z == None:
return summate_struct_1d(cov_samples, z_1, z_2, x)
Expand All @@ -64,14 +56,11 @@ def summate_struct(
else:
return summate_struct_3d(cov_samples, z_1, z_2, x, y, z)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_struct_1d(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
):

cdef int i, j, X_len, N
Expand All @@ -89,15 +78,12 @@ def summate_struct_1d(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_struct_2d(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y,
):
cdef int i, j, k, X_len, Y_len, N
cdef double phase
Expand All @@ -116,16 +102,13 @@ def summate_struct_2d(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_struct_3d(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y,
double[:] z,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y,
const double[:] z,
):
cdef int i, j, k, l, X_len, Y_len, Z_len, N
cdef double phase
Expand All @@ -150,10 +133,7 @@ def summate_struct_3d(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cdef (double) abs_square(double[:] vec) nogil:
cdef (double) abs_square(const double[:] vec) nogil:
cdef int i
cdef double r = 0.

Expand All @@ -162,14 +142,11 @@ cdef (double) abs_square(double[:] vec) nogil:

return r

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_incompr_unstruct(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:,:] pos
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:,:] pos
):
cdef int i, j, d, X_len, N
cdef double phase
Expand Down Expand Up @@ -198,31 +175,25 @@ def summate_incompr_unstruct(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_incompr_struct(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y=None,
double[:] z=None,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y=None,
const double[:] z=None,
):
if z == None:
return summate_incompr_struct_2d(cov_samples, z_1, z_2, x, y)
else:
return summate_incompr_struct_3d(cov_samples, z_1, z_2, x, y, z)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_incompr_struct_2d(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y,
):
cdef int i, j, k, d, X_len, Y_len, N
cdef double phase
Expand Down Expand Up @@ -250,16 +221,13 @@ def summate_incompr_struct_2d(

return np.asarray(summed_modes)

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def summate_incompr_struct_3d(
double[:,:] cov_samples,
double[:] z_1,
double[:] z_2,
double[:] x,
double[:] y,
double[:] z,
const double[:,:] cov_samples,
const double[:] z_1,
const double[:] z_2,
const double[:] x,
const double[:] y,
const double[:] z,
):
cdef int i, j, k, l, d, X_len, Y_len, Z_len, N
cdef double phase
Expand Down
11 changes: 6 additions & 5 deletions gstools/krige/krigesum.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# cython: language_level=2
#cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
# -*- coding: utf-8 -*-
"""
This is a summator for the kriging routines
"""
from __future__ import division, absolute_import, print_function

import numpy as np

Expand All @@ -12,9 +11,11 @@ from cython.parallel import prange
cimport numpy as np


@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False) # turn off negative index wrapping for entire function
def krigesum(double[:,:] krig_mat, double[:,:] krig_vecs, double[:] cond):
def krigesum(
const double[:,:] krig_mat,
const double[:,:] krig_vecs,
const double[:] cond
):

cdef int mat_i = krig_mat.shape[0]
cdef int res_i = krig_vecs.shape[1]
Expand Down
Loading