Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions examples/lin_algebra/cholesky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
#######################################################
# Copyright (c) 2024, 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


def main():
try:
af.info()

n = 5
t = af.randu((n, n))
arr_in = af.matmul(t, t, rhs_opts=af.MatProp.TRANS) + af.identity((n, n)) * n

print("Running Cholesky InPlace\n")
cin_upper = arr_in.copy()
cin_lower = arr_in.copy()

af.cholesky(cin_upper, True)
af.cholesky(cin_lower, False)

print(cin_upper)
print(cin_lower)

print("\nRunning Cholesky Out of place\n")

out_upper, upper_success = af.cholesky(arr_in, True)
out_lower, lower_success = af.cholesky(arr_in, False)

if upper_success == 0:
print(out_upper)
if lower_success == 0:
print(out_lower)

except Exception as e:
print("Error: ", str(e))


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions examples/lin_algebra/lu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
#######################################################
# Copyright (c) 2024, 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


def main():
try:
af.info()

in_array = af.randu((5, 8))

print("Running LU InPlace\n")
pivot = af.lu(in_array, inplace=True)
print(in_array)
print(pivot)

print("Running LU with Upper Lower Factorization\n")
lower, upper, pivot = af.lu(in_array)
print(lower)
print(upper)
print(pivot)

except Exception as e:
print("Error: ", str(e))


if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions examples/lin_algebra/qr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
#######################################################
# Copyright (c) 2024, 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


def main():
try:
af.info()
in_array = af.randu((5, 8))

print("Running QR InPlace\n")
q_in = in_array.copy()
print(q_in)

tau = af.qr(q_in, inplace=True)

print(q_in)
print(tau)

print("Running QR with Q and R factorization\n")
q, r, tau = af.qr(in_array)

print(q)
print(r)
print(tau)

except Exception as e:
print("Error: ", str(e))


if __name__ == "__main__":
main()