From 0fc8dec5e0d1b0006415f40e7b3574a0c0b48ca2 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Fri, 10 Feb 2017 15:04:12 +0100 Subject: [PATCH] [geometry] fix compatibility with old visual studio for Python 2.7 Also re-enable Py27 in Appveyors build matrix. --- appveyor.yml | 8 +++++++- mdtraj/geometry/include/math_patch.h | 12 +++++++++--- mdtraj/geometry/src/_geometry.pyx | 7 +------ mdtraj/geometry/src/image_molecules.pxi | 4 ++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ab2f50874..98b5f3fd4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,13 @@ environment: - PYTHON: "C:\\Miniconda3" CONDA_PY: "35" CONDA_NPY: "1.10" - + - PYTHON: "C:\\Miniconda3" + CONDA_PY: "27" + CONDA_NPY: "1.10" + - PYTHON: "C:\\Miniconda3-x64" + CONDA_PY: "27" + CONDA_NPY: "1.10" + ARCH: "64" - PYTHON: "C:\\Miniconda3-x64" CONDA_PY: "35" CONDA_NPY: "1.10" diff --git a/mdtraj/geometry/include/math_patch.h b/mdtraj/geometry/include/math_patch.h index 742770f53..be0f74124 100644 --- a/mdtraj/geometry/include/math_patch.h +++ b/mdtraj/geometry/include/math_patch.h @@ -1,11 +1,14 @@ // Math functions for old versions of visual studio - +#ifndef __MATH_PATH_H_ +#define __MATH_PATH_H_ #ifdef _MSC_VER #if _MSC_VER < 1900 // prior to vs2015 -float roundf(float x) { +#pragma once +inline float roundf(float x) { return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f); } -double cbrt(double x) { + +inline double cbrt(double x) { if (x<0) return -1.0 * pow(-1.0 * x, 1.0/3.0); else @@ -17,4 +20,7 @@ double cbrt(double x) { #define isnan(x) ((x)!=(x)) #endif // isnan +#else // use C99 compliant header. +#include #endif // _MSC_VER +#endif // __MATH_PATH_H_ diff --git a/mdtraj/geometry/src/_geometry.pyx b/mdtraj/geometry/src/_geometry.pyx index 0369510b8..7fff6b062 100644 --- a/mdtraj/geometry/src/_geometry.pyx +++ b/mdtraj/geometry/src/_geometry.pyx @@ -23,9 +23,6 @@ ############################################################################## import sys -import warnings -import cython -import numpy as np ############################################################################## # Headers @@ -74,8 +71,6 @@ cdef extern from "geometry.h" nogil: void find_closest_contact(const float* positions, const int* group1, const int* group2, int n_group1, int n_group2, const float* box_vectors_pointer, int* atom1, int* atom2, float* distance) - float roundf(float x) - float floorf(float x) cdef extern from "sasa.h": void sasa(const int n_frames, const int n_atoms, const float* xyzlist, @@ -239,4 +234,4 @@ def _find_closest_contact(float[:, ::1] positions, find_closest_contact(&positions[0,0], &group1[0], &group2[0], len(group1), len(group2), box_vectors_pointer, &atom1, &atom2, &distance) return (atom1, atom2, distance) -include "image_molecules.pxi" \ No newline at end of file +include "image_molecules.pxi" diff --git a/mdtraj/geometry/src/image_molecules.pxi b/mdtraj/geometry/src/image_molecules.pxi index d67b4b3e9..7dea65f4c 100644 --- a/mdtraj/geometry/src/image_molecules.pxi +++ b/mdtraj/geometry/src/image_molecules.pxi @@ -7,6 +7,10 @@ from libcpp.vector cimport vector ctypedef np.npy_intp intp +cdef extern from "math_patch.h" nogil: + float roundf(float x) + float floorf(float x) + cdef void make_whole(float[:,::1] frame_positions, float[:,::1] frame_unitcell_vectors, intp[:,:] sorted_bonds) nogil: