COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_cublas2 Namespace Reference

Functions

def test_float_gemv ()
 
def test_float_ger ()
 
def test_float_symv ()
 
def test_double_gemv ()
 
def test_double_ger ()
 
def test_double_symv ()
 

Variables

int dec = 4
 
int prec = 10**-dec
 
int sizem = 512
 
int sizen = 1024
 
 seed = np.int32(time.perf_counter() * 1e3)
 
 c = ch.context.get_instance()
 

Function Documentation

◆ test_double_gemv()

def test_cublas2.test_double_gemv ( )

Definition at line 123 of file test_cublas2.py.

123 def test_double_gemv():
124 
125  #function gemv
126  # testing: y=A.x
127  # x and y are vector, A a matrix
128 
129  alpha = 2
130  beta = 1
131 
132  Mat = ch.obj_double(c, np.random.randn(sizem, sizen))
133  MatT = ch.obj_double(c, np.random.randn(sizen, sizem))
134  # Mat.random_host(seed, 'U')
135  # MatT.random_host(seed + 2, 'U')
136 
137  Vectx = ch.obj_double(c, np.random.randn(sizen))
138  Vecty = ch.obj_double(c, np.random.randn(sizem))
139  # Vectx.random_host(seed + 3, 'U')
140  # Vecty.random_host(seed + 4, 'U')
141 
142  A = np.array(Mat)
143  AT = np.array(MatT)
144  x = np.array(Vectx)
145  y = np.array(Vecty)
146 
147  y = alpha * A.dot(x) + beta * y
148  y2 = alpha * A.dot(x)
149  y3 = alpha * AT.T.dot(x)
150 
151  # Vecty = ch.obj_double(c, np.random.randn((sizem)))
152 
153  Mat.gemv(Vectx, alpha, 'N', Vecty, beta)
154  Vecty_2 = Mat.gemv(Vectx, alpha, 'N')
155  Vecty_3 = MatT.gemv(Vectx, alpha, 'T')
156 
157  npt.assert_array_almost_equal(y, np.array(Vecty), decimal=dec - 1)
158  npt.assert_array_almost_equal(y2, np.array(Vecty_2), decimal=dec - 1)
159  npt.assert_array_almost_equal(y3, np.array(Vecty_3), decimal=dec - 1)
160 
161 

◆ test_double_ger()

def test_cublas2.test_double_ger ( )

Definition at line 162 of file test_cublas2.py.

162 def test_double_ger():
163  # function ger
164  # testing: A= x.y
165  # and : A= x.y+ A
166  # x and y are vectors, A a matrix
167  Mat = ch.obj_double(c, np.random.randn(sizem, sizen))
168  # Mat.random_host(seed + 2, 'U')
169 
170  Vectx = ch.obj_double(c, np.random.randn(sizen))
171  # Vectx.random_host(seed + 3, 'U')
172 
173  Vecty = ch.obj_double(c, np.random.randn(sizem))
174  # Vecty.random_host(seed + 4, 'U')
175 
176  x = np.array(Vectx)
177  A = np.array(Mat)
178  y = np.array(Vecty)
179 
180  caOresA = Vecty.ger(Vectx, Mat)
181  caOresB = Vecty.ger(Vectx)
182 
183  A = np.outer(y, x) + A
184  B = np.outer(y, x)
185 
186  # npt.assert_array_almost_equal(A, np.array(caOresA), decimal=dec)
187  npt.assert_array_almost_equal(B, np.array(caOresB), decimal=dec)
188 
189 

◆ test_double_symv()

def test_cublas2.test_double_symv ( )

Definition at line 190 of file test_cublas2.py.

190 def test_double_symv():
191  #function symv
192  # testing: y=A.x
193  # x and y are vector, A a symetric matrix
194 
195  MatSym = ch.obj_double(c, np.random.randn(sizem, sizem))
196  # MatSym.random_host(seed + 2, 'U')
197  data_R = np.array(MatSym)
198  data_R = data_R + data_R.T
199  MatSym = ch.obj_double(c, data_R)
200 
201  Vectx = ch.obj_double(c, np.random.randn((sizem)))
202  # Vectx.random_host(seed + 5, 'U')
203 
204  Vecty = ch.obj_double(c, np.random.randn((sizem)))
205 
206  A = np.array(MatSym)
207 
208  x2 = np.array(Vectx)
209 
210  y = A.dot(x2)
211 
212  MatSym.symv(Vectx, vecty=Vecty)
213  Vecty_2 = MatSym.symv(Vectx)
214 
215  npt.assert_array_almost_equal(y, np.array(Vecty), decimal=dec)
216  npt.assert_array_almost_equal(y, np.array(Vecty_2), decimal=dec)

◆ test_float_gemv()

def test_cublas2.test_float_gemv ( )

Definition at line 27 of file test_cublas2.py.

