Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0692510

Browse files
tuckeryazdanisyurkevi
authored andcommitted
adds linear algebra examples
1 parent 96fa976 commit 0692510

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

‎examples/lin_algebra/cholesky.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import arrayfire as af
2+
3+
def main():
4+
try:
5+
device = 0
6+
af.info()
7+
8+
n = 5
9+
t = af.randu(n,n)
10+
inn = af.matmulNT(t,t) + af.identity(n,n)*n
11+
12+
print("Running Cholesky InPlace\n")
13+
cin_upper = inn
14+
cin_lower = inn
15+
16+
af.cholesky_inplace(cin_upper, True)
17+
af.cholesky_inplace(cin_lower, False)
18+
19+
print(cin_upper)
20+
print(cin_lower)
21+
22+
print("Running Cholesky Out of place\n")
23+
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])
30+
31+
32+
except Exception as e:
33+
print('Error: ',str(e))
34+
35+
if __name__ == '__main__':
36+
main()

‎examples/lin_algebra/lu.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
import arrayfire as af
3+
def main():
4+
try:
5+
device = 0
6+
#af.setDevice(device)
7+
af.info()
8+
9+
inn = af.randu(5,8)
10+
print(inn)
11+
12+
lin = inn
13+
14+
print("Running LU InPlace\n")
15+
# Ask if this is correct.
16+
pivot = af.lu_inplace(lin)
17+
print(lin)
18+
print(pivot)
19+
20+
print("Running LU with Upper Lower Factorization\n")
21+
lower, upper, pivot = af.lu(inn)
22+
print(lower)
23+
print(upper)
24+
print(pivot)
25+
except Exception as e:
26+
print('Error: ', str(e))
27+
28+
if __name__ == '__main__':
29+
main()
30+

‎examples/lin_algebra/qr.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
import arrayfire as af
3+
def main():
4+
try:
5+
#Skip device=argc....
6+
device = 0
7+
af.info()
8+
9+
print("Running QR InPlace\n")
10+
inn = af.randu(5,8)
11+
print(inn)
12+
13+
qin = inn
14+
tau = af.qr_inplace(qin)
15+
16+
print(qin)
17+
print(tau)
18+
19+
print("Running QR with Q and R factorization\n")
20+
q,r,tau = af.qr(inn)
21+
22+
print(q)
23+
print(r)
24+
print(tau)
25+
26+
except Exception as e:
27+
print("Error: ",str(e))
28+
29+
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /