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

Integration tests should run w/o conda also #30

Merged
merged 4 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ env:
# Directory where tests are run from
- TEST_DIR=/tmp/test_dir/
- MODULE=umap
matrix:
- DISTRIB="conda" PYTHON_VERSION="2.7"
NUMPY_VERSION="1.13.3" SCIPY_VERSION="0.19.1"
- DISTRIB="conda" PYTHON_VERSION="3.6" COVERAGE="true"
NUMPY_VERSION="1.13.3" SCIPY_VERSION="0.19.1"

matrix:
include:
- python: 3.6
- env: DISTRIB="conda" PYTHON_VERSION="2.7" NUMPY_VERSION="1.13.3" SCIPY_VERSION="0.19.1"
- env: DISTRIB="conda" PYTHON_VERSION="3.6" COVERAGE="true" NUMPY_VERSION="1.13.3" SCIPY_VERSION="0.19.1"

install: source ci_scripts/install.sh
script: bash ci_scripts/test.sh
Expand Down
73 changes: 39 additions & 34 deletions ci_scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
# Deactivate the travis-provided virtual environment and setup a
# conda-based environment instead
deactivate
if [[ "$DISTRIB" == "conda" ]]; then

# Use the miniconda installer for faster download / install of conda
# itself
pushd .
cd
mkdir -p download
cd download
echo "Cached in $HOME/download :"
ls -l
echo
if [[ ! -f miniconda.sh ]]
then
wget http://repo.continuum.io/miniconda/Miniconda-3.6.0-Linux-x86_64.sh \
-O miniconda.sh
fi
chmod +x miniconda.sh && ./miniconda.sh -b
cd ..
export PATH=/home/travis/miniconda/bin:$PATH
conda update --yes conda
popd
# Deactivate the travis-provided virtual environment and setup a
# conda-based environment instead
deactivate

# Configure the conda environment and put it in the path using the
# provided versions
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION numba scikit-learn
# Use the miniconda installer for faster download / install of conda
# itself
pushd .
cd
mkdir -p download
cd download
echo "Cached in $HOME/download :"
ls -l
echo
if [[ ! -f miniconda.sh ]]
then
wget http://repo.continuum.io/miniconda/Miniconda-3.6.0-Linux-x86_64.sh \
-O miniconda.sh
fi
chmod +x miniconda.sh && ./miniconda.sh -b
cd ..
export PATH=/home/travis/miniconda/bin:$PATH
conda update --yes conda
popd

source activate testenv
# Configure the conda environment and put it in the path using the
# provided versions
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION numba scikit-learn

source activate testenv

if [[ "$COVERAGE" == "true" ]]; then
pip install coverage coveralls
fi

python --version
python -c "import numpy; print('numpy %s' % numpy.__version__)"
python -c "import scipy; print('scipy %s' % scipy.__version__)"
python setup.py develop
if [[ "$COVERAGE" == "true" ]]; then
pip install coverage coveralls
fi

python --version
python -c "import numpy; print('numpy %s' % numpy.__version__)"
python -c "import scipy; print('scipy %s' % scipy.__version__)"
python setup.py develop
else
pip install -e .
fi
93 changes: 48 additions & 45 deletions umap/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Enough simple sparse operations in numba to enable sparse UMAP
#
# License: BSD 3 clause

from __future__ import print_function
import numpy as np
import numba

