1
+ import pytest
2
+ from pyrix import Matrix , unitMatrix , zeroMatrix , randomMatrix , identityMatrix
3
+ from pyrix .exception import incompaitableTypeException , divisionErrorException , bitWiseOnMatrix
4
+ import copy
5
+ from pyrix .util import flipDimensions ,Copy ,JSONExport ,JSONImport ,nestifyMatrix ,listifyMatrix
6
+ import math
7
+ data = [
8
+ [
9
+ [2.5 , 3.3 ],
10
+ [6.3 , 0 ]
11
+ ],
12
+ [
13
+ [1.1134 , 23.2165 , 90.4564 ],
14
+ [2.4453 , 23.2351 , 91.8869 ],
15
+ [1.0011 , 56.4221 , 0.54322 ]
16
+ ],
17
+ [
18
+ [4.935264587402344e-05 , 2.765655517578125e-05 ,
19
+ 2.86102294921875e-05 , 3.0517578125e-05 ],
20
+ [3.4809112548828125e-05 , 3.814697265625e-05 ,
21
+ 4.172325134277344e-05 , 0.00010323524475097656 ],
22
+ [7.915496826171875e-05 , 8.416175842285156e-05 ,
23
+ 8.96453857421875e-05 , 9.703636169433594e-05 ],
24
+ [0.00010395050048828125 , 0.00011372566223144531 ,
25
+ 0.00011777877807617188 , 0.00012445449829101562 ]
26
+ ],
27
+ [
28
+ [0.2511575222015381 , 0.2516036033630371 , 0.2521524429321289 ,
29
+ 0.2523155212402344 , 0.25193333625793457 ],
30
+ [0.2519676685333252 , 0.2544589042663574 , 0.25499844551086426 ,
31
+ 0.2547335624694824 , 0.25522279739379883 ],
32
+ [0.2551295757293701 , 0.2559933662414551 , 0.256514310836792 ,
33
+ 0.25737428665161133 , 0.2577781677246094 ],
34
+ [0.2581827640533447 , 0.2585480213165283 , 0.25943970680236816 ,
35
+ 0.2707202434539795 , 0.26087403297424316 ],
36
+ [0.26274585723876953 , 0.263012170791626 , 0.2636113166809082 ,
37
+ 0.26253175735473633 , 0.2637825012207031 ]
38
+ ]
39
+ ]
40
+ listed = [
41
+ [2.5 , 3.3 ,6.3 , 0 ],
42
+ [1.1134 , 23.2165 , 90.4564 ,2.4453 , 23.2351 , 91.8869 ,1.0011 , 56.4221 , 0.54322 ],
43
+ [4.935264587402344e-05 , 2.765655517578125e-05 ,
44
+ 2.86102294921875e-05 , 3.0517578125e-05 ,3.4809112548828125e-05 , 3.814697265625e-05 ,
45
+ 4.172325134277344e-05 , 0.00010323524475097656 ,7.915496826171875e-05 , 8.416175842285156e-05 ,
46
+ 8.96453857421875e-05 , 9.703636169433594e-05 ,0.00010395050048828125 , 0.00011372566223144531 ,
47
+ 0.00011777877807617188 , 0.00012445449829101562 ],
48
+ [0.2511575222015381 , 0.2516036033630371 , 0.2521524429321289 ,
49
+ 0.2523155212402344 , 0.25193333625793457 ,0.2519676685333252 , 0.2544589042663574 , 0.25499844551086426 ,
50
+ 0.2547335624694824 , 0.25522279739379883 ,0.2551295757293701 , 0.2559933662414551 , 0.256514310836792 ,
51
+ 0.25737428665161133 , 0.2577781677246094 ,0.2581827640533447 , 0.2585480213165283 , 0.25943970680236816 ,
52
+ 0.2707202434539795 , 0.26087403297424316 ,0.26274585723876953 , 0.263012170791626 , 0.2636113166809082 ,
53
+ 0.26253175735473633 , 0.2637825012207031 ]
54
+ ]
55
+
56
+ @pytest .fixture (scope = "session" )
57
+ def test_Matrixinit5 ():
58
+ (rows , cols ) = [2 , 3 , 4 , 5 ], [2 , 3 , 4 , 5 ]
59
+ objects = []
60
+ traversal = 0
61
+ try :
62
+ for (r , c , d ) in zip (rows , cols , data ):
63
+ objects .append (Matrix (nrow = r , ncol = c , data = d ))
64
+ traversal += 1
65
+ except incompaitableTypeException :
66
+ print ("Incompaitable Sizes" )
67
+ return objects
68
+
69
+ def test_listifynestify (test_Matrixinit5 ):
70
+ listings = []
71
+ copmat = Copy (test_Matrixinit5 )
72
+ for i in range (len (test_Matrixinit5 )):
73
+ listings .append (listifyMatrix (test_Matrixinit5 [i ]))
74
+ assert listings [i ]== listed [i ]
75
+ for i in range (len (test_Matrixinit5 )):
76
+ assert nestifyMatrix (listings [i ],i + 2 ,i + 2 )== data [i ]
77
+
78
+
79
+ def test_JSON (test_Matrixinit5 ):
80
+ for i in range (len (test_Matrixinit5 )):
81
+ JSONExport (test_Matrixinit5 [i ],"test.json" )
82
+ temp = JSONImport ("test.json" ,mode = "manual" )
83
+ assert temp == test_Matrixinit5 [i ]
84
+
85
+ def test_flipdims (test_Matrixinit5 ):
86
+ for i in range (len (test_Matrixinit5 )):
87
+ assert flipDimensions (test_Matrixinit5 [i ])== test_Matrixinit5 [i ]
0 commit comments