Skip to content

Commit

Permalink
[geometry] fix compatibility with old visual studio for Python 2.7
Browse files Browse the repository at this point in the history
Also re-enable Py27 in Appveyors build matrix.
  • Loading branch information
marscher committed Feb 10, 2017
1 parent df889d3 commit 0fc8dec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
8 changes: 7 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions mdtraj/geometry/include/math_patch.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,4 +20,7 @@ double cbrt(double x) {
#define isnan(x) ((x)!=(x))
#endif // isnan

#else // use C99 compliant header.
#include <math.h>
#endif // _MSC_VER
#endif // __MATH_PATH_H_
7 changes: 1 addition & 6 deletions mdtraj/geometry/src/_geometry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
##############################################################################

import sys
import warnings
import cython
import numpy as np

##############################################################################
# Headers
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
include "image_molecules.pxi"
4 changes: 4 additions & 0 deletions mdtraj/geometry/src/image_molecules.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0fc8dec

Please sign in to comment.