Skip to content

Commit

Permalink
Merge pull request #78 from astrofrog/circle-ci
Browse files Browse the repository at this point in the history
Added 32-bit CircleCI configuration
  • Loading branch information
astrofrog committed Nov 25, 2016
2 parents 54427e6 + 4b32abd commit 8db809e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
23 changes: 23 additions & 0 deletions .run_docker_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

docker info

cat << EOF | docker run -i \
-v ${PWD}:/regions_src \
-a stdin -a stdout -a stderr \
astropy/affiliated-32bit-test-env:1.6 \
bash || exit $?
cd /regions_src
echo "Output of uname -m:"
uname -m
echo "Output of sys.maxsize in Python:"
python -c 'import sys; print(sys.maxsize)'
pip install https://github.com/astrofrog/pytest-arraydiff/archive/master.zip
python setup.py test -V -a "-s"
EOF
11 changes: 11 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
machine:
services:
- docker

dependencies:
override:
- docker pull astropy/affiliated-32bit-test-env:1.6

test:
override:
- ./.run_docker_tests.sh
27 changes: 14 additions & 13 deletions regions/_geometry/circular_overlap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ctypedef np.float64_t DTYPE_t
# NOTE: Here we need to make sure we use cimport to import the C functions from
# core (since these were defined with cdef). This also requires the core.pxd
# file to exist with the function signatures.
from .core cimport area_arc, area_triangle
from .core cimport area_arc, area_triangle, floor_sqrt


def circular_overlap_grid(double xmin, double xmax, double ymin, double ymax,
Expand Down Expand Up @@ -188,9 +188,10 @@ cdef double circular_overlap_single_exact(double xmin, double ymin,
+ circular_overlap_single_exact(0., 0., xmax, ymax, r)


def circular_overlap_core(double xmin, double ymin, double xmax, double ymax,
cdef double circular_overlap_core(double xmin, double ymin, double xmax, double ymax,
double r):
"""Assumes that the center of the circle is <= xmin,
"""
Assumes that the center of the circle is <= xmin,
ymin (can always modify input to conform to this).
"""

Expand All @@ -202,29 +203,29 @@ def circular_overlap_core(double xmin, double ymin, double xmax, double ymax,
area = (xmax - xmin) * (ymax - ymin)
else:
area = 0.
d1 = sqrt(xmax * xmax + ymin * ymin)
d2 = sqrt(xmin * xmin + ymax * ymax)
d1 = floor_sqrt(xmax * xmax + ymin * ymin)
d2 = floor_sqrt(xmin * xmin + ymax * ymax)
if d1 < r and d2 < r:
x1, y1 = sqrt(r * r - ymax * ymax), ymax
x2, y2 = xmax, sqrt(r * r - xmax * xmax)
x1, y1 = floor_sqrt(r * r - ymax * ymax), ymax
x2, y2 = xmax, floor_sqrt(r * r - xmax * xmax)
area = ((xmax - xmin) * (ymax - ymin) -
area_triangle(x1, y1, x2, y2, xmax, ymax) +
area_arc(x1, y1, x2, y2, r))
elif d1 < r:
x1, y1 = xmin, sqrt(r * r - xmin * xmin)
x2, y2 = xmax, sqrt(r * r - xmax * xmax)
x1, y1 = xmin, floor_sqrt(r * r - xmin * xmin)
x2, y2 = xmax, floor_sqrt(r * r - xmax * xmax)
area = (area_arc(x1, y1, x2, y2, r) +
area_triangle(x1, y1, x1, ymin, xmax, ymin) +
area_triangle(x1, y1, x2, ymin, x2, y2))
elif d2 < r:
x1, y1 = sqrt(r * r - ymin * ymin), ymin
x2, y2 = sqrt(r * r - ymax * ymax), ymax
x1, y1 = floor_sqrt(r * r - ymin * ymin), ymin
x2, y2 = floor_sqrt(r * r - ymax * ymax), ymax
area = (area_arc(x1, y1, x2, y2, r) +
area_triangle(x1, y1, xmin, y1, xmin, ymax) +
area_triangle(x1, y1, xmin, y2, x2, y2))
else:
x1, y1 = sqrt(r * r - ymin * ymin), ymin
x2, y2 = xmin, sqrt(r * r - xmin * xmin)
x1, y1 = floor_sqrt(r * r - ymin * ymin), ymin
x2, y2 = xmin, floor_sqrt(r * r - xmin * xmin)
area = (area_arc(x1, y1, x2, y2, r) +
area_triangle(x1, y1, x2, y2, xmin, ymin))

Expand Down
1 change: 1 addition & 0 deletions regions/_geometry/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cdef double area_triangle(double x1, double y1, double x2, double y2, double x3,
cdef double area_arc_unit(double x1, double y1, double x2, double y2)
cdef int in_triangle(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3)
cdef double overlap_area_triangle_unit_circle(double x1, double y1, double x2, double y2, double x3, double y3)
cdef double floor_sqrt(double x)
16 changes: 16 additions & 0 deletions regions/_geometry/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ ctypedef struct intersections:
point p2


cdef double floor_sqrt(double x):
"""
In some of the geometrical functions, we have to take the sqrt of a number
and we know that the number should be >= 0. However, in some cases the
value is e.g. -1e-10, but we want to treat it as zero, which is what
this function does.
Note that this does **not** check whether negative values are close or not
to zero, so this should be used only in cases where the value is expected
to be positive on paper.
"""
if x > 0:
return sqrt(x)
else:
return 0

# NOTE: The following two functions use cdef because they are not intended to be
# called from the Python code. Using def makes them callable from outside, but
# also slower. Some functions currently return multiple values, and for those we
Expand Down

0 comments on commit 8db809e

Please sign in to comment.