MCPcopy Create free account
hub / github.com/PythonOT/POT / eliminate_zeros

Method eliminate_zeros

ot/backend.py:2296–2310  ·  view source on GitHub ↗
(self, a, threshold=0.0)

Source from the content-addressed store, hash-verified

2294 return self.todense(a)
2295
2296 def eliminate_zeros(self, a, threshold=0.0):
2297 if self.issparse(a):
2298 if threshold > 0:
2299 mask = self.abs(a) <= threshold
2300 mask = ~mask
2301 mask = mask.nonzero()
2302 else:
2303 mask = a._values().nonzero()
2304 nv = a._values().index_select(0, mask.view(-1))
2305 ni = a._indices().index_select(1, mask.view(-1))
2306 return self.coo_matrix(nv, ni[0], ni[1], shape=a.shape, type_as=a)
2307 else:
2308 if threshold > 0:
2309 a[self.abs(a) <= threshold] = 0
2310 return a
2311
2312 def todense(self, a):
2313 if self.issparse(a):

Callers

nothing calls this directly

Calls 3

issparseMethod · 0.95
absMethod · 0.95
coo_matrixMethod · 0.95

Tested by

no test coverage detected