Skip to content

Commit

Permalink
Merge branch 'master' into test-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
VikingScientist authored Feb 21, 2020
2 parents 849a47e + d980dee commit bb28a22
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 27 deletions.
68 changes: 68 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
language: shell

env:
global:
- CIBW_SKIP="cp27*"
- CIBW_BEFORE_BUILD="pip install cython numpy"
- TWINE_USERNAME=__token__
# TWINE_PASSWORD should be set to an API token in the Travis settings
jobs:
- CONDA_PYTHON=3.5
- CONDA_PYTHON=3.6
- CONDA_PYTHON=3.7
- CONDA_PYTHON=3.8

os:
- linux
- windows
- osx

stages:
- test
- name: deploy
if: tag IS PRESENT AND repo = sintefmath/Splipy

before_install:
- source ./ci/before_install.sh

install:
- source ./ci/install.sh
- conda install -y python=${CONDA_PYTHON}
- pip install -r requirements.txt
- pip install twine cibuildwheel==1.1.0
- |-
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
pip install opencv-python
fi
- conda list

script:
- python setup.py install
- pytest test --benchmark-skip

jobs:
include:
- stage: deploy
name: Deploy source distribution
script: python setup.py sdist --formats=gztar
after_success: python -m twine upload --skip-existing dist/*.tar.gz
- stage: deploy
name: Build and deploy Linux wheels
services: docker
script: python -m cibuildwheel --output-dir wheelhouse
after_success: python -m twine upload --skip-existing wheelhouse/*.whl
- stage: deploy
name: Build and deploy OSX wheels
os: osx
script: python -m cibuildwheel --output-dir wheelhouse
after_success: python -m twine upload --skip-existing wheelhouse/*.whl
- stage: deploy
name: Build and deploy Windows wheels
os: windows
script: python -m cibuildwheel --output-dir wheelhouse
after_success: python -m twine upload --skip-existing wheelhouse/*.whl

notifications:
email:
on_success: never
on_failure: always
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global-include *.pyx
global-include *.pxd
21 changes: 6 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Dependencies

**Required**

This library requires numpy and scipy. E.g. on Ubuntu::
This library requires numpy and scipy. For building, cython is also
required. E.g. on Ubuntu::

pip install numpy
pip install scipy
Expand Down Expand Up @@ -124,17 +125,7 @@ number, create a commit and a tag. To push this to github, use::

git push --tags

After that, to create the actual packages, run::

rm -rf dist
python setup.py sdist
python setup.py bdist_wheel --universal

to create a source distribution and a wheel. These can then be uploaded where
they need to be uploaded. The recommended way to do that is using `twine
<https://pypi.python.org/pypi/twine>`_::

twine upload dist/* -r <index>

Where `index` is the name of the index in your `~/.pypirc` where you want to
upload.
After that, Travis CI should automatically build and deploy the
packages to PyPi. It would be helpful to monitor the Travis build so
that errors can be fixed quickly. See the `list of builds
<https://travis-ci.org/sintefmath/Splipy/builds>`_.
27 changes: 27 additions & 0 deletions ci/before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Set conda path info
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
export MINICONDA_PATH=$HOME/miniconda;
export MINICONDA_SUB_PATH=$MINICONDA_PATH/bin;
elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
export MINICONDA_PATH=$HOME/miniconda;
export MINICONDA_PATH_WIN=`cygpath --windows $MINICONDA_PATH`;
export MINICONDA_SUB_PATH=$MINICONDA_PATH/Scripts;
fi;
export MINICONDA_LIB_BIN_PATH=$MINICONDA_PATH/Library/bin;

# Obtain miniconda installer
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
mkdir -p $HOME/download;
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
echo "downloading miniconda.sh for linux";
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $HOME/download/miniconda.sh;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
echo "downloading miniconda.sh for osx";
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O $HOME/download/miniconda.sh;
fi;
fi;

# Install openssl for Windows
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
choco install openssl.light;
fi;
40 changes: 40 additions & 0 deletions ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Installing miniconda
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
echo "installing miniconda for posix";
bash $HOME/download/miniconda.sh -b -u -p $MINICONDA_PATH;
elif [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
echo "folder $MINICONDA_SUB_PATH does not exist"
echo "installing miniconda for windows";
choco install miniconda3 --params="'/JustMe /AddToPath:1 /D:$MINICONDA_PATH_WIN'";
fi;

export PATH="$MINICONDA_PATH:$MINICONDA_SUB_PATH:$MINICONDA_LIB_BIN_PATH:$PATH";

# Checking miniconda existance
echo "checking if folder $MINICONDA_SUB_PATH exists"
if [[ -d $MINICONDA_SUB_PATH ]]; then
echo "folder $MINICONDA_SUB_PATH exists"
else
echo "folder $MINICONDA_SUB_PATH does not exist"
fi;

source $MINICONDA_PATH/etc/profile.d/conda.sh;
hash -r;
echo $TRAVIS_OS_NAME
echo $CONDA_PYTHON
python --version
conda config --set always_yes yes --set changeps1 no;
conda update -q conda;

# Free channel has Python < 3.7
conda config --set restore_free_channel true;

# Useful for debugging any issues with conda
conda info -a

# See if test-environment already available
echo "create test-environment";
conda create -n test-environment;

conda activate test-environment
conda list
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Cython==0.29.15
numpy==1.18.1
pytest==5.3.5
scipy==1.4.1
pytest-benchmark==3.2.3
h5py==2.10.0
tqdm==4.41.1
nutils==4.1
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

from setuptools import setup
# import numpy as np
from Cython.Build import cythonize
import numpy as np

with open('PyPI_text.md') as f:
long_description = f.read()
Expand Down Expand Up @@ -29,7 +30,8 @@
'FiniteElement': ["nutils>=4.0"],
'Images': ["opencv-python>=4.0"],
},
# include_dirs=[np.get_include()],
ext_modules=cythonize("splipy/basis_eval.pyx"),
include_dirs=[np.get_include()],
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Multimedia :: Graphics :: 3D Modeling',
Expand Down
33 changes: 30 additions & 3 deletions splipy/BSplineBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bisect import bisect_right, bisect_left
import numpy as np
import copy
from splipy import basis_eval
from scipy.sparse import csr_matrix

__all__ = ['BSplineBasis']
Expand Down Expand Up @@ -106,6 +107,34 @@ def greville(self, index=None):

def evaluate(self, t, d=0, from_right=True, sparse=False):
""" Evaluate all basis functions in a given set of points.
:param t: The parametric coordinate(s) in which to evaluate
:type t: float or [float]
:param int d: Number of derivatives to compute
:param bool from_right: True if evaluation should be done in the limit
from above
:param bool sparse: True if computed matrix should be returned as sparse
:return: A matrix *N[i,j]* of all basis functions *j* evaluated in all
points *i*
:rtype: numpy.array
"""
# for single-value input, wrap it into a list so it don't crash on the loop below
t = ensure_listlike(t)
t = np.array(t, dtype=np.float64)
basis_eval.snap(self.knots, t, state.knot_tolerance)

if self.order <= d: # requesting more derivatives than polymoial degree: return all zeros
return np.matrix(np.zeros((len(t), self.num_functions())))

(data, size) = basis_eval.evaluate(self.knots, self.order, t, self.periodic, state.knot_tolerance, d, from_right)

N = csr_matrix(data, size)
if not sparse:
N = N.todense()
return N

def evaluate_old(self, t, d=0, from_right=True, sparse=False):
""" Evaluate all basis functions in a given set of points.
:param t: The parametric coordinate(s) in which to evaluate
:type t: float or [float]
:param int d: Number of derivatives to compute
Expand Down Expand Up @@ -135,16 +164,14 @@ def evaluate(self, t, d=0, from_right=True, sparse=False):
for i in range(len(t)):
if t[i] < self.start() or t[i] > self.end():
t[i] = (t[i] - self.start()) % (self.end() - self.start()) + self.start()
if abs(t[i] - self.start()) < state.knot_tolerance and not from_right:
t[i] = self.end()
for i in range(len(t)):
right = from_right
evalT = t[i]
# Special-case the endpoint, so the user doesn't need to
if abs(t[i] - self.end()) < state.knot_tolerance:
right = False
# Skip non-periodic evaluation points outside the domain
if t[i] < self.start() or t[i] > self.end() or (abs(t[i]-self.start()) < state.knot_tolerance and not right):
if t[i] < self.start() or t[i] > self.end():
continue

# mu = index of last non-zero basis function
Expand Down
Loading

0 comments on commit bb28a22

Please sign in to comment.