Skip to content

Commit b351770

Browse files
authored
Merge pull request #23 from meyer-lab/test
Add test on factorizations
2 parents fb467a1 + 74ac736 commit b351770

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tensorpack/test/testcase.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import tensorly as tl
2+
import numpy as np
3+
from tensorly.random import random_cp
4+
from tensorpack.cmtf import perform_CP, calcR2X
5+
6+
7+
def testcase(shape: tuple, rankOrig: int, rankNew: int):
8+
9+
'''
10+
Creates a random CP tensor and converts it into a full tensor.
11+
Then, it tests the CP-decomposition method to see if the R2X results correctly.
12+
'''
13+
14+
tFacOrig = random_cp(shape, rankOrig, full=False)
15+
tOrig = tl.cp_to_tensor(tFacOrig)
16+
17+
originalR2X = calcR2X(tFacOrig, tOrig)
18+
assert originalR2X == 1
19+
20+
tFacNew = perform_CP(tOrig, r=rankNew)
21+
newR2X = calcR2X(tFacNew, tOrig)
22+
23+
return newR2X

0 commit comments

Comments
 (0)