forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlapack.py
More file actions
92 lines (63 loc) · 1.86 KB
/
lapack.py
File metadata and controls
92 lines (63 loc) · 1.86 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
from . import _util
def simple_lapack(verbose=False):
display_func = _util.display_func(verbose)
print_func = _util.print_func(verbose)
a = af.randu(5, 5)
l, u, p = af.lu(a)
display_func(l)
display_func(u)
display_func(p)
p = af.lu_inplace(a, "full")
display_func(a)
display_func(p)
a = af.randu(5, 3)
q, r, t = af.qr(a)
display_func(q)
display_func(r)
display_func(t)
af.qr_inplace(a)
display_func(a)
a = af.randu(5, 5)
a = af.matmulTN(a, a.copy()) + 10 * af.identity(5, 5)
R, info = af.cholesky(a)
display_func(R)
print_func(info)
af.cholesky_inplace(a)
display_func(a)
a = af.randu(5, 5)
ai = af.inverse(a)
display_func(a)
display_func(ai)
ai = af.pinverse(a)
display_func(ai)
x0 = af.randu(5, 3)
b = af.matmul(a, x0)
x1 = af.solve(a, b)
display_func(x0)
display_func(x1)
p = af.lu_inplace(a)
x2 = af.solve_lu(a, p, b)
display_func(x2)
print_func(af.rank(a))
print_func(af.det(a))
print_func(af.norm(a, af.NORM.EUCLID))
print_func(af.norm(a, af.NORM.MATRIX_1))
print_func(af.norm(a, af.NORM.MATRIX_INF))
print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1))
a = af.randu(10, 10)
display_func(a)
u, s, vt = af.svd(a)
display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
u, s, vt = af.svd_inplace(a)
display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
_util.tests["lapack"] = simple_lapack