-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·56 lines (44 loc) · 1 KB
/
example.py
File metadata and controls
executable file
·56 lines (44 loc) · 1 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
#!/usr/bin/python
"""A simple example of how the bandmat package may be used."""
# Copyright 2013, 2014, 2015, 2016, 2017, 2018 Matt Shannon
# This file is part of bandmat.
# See `License` for details of license and warranty.
import numpy as np
import bandmat as bm
a_bm = bm.BandMat(
1, 1,
np.array([
[0.0, 0.2, 0.3, 0.4, 0.5],
[1.0, 0.9, 1.1, 0.8, 1.3],
[0.3, 0.1, 0.5, 0.6, 0.0],
])
)
b_bm = bm.BandMat(
1, 0,
np.array([
[1.0, 0.9, 1.1, 0.8, 1.3],
[0.3, 0.1, 0.5, 0.6, 0.0],
])
)
c_bm = bm.dot_mm(a_bm.T, b_bm)
d_bm = a_bm + b_bm
a_full = a_bm.full()
b_full = b_bm.full()
c_full = c_bm.full()
d_full = d_bm.full()
print('a_full:')
print(a_full)
print()
print('b_full:')
print(b_full)
print()
print('np.dot(a_full.T, b_full):')
print(c_full)
print()
print('a_full + b_full:')
print(d_full)
print()
c_full_again = np.dot(a_full.T, b_full)
assert np.allclose(c_full_again, c_full)
d_full_again = a_full + b_full
assert np.allclose(d_full_again, d_full)