You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The constructor for sptensor fails an assertion when the tensor size is large. It's important to note that the shape isn't allocated, simply checked for consistency.
Example
For size = (50000000, 50000000, 100, 50000) and nnzs = 1000000000, we get:
X = ttb.sptenrand(sz, nonzeros=nnz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jermyer/pyttb/pyttb/sptensor.py", line 3709, in sptenrand
return ttb.sptensor.from_function(unit_uniform, shape, valid_nonzeros)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jermyer/pyttb/pyttb/sptensor.py", line 214, in from_function
assert False, (
AssertionError: Requested number of nonzeros must be positive and less than the total size
Checking np.prod(size) used in the assertion, np.prod(size) = -6892481975075995648 .
Solution
Use prod from the math module to get the correct result, i.e.,
>>> from math import prod
>>> sz = (50000000,50000000,100,50000)
>>> prod(sz)
12500000000000000000000
This has the added bonus that sz is a python tuple, not a numpy object, as pointed out by @dmdunla.
The text was updated successfully, but these errors were encountered:
Issue
The constructor for
sptensor
fails an assertion when the tensor size is large. It's important to note that theshape
isn't allocated, simply checked for consistency.Example
For
size = (50000000, 50000000, 100, 50000)
andnnzs = 1000000000
, we get:Checking
np.prod(size)
used in the assertion,np.prod(size) = -6892481975075995648
.Solution
Use
prod
from themath
module to get the correct result, i.e.,This has the added bonus that
sz
is a pythontuple
, not anumpy
object, as pointed out by @dmdunla.The text was updated successfully, but these errors were encountered: