Skip to content

Commit d9d8f2f

Browse files
committed
Fixing inefficiency in pyttb.tenrand.
The old version was creating random data as a multway arraw, reordering it to Fortran order (expensive and pointless), and then called the tensor constructor. Instead, we exploit the fact that we can just pass a 1D random array and then reshape that into the desired shape.
1 parent 9b0f88d commit d9d8f2f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

pyttb/tensor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2857,8 +2857,7 @@ def tenrand(shape: Shape, order: MemoryLayout = "F") -> tensor:
28572857
# Typing doesn't play nice with partial
28582858
# mypy issue: 1484
28592859
def unit_uniform(pass_through_shape: Tuple[int, ...]) -> np.ndarray:
2860-
data = np.random.uniform(low=0, high=1, size=pass_through_shape)
2861-
to_memory_order(data, order)
2860+
data = np.random.uniform(low=0, high=1, size=np.prod(pass_through_shape))
28622861
return data
28632862

28642863
return tensor.from_function(unit_uniform, shape)

0 commit comments

Comments
 (0)