lin_algebra/cholesky.cpp
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* https://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <arrayfire.h>
#include <cstdio>
#include <cstdlib>
using namespace af;
int main(int argc, char* argv[]) {
try {
// Select a device and display arrayfire info
int device = argc > 1 ? atoi(argv[1]) : 0;
af::setDevice(device);
int n = 5;
array t = randu(n, n);
array in = matmulNT(t, t) + identity(n, n) * n;
af_print(in);
printf("Running Cholesky InPlace\n");
array cin_upper = in.copy();
array cin_lower = in.copy();
choleskyInPlace(cin_upper, true);
choleskyInPlace(cin_lower, false);
af_print(cin_upper);
af_print(cin_lower);
printf("Running Cholesky Out of place\n");
array out_upper;
array out_lower;
cholesky(out_upper, in, true);
cholesky(out_lower, in, false);
af_print(out_upper);
af_print(out_lower);
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
af::cholesky
AFAPI int cholesky(array &out, const array &in, const bool is_upper=true)
C++ Interface for cholesky decomposition.
af::info
AFAPI void info()
af::setDevice
AFAPI void setDevice(const int device)
Sets the current device.
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:15
af_print
#define af_print(...)
Definition: util.h:148
af::matmulNT
AFAPI array matmulNT(const array &lhs, const array &rhs)
Matrix multiply of two arrays.
af::randu
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::choleskyInPlace
AFAPI int choleskyInPlace(array &in, const bool is_upper=true)
C++ Interface for in place cholesky decomposition.
arrayfire.h
af::array::copy
array copy() const
Perform deep copy of the array.
af::identity
AFAPI array identity(const dim4 &dims, const dtype ty=f32)
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60