lin_algebra/lu.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);
array in = randu(5, 8);
af_print(in);
array lin = in.copy();
printf("Running LU InPlace\n");
array pivot;
luInPlace(pivot, lin);
af_print(lin);
af_print(pivot);
printf("Running LU with Upper Lower Factorization\n");
lu(lower, upper, pivot, in);
af_print(pivot);
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
af::lower
AFAPI array lower(const array &in, bool is_unit_diag=false)
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::randu
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
af::luInPlace
AFAPI void luInPlace(array &pivot, array &in, const bool is_lapack_piv=true)
C++ Interface for in place LU decomposition.
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::lu
AFAPI void lu(array &out, array &pivot, const array &in, const bool is_lapack_piv=true)
C++ Interface for LU decomposition in packed format.
arrayfire.h
af::upper
AFAPI array upper(const array &in, bool is_unit_diag=false)
af::array::copy
array copy() const
Perform deep copy of the array.
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60