-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
42 lines (34 loc) · 742 Bytes
/
test.py
File metadata and controls
42 lines (34 loc) · 742 Bytes
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
from PCG import PCG
import numpy as np
import utils
# num_get_pos
nq = 2
# num_get_vel
nv = 1
# knot points
n_blocks = 4
nx = nq+nv
n = nx * n_blocks
# PCG expects a positive semidefinite matrix
A = utils.psd_block_diagonal(nx, n_blocks)
# Generate a random vector b
b = np.random.rand(n, 1)
# create PCG object
options = {'preconditioner_type' : 'SS'}
pcg = PCG(A, b, nx, n_blocks, options = options)
x_pcg = pcg.solve()
# compare
x_numpy = np.linalg.solve(A, b)
if(np.allclose(x_numpy, x_pcg)):
print("Test passed")
else:
print("Test failed")
print("Numpy answer")
print(x_numpy)
print("PCG answer")
print(x_pcg)
# print trace
pcg.update_RETURN_TRACE(True)
x_pcg, traces = pcg.solve()
print("Printing Traces")
print(traces)