Exemple #1
0
def test_from_to_without():
    frm, to, without = 2, 88, 47
    lst = list(range(frm, without)) + list(range(without + 1, to))
    assert lst == from_to_without(frm, to, without)

    rlst = list(range(to - 1, without, -1)) + list(
        range(without - 1, frm - 1, -1))
    assert rlst == from_to_without(frm, to, without, reverse=True)
    assert lst[::-1] == from_to_without(frm, to, without, reverse=True)
Exemple #2
0
 def uttkrp(self, U, mode):
     R = U[1].shape[1] if mode == 0 else U[0].shape[1]
     dims = from_to_without(0, self.ndim, mode)
     V = np.zeros((self.shape[mode], R))
     for r in range(R):
         Z = tuple(U[n][:, r] for n in dims)
         TZ = self.ttv(Z, mode, without=True)
         if isinstance(TZ, sptensor):
             V[TZ.subs, r] = TZ.vals
         else:
             V[:, r] = self.ttv(Z, mode, without=True)
     return V
Exemple #3
0
 def uttkrp(self, U, mode):
     R = U[1].shape[1] if mode == 0 else U[0].shape[1]
     # dims = list(range(0, mode)) + list(range(mode + 1, self.ndim))
     dims = from_to_without(0, self.ndim, mode)
     V = zeros((self.shape[mode], R))
     for r in range(R):
         Z = tuple(U[n][:, r] for n in dims)
         TZ = self.ttv(Z, mode, without=True)
         if isinstance(TZ, sptensor):
             V[TZ.subs, r] = TZ.vals
         else:
             V[:, r] = self.ttv(Z, mode, without=True)
     return V