Skip to content

Commit

Permalink
Fix some package and variable names; lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ghbrown committed Jun 25, 2024
1 parent dd8c86d commit e5c6a9a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pyttb/ktensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,21 +889,24 @@ def full(self) -> ttb.tensor:
[63. 85.]]
<BLANKLINE>
"""

def min_split_dims(dims):
"""
solve
min_{i in range(1,d)} product(dims[:i]) + product(dims[i:])
to minimize the memory footprint of the intermediate matrix
"""
sum_of_prods = [np.prod(dims[:i])+np.prod(dims[i:])
for i in range(1,len(dims))]
sum_of_prods = [
np.prod(dims[:i]) + np.prod(dims[i:]) for i in range(1, len(dims))
]
i_min = np.argmin(sum_of_prods) + 1 # note range above starts at 1
return i_min

i_split = min_split_dims(self.shape)
data = ( (ttb.khatrirao(*self.factor_matrices[:i_split],reverse=True) * w) @
ttb.khatrirao(*self.factor_matrices[i_split:],reverse=True).T )
return pyttb.tensor(data, self.shape, copy=False)
data = (
ttb.khatrirao(*self.factor_matrices[:i_split], reverse=True) * self.weights
) @ ttb.khatrirao(*self.factor_matrices[i_split:], reverse=True).T
return ttb.tensor(data, self.shape, copy=False)

def innerprod(
self, other: Union[ttb.tensor, ttb.sptensor, ktensor, ttb.ttensor]
Expand Down

0 comments on commit e5c6a9a

Please sign in to comment.