27 def test_float_gemv():
28 
29  #function gemv
30  # testing: y=A.x
31  # x and y are vector, A a matrix
32 
33  alpha = 2
34  beta = 1
35 
36  Mat = ch.obj_float(c, np.random.randn(sizem, sizen))
37  MatT = ch.obj_float(c, np.random.randn(sizen, sizem))
38  # Mat.random_host(seed, 'U')
39  # MatT.random_host(seed + 2, 'U')
40 
41  Vectx = ch.obj_float(c, np.random.randn(sizen))
42  Vecty = ch.obj_float(c, np.random.randn(sizem))
43  # Vectx.random_host(seed + 3, 'U')
44  # Vecty.random_host(seed + 4, 'U')
45 
46  A = np.array(Mat)
47  AT = np.array(MatT)
48  x = np.array(Vectx)
49  y = np.array(Vecty)
50 
51  y = alpha * A.dot(x) + beta * y
52  y2 = alpha * A.dot(x)
53  y3 = alpha * AT.T.dot(x)
54 
55  # Vecty = ch.obj_float(c, np.random.randn((sizem)))
56 
57  Mat.gemv(Vectx, alpha, 'N', Vecty, beta)
58  Vecty_2 = Mat.gemv(Vectx, alpha, 'N')
59  Vecty_3 = MatT.gemv(Vectx, alpha, 'T')
60 
61  npt.assert_array_almost_equal(y, np.array(Vecty), decimal=dec - 1)
62  npt.assert_array_almost_equal(y2, np.array(Vecty_2), decimal=dec - 1)
63  npt.assert_array_almost_equal(y3, np.array(Vecty_3), decimal=dec - 1)
64 
65 

◆ test_float_ger()

def test_cublas2.test_float_ger ( )

Definition at line 66 of file test_cublas2.py.

66 def test_float_ger():
67  # function ger
68  # testing: A= x.y
69  # and : A= x.y+ A
70  # x and y are vectors, A a matrix
71  Mat = ch.obj_float(c, np.random.randn(sizem, sizen))
72  # Mat.random_host(seed + 2, 'U')
73 
74  Vectx = ch.obj_float(c, np.random.randn(sizen))
75  # Vectx.random_host(seed + 3, 'U')
76 
77  Vecty = ch.obj_float(c, np.random.randn(sizem))
78  # Vecty.random_host(seed + 4, 'U')
79 
80  x = np.array(Vectx)
81  A = np.array(Mat)
82  y = np.array(Vecty)
83 
84  caOresA = Vecty.ger(Vectx, Mat)
85  caOresB = Vecty.ger(Vectx)
86 
87  A = np.outer(y, x) + A
88  B = np.outer(y, x)
89 
90  # npt.assert_array_almost_equal(A, np.array(caOresA), decimal=dec)
91  npt.assert_array_almost_equal(B, np.array(caOresB), decimal=dec)
92 
93 

◆ test_float_symv()

def test_cublas2.test_float_symv ( )

Definition at line 94 of file test_cublas2.py.

94 def test_float_symv():
95  #function symv
96  # testing: y=A.x
97  # x and y are vector, A a symetric matrix
98 
99  MatSym = ch.obj_float(c, np.random.randn(sizem, sizem))
100  # MatSym.random_host(seed + 2, 'U')
101  data_R = np.array(MatSym)
102  data_R = data_R + data_R.T
103  MatSym = ch.obj_float(c, data_R)
104 
105  Vectx = ch.obj_float(c, np.random.randn((sizem)))
106  # Vectx.random_host(seed + 5, 'U')
107 
108  Vecty = ch.obj_float(c, np.random.randn((sizem)))
109 
110  A = np.array(MatSym)
111 
112  x2 = np.array(Vectx)
113 
114  y = A.dot(x2)
115 
116  MatSym.symv(Vectx, vecty=Vecty)
117  Vecty_2 = MatSym.symv(Vectx)
118 
119  npt.assert_array_almost_equal(y, np.array(Vecty), decimal=dec)
120  npt.assert_array_almost_equal(y, np.array(Vecty_2), decimal=dec)
121 
122 

Variable Documentation

◆ c

test_cublas2.c = ch.context.get_instance()

Definition at line 18 of file test_cublas2.py.

◆ dec

int test_cublas2.dec = 4

Definition at line 6 of file test_cublas2.py.

◆ prec

int test_cublas2.prec = 10**-dec

Definition at line 7 of file test_cublas2.py.

◆ seed

test_cublas2.seed = np.int32(time.perf_counter() * 1e3)

Definition at line 12 of file test_cublas2.py.

◆ sizem

int test_cublas2.sizem = 512

Definition at line 9 of file test_cublas2.py.

◆ sizen

int test_cublas2.sizen = 1024

Definition at line 10 of file test_cublas2.py.