Skip to content

Commit d7bb85a

Browse files
tgkoldadmdunla
andauthored
Fixing inefficiency in pyttb.tenrand. (#428)
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. Co-authored-by: Danny Dunlavy <[email protected]>
1 parent 62fe166 commit d7bb85a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Diff for: pyttb/tensor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2959,8 +2959,7 @@ def tenrand(shape: Shape, order: MemoryLayout = "F") -> tensor:
29592959
# Typing doesn't play nice with partial
29602960
# mypy issue: 1484
29612961
def unit_uniform(pass_through_shape: Tuple[int, ...]) -> np.ndarray:
2962-
data = np.random.uniform(low=0, high=1, size=pass_through_shape)
2963-
to_memory_order(data, order)
2962+
data = np.random.uniform(low=0, high=1, size=np.prod(pass_through_shape))
29642963
return data
29652964

29662965
return tensor.from_function(unit_uniform, shape)

0 commit comments

Comments
 (0)