/ sparse Public

# Partial Add Reduction Loses Index Combinations#82

Closed
opened this issue Jan 18, 2018 · 2 comments
Closed

# Partial Add Reduction Loses Index Combinations #82

opened this issue Jan 18, 2018 · 2 comments
Labels

### BruceChurch commented Jan 18, 2018

 Is this correct behavior for a partial add reduction? Using the canonical example I added a reduction over the first two indices. And the results look strange in that the first index of the resulting 2D sparse matrix are all zeros. Here is a simple example illustrating the point. Thanks, Bruce ``````import numpy as np import pandas as pd import sparse n = 1000 ndims = 4 nnz = 1000000 coords = np.random.randint(0, n - 1, size=(ndims, nnz)) data = np.random.random(nnz) x = sparse.COO(coords, data, shape=((n,)*ndims)) z = x.sum(axis=(0,1)) # how many unique combos is the last 2 slots of x? df = pd.DataFrame(coords[:2].T) print df.drop_duplicates().shape # how many unique combos is the 2 slots of z? df2=pd.DataFrame(z.coords.T) print df2.drop_duplicates().shape # Shouldn't these match? `````` The text was updated successfully, but these errors were encountered:
Merged

### hameerabbasi commented Jan 18, 2018

 @BruceChurch, your test is a little off. This line: ``````df = pd.DataFrame(coords[:2].T) `````` Should be ``````df = pd.DataFrame(coords[2:].T) `````` Since we have to check the uniques over the axes that we are NOT summing over. That said, PR #83 fixes this issue. Would you mind testing it?

### BruceChurch commented Jan 19, 2018

 Yes this fixes the problem. Thanks!