|
| 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 | + |
1 | 11 | import arrayfire as af
|
2 | 12 |
|
3 | 13 | def main():
|
4 | 14 | try:
|
5 | | - device = 0 |
6 | 15 | af.info()
|
7 | | - |
| 16 | + |
8 | 17 | 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 |
11 | 20 |
|
12 | 21 | 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 | + |
16 | 25 | af.cholesky_inplace(cin_upper, True)
|
17 | 26 | af.cholesky_inplace(cin_lower, False)
|
18 | 27 |
|
19 | 28 | print(cin_upper)
|
20 | 29 | print(cin_lower)
|
21 | 30 |
|
22 | | - print("Running Cholesky Out of place\n") |
| 31 | + print("\nRunning Cholesky Out of place\n") |
23 | 32 |
|
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) |
30 | 35 |
|
| 36 | + if upper_success == 0: |
| 37 | + print(out_upper) |
| 38 | + if lower_success == 0: |
| 39 | + print(out_lower) |
31 | 40 |
|
32 | 41 | except Exception as e:
|
33 | | - print('Error: ',str(e)) |
| 42 | + print('Error: ',str(e)) |
34 | 43 |
|
35 | 44 | if __name__ == '__main__':
|
36 | 45 | main()
|
0 commit comments