test_libtt.py
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python3
# ====================================================
# First, compile: python setup.py build_ext --inplace
# Second, exucute: python test_libtt.py
# ====================================================
# ====================================================
# ====================================================
# === Import the extension and manage errors
# ====================================================
# ====================================================
try:
import libtt
except Exception as e:
print(f"Error import libtt: {e}")
print("\nI try to help you to find the solution:")
import os, glob
import subprocess
cwd = os.getcwd()
fics = glob.glob("libtt*.so")
for fic in fics:
cmd = f"ldd {fic}"
print(f"\nExecute: {cmd}")
argus = []
argus.append("ldd")
argus.append(fic)
res = subprocess.run(argus, capture_output=True)
outb = res.stdout
outs = outb.decode().split("\n")
comment = ""
for out in outs:
print(out)
words = out.split()
if len(words) > 2:
lib = words[0]
path = words[2]
if path == "not":
comment = f"The path of the library {lib} is not found. Try:"
if comment != "":
print(f"{comment}")
cmd = f"export LD_LIBRARY_PATH={cwd}:$LD_LIBRARY_PATH"
print(f"$ {cmd}")
print("\nIf it a success you have to record the LD_LIBRARY_PATH permanently:")
print("$ sudo vi /etc/ld.so.conf")
print("$ sudo ldconfig")
print("")
exit()
# ====================================================
# ====================================================
# === List of tests to execute
# ====================================================
# ====================================================
tests = []
#tests.append("matrix")
#tests.append("matrixio")
tests.append("pimaseries")
# ====================================================
# ====================================================
# === Code of tests
# ====================================================
# ====================================================
import time
for test in tests:
print("="*40+"\n"+"="*10+f" Test: {test} \n"+"="*40)
if test == "matrix":
res = libtt.matrix(4096,4096,8.99)
print(f"{res=}")
res = libtt.matrix(10,5,4.56)
print(f"{res=}")
if test == "matrixio":
import numpy as np
for k in range(15):
print("="*20 + f" libtt {k}")
p = np.zeros((1000,1000), dtype=np.dtype(np.uint32) )
#p = np.zeros((1000,1000), dtype=np.dtype(np.int32) )
#p = np.zeros((4096, 4096), dtype=np.dtype(np.float32) )
#p = np.zeros((4096, 4096), dtype=np.dtype(np.float64) )
print(f"{p=}")
res = libtt.matrixio(p)
print(f"{res=}")
if test == "pimaseries":
import sys
sys.path.append("..");
import guitastro
import numpy as np
try:
print("== ima")
ima = guitastro.Ima()
p = np.zeros((100,50), dtype=np.dtype(np.uint32) )
#p = np.zeros((100,50), dtype=np.dtype(np.float32) )
#p = np.zeros((100,50), dtype=np.dtype(np.float64) )
#p = [ [1, 3, 4], [7, -6, -9] ]
ima.array2buf(p)
for k in range(15):
print("="*20 + f" libtt {k}")
print(f"{ima._array}")
print(f"{ima._array.dtype=}")
#print(f"{ima.cards=}")
ima2 = libtt.pimaseries(ima, "OFFSET offset=100")
print(f"{ima2}")
print(f"{ima2.dtype=}")
except BaseException as e:
print("Error:", str(e))
print("== END")
del sys.modules['libtt']
del libtt
print("== SUPER END")