Expand Down Expand Up @@ -192,10 +192,10 @@ def sparse_random_projection_cosine_split(inds,
left = indices[left_index]
right = indices[right_index]

left_inds = inds[indptr[left]:indptr[left+1]]
left_data = data[indptr[left]:indptr[left+1]]
right_inds = inds[indptr[right]:indptr[right+1]]
right_data = data[indptr[right]:indptr[right+1]]
left_inds = inds[indptr[left]:indptr[left + 1]]
left_data = data[indptr[left]:indptr[left + 1]]
right_inds = inds[indptr[right]:indptr[right + 1]]
right_data = data[indptr[right]:indptr[right + 1]]

left_norm = norm(left_data)
right_norm = norm(right_data)
Expand All @@ -222,8 +222,8 @@ def sparse_random_projection_cosine_split(inds,
for i in range(indices.shape[0]):
margin = 0.0

i_inds = inds[indptr[indices[i]]:indptr[indices[i]+1]]
i_data = data[indptr[indices[i]]:indptr[indices[i]+1]]
i_inds = inds[indptr[indices[i]]:indptr[indices[i] + 1]]
i_data = data[indptr[indices[i]]:indptr[indices[i] + 1]]

mul_inds, mul_data = sparse_mul(hyperplane_inds,
hyperplane_data,
Expand Down Expand Up @@ -314,10 +314,10 @@ def sparse_random_projection_split(inds,
left = indices[left_index]
right = indices[right_index]

left_inds = inds[indptr[left]:indptr[left+1]]
left_data = data[indptr[left]:indptr[left+1]]
right_inds = inds[indptr[right]:indptr[right+1]]
right_data = data[indptr[right]:indptr[right+1]]
left_inds = inds[indptr[left]:indptr[left + 1]]
left_data = data[indptr[left]:indptr[left + 1]]
right_inds = inds[indptr[right]:indptr[right + 1]]
right_data = data[indptr[right]:indptr[right + 1]]

# Compute the normal vector to the hyperplane (the vector between
# the two points) and the offset from the origin
Expand Down Expand Up @@ -347,8 +347,8 @@ def sparse_random_projection_split(inds,
side = np.empty(indices.shape[0], np.int8)
for i in range(indices.shape[0]):
margin = hyperplane_offset
i_inds = inds[indptr[indices[i]]:indptr[indices[i]+1]]
i_data = data[indptr[indices[i]]:indptr[indices[i]+1]]
i_inds = inds[indptr[indices[i]]:indptr[indices[i] + 1]]
i_data = data[indptr[indices[i]]:indptr[indices[i] + 1]]

mul_inds, mul_data = sparse_mul(hyperplane_inds,
hyperplane_data,
Expand Down Expand Up @@ -421,11 +421,11 @@ def nn_descent(inds, indptr, data, n_vertices, n_neighbors, rng_state,
indices = rejection_sample(n_neighbors, n_vertices, rng_state)
for j in range(indices.shape[0]):

from_inds = inds[indptr[i]:indptr[i+1]]
from_data = data[indptr[i]:indptr[i+1]]
from_inds = inds[indptr[i]:indptr[i + 1]]
from_data = data[indptr[i]:indptr[i + 1]]

to_inds = inds[indptr[indices[j]]:indptr[indices[j]+1]]
to_data = data[indptr[indices[j]]:indptr[indices[j]+1]]
to_inds = inds[indptr[indices[j]]:indptr[indices[j] + 1]]
to_data = data[indptr[indices[j]]:indptr[indices[j] + 1]]

d = sparse_dist(from_inds, from_data,
to_inds, to_data,
Expand All @@ -447,9 +447,9 @@ def nn_descent(inds, indptr, data, n_vertices, n_neighbors, rng_state,
from_data = data[indptr[leaf_array[n, i]]:indptr[leaf_array[n, i] + 1]]

to_inds = inds[
indptr[leaf_array[n, j]]:indptr[leaf_array[n, j] + 1]]
indptr[leaf_array[n, j]]:indptr[leaf_array[n, j] + 1]]
to_data = data[
indptr[leaf_array[n, j]]:indptr[leaf_array[n, j] + 1]]
indptr[leaf_array[n, j]]:indptr[leaf_array[n, j] + 1]]

d = sparse_dist(from_inds, from_data,
to_inds, to_data,
Expand All @@ -464,7 +464,7 @@ def nn_descent(inds, indptr, data, n_vertices, n_neighbors, rng_state,

for n in range(n_iters):
if verbose:
print("\tnn descent iteration ", n, " / ", n_iters)
print("\t", n, " / ", n_iters)

candidate_neighbors = build_candidates(current_graph, n_vertices,
n_neighbors, max_candidates,
Expand All @@ -486,9 +486,9 @@ def nn_descent(inds, indptr, data, n_vertices, n_neighbors, rng_state,
from_data = data[indptr[p]:indptr[p + 1]]

to_inds = inds[
indptr[q]:indptr[q + 1]]
indptr[q]:indptr[q + 1]]
to_data = data[
indptr[q]:indptr[q + 1]]
indptr[q]:indptr[q + 1]]

d = sparse_dist(from_inds, from_data,
to_inds, to_data,
Expand All @@ -504,6 +504,7 @@ def nn_descent(inds, indptr, data, n_vertices, n_neighbors, rng_state,

return nn_descent


@numba.njit()
def sparse_euclidean(ind1, data1, ind2, data2):
aux_inds, aux_data = sparse_diff(ind1, data1, ind2, data2)
Expand Down Expand Up @@ -560,6 +561,7 @@ def sparse_canberra(ind1, data1, ind2, data2):

return np.sum(val_data)


@numba.njit()
def sparse_bray_curtis(ind1, data1, ind2, data2):
abs_data1 = np.abs(data1)
Expand Down Expand Up @@ -615,7 +617,7 @@ def sparse_kulsinski(ind1, data1, ind2, data2, n_features):
return 0.0
else:
return float(num_not_equal - num_true_true + n_features) / \
(num_not_equal + n_features)
(num_not_equal + n_features)


@numba.njit()
Expand Down Expand Up @@ -708,28 +710,29 @@ def sparse_correlation(ind1, data1, ind2, data2, n_features):
else:
return (1.0 - (dot_product / (norm1 * norm2)))


sparse_named_distances = {
'euclidean' : sparse_euclidean,
'manhattan' : sparse_manhattan,
'l1' : sparse_manhattan,
'taxicab' : sparse_manhattan,
'chebyshev' : sparse_chebyshev,
'linf' : sparse_chebyshev,
'linfty' : sparse_chebyshev,
'linfinity' : sparse_chebyshev,
'minkowski' : sparse_minkowski,
'hamming' : sparse_hamming,
'canberra' : sparse_canberra,
'bray_curtis' : sparse_bray_curtis,
'jaccard' : sparse_jaccard,
'matching' : sparse_matching,
'kulsinski' : sparse_kulsinski,
'rogers_tanimoto' : sparse_rogers_tanimoto,
'russellrao' : sparse_russellrao,
'sokal_michener' : sparse_sokal_michener,
'sokal_sneath' : sparse_sokal_sneath,
'cosine' : sparse_cosine,
'correlation' : sparse_correlation,
'euclidean': sparse_euclidean,
'manhattan': sparse_manhattan,
'l1': sparse_manhattan,
'taxicab': sparse_manhattan,
'chebyshev': sparse_chebyshev,
'linf': sparse_chebyshev,
'linfty': sparse_chebyshev,
'linfinity': sparse_chebyshev,
'minkowski': sparse_minkowski,
'hamming': sparse_hamming,
'canberra': sparse_canberra,
'bray_curtis': sparse_bray_curtis,
'jaccard': sparse_jaccard,
'matching': sparse_matching,
'kulsinski': sparse_kulsinski,
'rogers_tanimoto': sparse_rogers_tanimoto,
'russellrao': sparse_russellrao,
'sokal_michener': sparse_sokal_michener,
'sokal_sneath': sparse_sokal_sneath,
'cosine': sparse_cosine,
'correlation': sparse_correlation,
}

sparse_need_n_features = (
Expand All @@ -740,4 +743,4 @@ def sparse_correlation(ind1, data1, ind2, data2, n_features):
'russellrao',
'sokal_michener',
'correlation'
)
)
Loading