Skip to content

Commit 33b0558

Browse files
committed
minor fixes to linear algebra examples
1 parent 0692510 commit 33b0558

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

examples/lin_algebra/cholesky.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
1+
#!/usr/bin/env python
2+
#######################################################
3+
# Copyright (c) 2022, ArrayFire
4+
# All rights reserved.
5+
#
6+
# This file is distributed under 3-clause BSD license.
7+
# The complete license agreement can be obtained at:
8+
# http://arrayfire.com/licenses/BSD-3-Clause
9+
########################################################
10+
111
import arrayfire as af
212

313
def main():
414
try:
5-
device = 0
615
af.info()
7-
16+
817
n = 5
9-
t = af.randu(n,n)
10-
inn = af.matmulNT(t,t) + af.identity(n,n)*n
18+
t = af.randu(n, n)
19+
arr_in = af.matmulNT(t, t) + af.identity(n, n) * n
1120

1221
print("Running Cholesky InPlace\n")
13-
cin_upper = inn
14-
cin_lower = inn
15-
22+
cin_upper = arr_in.copy()
23+
cin_lower = arr_in.copy()
24+
1625
af.cholesky_inplace(cin_upper, True)
1726
af.cholesky_inplace(cin_lower, False)
1827

1928
print(cin_upper)
2029
print(cin_lower)
2130

22-
print("Running Cholesky Out of place\n")
31+
print("\nRunning Cholesky Out of place\n")
2332

24-
out_upper = af.cholesky(inn, True)
25-
out_lower = af.cholesky(inn, False)
26-
27-
# Do we want to print the array like above? If yes this is correct.
28-
print(out_upper[0])
29-
print(out_lower[0])
33+
out_upper, upper_success = af.cholesky(arr_in, True)
34+
out_lower, lower_success = af.cholesky(arr_in, False)
3035

36+
if upper_success == 0:
37+
print(out_upper)
38+
if lower_success == 0:
39+
print(out_lower)
3140

3241
except Exception as e:
33-
print('Error: ',str(e))
42+
print('Error: ', str(e))
3443

3544
if __name__ == '__main__':
3645
main()

examples/lin_algebra/lu.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
#!/usr/bin/env python
2+
#######################################################
3+
# Copyright (c) 2022, ArrayFire
4+
# All rights reserved.
5+
#
6+
# This file is distributed under 3-clause BSD license.
7+
# The complete license agreement can be obtained at:
8+
# http://arrayfire.com/licenses/BSD-3-Clause
9+
########################################################
10+
211
import arrayfire as af
12+
313
def main():
414
try:
5-
device = 0
6-
#af.setDevice(device)
715
af.info()
816

9-
inn = af.randu(5,8)
10-
print(inn)
11-
12-
lin = inn
17+
in_array = af.randu(5,8)
1318

1419
print("Running LU InPlace\n")
15-
# Ask if this is correct.
16-
pivot = af.lu_inplace(lin)
17-
print(lin)
20+
pivot = af.lu_inplace(in_array)
21+
print(in_array)
1822
print(pivot)
1923

2024
print("Running LU with Upper Lower Factorization\n")
21-
lower, upper, pivot = af.lu(inn)
25+
lower, upper, pivot = af.lu(in_array)
2226
print(lower)
2327
print(upper)
2428
print(pivot)
29+
2530
except Exception as e:
2631
print('Error: ', str(e))
2732

examples/lin_algebra/qr.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
#!/usr/bin/env python
2+
#######################################################
3+
# Copyright (c) 2022, ArrayFire
4+
# All rights reserved.
5+
#
6+
# This file is distributed under 3-clause BSD license.
7+
# The complete license agreement can be obtained at:
8+
# http://arrayfire.com/licenses/BSD-3-Clause
9+
########################################################
10+
211
import arrayfire as af
12+
313
def main():
414
try:
5-
#Skip device=argc....
6-
device = 0
715
af.info()
16+
in_array = af.randu(5,8)
817

918
print("Running QR InPlace\n")
10-
inn = af.randu(5,8)
11-
print(inn)
19+
q_in = in_array.copy()
20+
print(q_in)
1221

13-
qin = inn
14-
tau = af.qr_inplace(qin)
22+
tau = af.qr_inplace(q_in)
1523

16-
print(qin)
24+
print(q_in)
1725
print(tau)
1826

1927
print("Running QR with Q and R factorization\n")
20-
q,r,tau = af.qr(inn)
28+
q, r, tau = af.qr(in_array)
2129

2230
print(q)
2331
print(r)
2432
print(tau)
2533

2634
except Exception as e:
27-
print("Error: ",str(e))
28-
29-
35+
print("Error: ", str(e))
3036

3137
if __name__ == '__main__':
3238
main()

0 commit comments

Comments
 (0)