Commit 921a4947 authored by Ghislain Antony Vaillant's avatar Ghislain Antony Vaillant

Merge tag 'upstream/0.1.1'

Upstream version 0.1.1

# gpg: Signature made Sat 05 Aug 2017 09:39:07 BST
# gpg:                using RSA key F3DB8E7525060E1BDB84C20D6A990FB3DDEB910A
# gpg:                issuer "ghisvail@gmail.com"
# gpg: Good signature from "Ghislain Antony Vaillant <ghisvail@gmail.com>" [ultimate]
parents 625557b9 dd5978fd
......@@ -5,7 +5,7 @@ from setuptools import setup
setup(name='sparse',
version='0.1.0',
version='0.1.1',
description='Sparse',
url='http://github.com/mrocklin/sparse/',
maintainer='Matthew Rocklin',
......
from .core import COO, tensordot, concatenate, stack, dot
__version__ = '0.1.0'
__version__ = '0.1.1'
This diff is collapsed.
......@@ -55,6 +55,7 @@ def test_transpose(axis):
[(2, 3, 4, 5), (8, 15)],
[(2, 3, 4, 5), (24, 5)],
[(2, 3, 4, 5), (20, 6)],
[(), ()],
])
def test_reshape(a, b):
x = random_x(a)
......@@ -70,7 +71,7 @@ def test_large_reshape():
col = row % m # np.random.randint(0, m, size=n, dtype=np.uint16)
data = np.ones(n, dtype=np.uint8)
x = COO((data, (row, col)))
x = COO((data, (row, col)), sorted=True, has_duplicates=False)
assert_eq(x, x.reshape(x.shape))
......@@ -126,6 +127,7 @@ def test_tensordot(a_shape, b_shape, axes):
def test_dot():
import operator
a = random_x((3, 4, 5))
b = random_x((5, 6))
......@@ -135,6 +137,33 @@ def test_dot():
assert_eq(a.dot(b), sa.dot(sb))
assert_eq(np.dot(a, b), sparse.dot(sa, sb))
if hasattr(operator, 'matmul'):
# Basic equivalences
assert_eq(eval("a @ b"), eval("sa @ sb"))
assert_eq(eval("sa @ sb"), sparse.dot(sa, sb))
# Test that SOO's and np.array's combine correctly
assert_eq(eval("a @ sb"), eval("sa @ b"))
@pytest.mark.xfail
def test_dot_nocoercion():
a = random_x((3, 4, 5))
b = random_x((5, 6))
la = a.tolist()
lb = b.tolist()
la, lb # silencing flake8
sa = COO.from_numpy(a)
sb = COO.from_numpy(b)
sa, sb # silencing flake8
if hasattr(operator, 'matmul'):
# Operations with naive collection (list)
assert_eq(eval("la @ b"), eval("la @ sb"))
assert_eq(eval("a @ lb"), eval("sa @ lb"))
@pytest.mark.parametrize('func', [np.expm1, np.log1p, np.sin, np.tan,
np.sinh, np.tanh, np.floor, np.ceil,
......@@ -365,8 +394,8 @@ def test_scalar_exponentiation():
def test_create_with_lists_of_tuples():
L = [((0, 0, 0), 1),
((1, 1, 1), 2),
((1, 2, 1), 1),
((1, 1, 1), 2),
((1, 3, 2), 3)]
s = COO(L)
......@@ -410,21 +439,13 @@ def test_scipy_sparse_interface():
def test_cache_csr():
x = random_x((10, 5))
s = COO.from_numpy(x)
s = COO(x, cache=True)
assert isinstance(s.tocsr(), scipy.sparse.csr_matrix)
assert isinstance(s.tocsc(), scipy.sparse.csc_matrix)
assert s.tocsr() is s.tocsr()
assert s.tocsc() is s.tocsc()
st = s.T
assert_eq(st._csr, st)
assert_eq(st._csc, st)
assert isinstance(st.tocsr(), scipy.sparse.csr_matrix)
assert isinstance(st.tocsc(), scipy.sparse.csc_matrix)
def test_empty_shape():
x = COO([], [1.0])
......@@ -447,3 +468,39 @@ def test_raise_dense():
with pytest.raises((ValueError, NotImplementedError)):
x + 1
def test_large_sum():
n = 500000
x = np.random.randint(0, 10000, size=(n,))
y = np.random.randint(0, 1000, size=(n,))
z = np.random.randint(0, 3, size=(n,))
data = np.random.random(n)
a = COO((x, y, z), data)
assert a.shape == (10000, 1000, 3)
b = a.sum(axis=2)
assert b.nnz > 100000
def test_add_many_sparse_arrays():
x = COO({(1, 1): 1})
y = sum([x] * 100)
assert y.nnz < np.prod(y.shape)
def test_caching():
x = COO({(10, 10, 10): 1})
assert x[:].reshape((100, 10)).transpose().tocsr() is not x[:].reshape((100, 10)).transpose().tocsr()
x = COO({(10, 10, 10): 1}, cache=True)
assert x[:].reshape((100, 10)).transpose().tocsr() is x[:].reshape((100, 10)).transpose().tocsr()
x = COO({(1, 1, 1, 1, 1, 1, 1, 2): 1}, cache=True)
for i in range(x.ndim):
x.reshape((1,) * i + (2,) + (1,) * (x.ndim - i - 1))
assert len(x._cache['reshape']) < 5
import numpy as np
from .core import COO
def assert_eq(x, y):
assert x.shape == y.shape
assert x.dtype == y.dtype
if isinstance(x, COO):
if x.sorted:
assert is_lexsorted(x)
if isinstance(y, COO):
if y.sorted:
assert is_lexsorted(y)
if hasattr(x, 'todense'):
xx = x.todense()
else:
......@@ -13,3 +22,7 @@ def assert_eq(x, y):
else:
yy = y
assert np.allclose(xx, yy)
def is_lexsorted(x):
return not x.shape or (np.diff(x.linear_loc()) > 0).all()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment