Skip to content

Commit e515f30

Browse files
Statistics: Rename sparse_zeros to sparse_implicit_zeros
1 parent dd516a7 commit e515f30

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Orange/data/table.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
)
2020
from Orange.data.util import SharedComputeValue, vstack, hstack
2121
from Orange.statistics.util import bincount, countnans, contingency, \
22-
stats as fast_stats, sparse_has_zeros, sparse_count_zeros, \
23-
sparse_zero_weights
22+
stats as fast_stats, sparse_has_implicit_zeros, sparse_count_implicit_zeros, \
23+
sparse_implicit_zero_weights
2424
from Orange.util import flatten
2525

2626
__all__ = ["dataset_dirs", "get_sample_datasets_dir", "RowInstance", "Table"]
@@ -1427,11 +1427,11 @@ def _compute_distributions(self, columns=None):
14271427
dist = np.array(_valuecount.valuecount(vals))
14281428
# If sparse, then 0s will not be counted with `valuecount`, so
14291429
# we have to add them to the result manually.
1430-
if sp.issparse(x) and sparse_has_zeros(x):
1430+
if sp.issparse(x) and sparse_has_implicit_zeros(x):
14311431
if W is not None:
1432-
zero_weights = sparse_zero_weights(x, W).sum()
1432+
zero_weights = sparse_implicit_zero_weights(x, W).sum()
14331433
else:
1434-
zero_weights = sparse_count_zeros(x)
1434+
zero_weights = sparse_count_implicit_zeros(x)
14351435
zero_vec = [0, zero_weights]
14361436
dist = np.insert(dist, np.searchsorted(dist[0], 0), zero_vec, axis=1)
14371437
# Since `countnans` assumes vector shape to be (1, n) and `x`

Orange/statistics/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ def _count_nans_per_row_sparse(X, weights, dtype=None):
3030
return np.fromiter((np.isnan(row.data).sum() for row in X), dtype=dtype)
3131

3232

33-
def sparse_count_zeros(x):
33+
def sparse_count_implicit_zeros(x):
3434
""" Count the number of implicit zeros in a sparse matrix. """
3535
if not sp.issparse(x):
3636
raise TypeError('The matrix provided was not sparse.')
3737
return np.prod(x.shape) - x.nnz
3838

3939

40-
def sparse_has_zeros(x):
40+
def sparse_has_implicit_zeros(x):
4141
""" Check if sparse matrix contains any implicit zeros. """
4242
if not sp.issparse(x):
4343
raise TypeError('The matrix provided was not sparse.')
4444
return np.prod(x.shape) != x.nnz
4545

4646

47-
def sparse_zero_weights(x, weights):
47+
def sparse_implicit_zero_weights(x, weights):
4848
""" Extract the weight values of all zeros in a sparse matrix. """
4949
if not sp.issparse(x):
5050
raise TypeError('The matrix provided was not sparse.')
@@ -103,10 +103,10 @@ def bincount(x, weights=None, max_val=None, minlength=None):
103103
if sp.issparse(x):
104104
x = x.tocsr()
105105
if weights is not None:
106-
zero_weights = sparse_zero_weights(x, weights).sum()
106+
zero_weights = sparse_implicit_zero_weights(x, weights).sum()
107107
weights = weights[x.indices]
108108
else:
109-
zero_weights = sparse_count_zeros(x)
109+
zero_weights = sparse_count_implicit_zeros(x)
110110

111111
x = x.data
112112

@@ -343,7 +343,7 @@ def _nan_min_max(x, func, axis=0):
343343
return func(x, axis=axis)
344344
if axis is None:
345345
extreme = func(x.data, axis=axis) if x.nnz else float('nan')
346-
if sparse_has_zeros(x):
346+
if sparse_has_implicit_zeros(x):
347347
extreme = func([0, extreme])
348348
return extreme
349349
if axis == 0:
@@ -356,7 +356,7 @@ def _nan_min_max(x, func, axis=0):
356356
for row in x:
357357
values = row.data
358358
extreme = func(values) if values.size else float('nan')
359-
if sparse_has_zeros(row):
359+
if sparse_has_implicit_zeros(row):
360360
extreme = func([0, extreme])
361361
r.append(extreme)
362362
return np.array(r)
@@ -422,7 +422,7 @@ def unique(x, return_counts=False):
422422
if not sp.issparse(x):
423423
return np.unique(x, return_counts=return_counts)
424424

425-
implicit_zeros = sparse_count_zeros(x)
425+
implicit_zeros = sparse_count_implicit_zeros(x)
426426
explicit_zeros = not np.all(x.data)
427427
r = np.unique(x.data, return_counts=return_counts)
428428
if not implicit_zeros:

0 commit comments

Comments
 (0)