Skip to content

Commit 4f209e8

Browse files
committed
Out of place cholesky now returns triangular matrix for all backends
1 parent 5405f79 commit 4f209e8

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/api/cpp/lapack.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ namespace af
6363

6464
array cholesky(const array &in, int *info, const bool is_upper)
6565
{
66-
array out = in.copy();
67-
AF_THROW(af_cholesky_inplace(info, out.get(), is_upper));
68-
return out;
66+
af_array out;
67+
AF_THROW(af_cholesky(&out, info, in.get(), is_upper));
68+
return array(out);
6969
}
7070

7171
void choleskyInplace(array &in, int *info, const bool is_upper)

src/backend/cpu/cholesky.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <iostream>
1818
#include <cassert>
1919
#include <err_cpu.hpp>
20+
#include <triangle.hpp>
2021

2122
#include <lapack_helper.hpp>
2223

@@ -47,6 +48,10 @@ Array<T> cholesky(int *info, const Array<T> &in, const bool is_upper)
4748
{
4849
Array<T> out = copyArray<T>(in);
4950
*info = cholesky_inplace(out, is_upper);
51+
52+
if (is_upper) triangle<T, true >(out, out);
53+
else triangle<T, false>(out, out);
54+
5055
return out;
5156
}
5257

src/backend/cuda/cholesky.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <iostream>
1919
#include <memory.hpp>
2020
#include <copy.hpp>
21+
#include <triangle.hpp>
2122

2223
#include <math.hpp>
2324
#include <err_common.hpp>
@@ -94,6 +95,10 @@ Array<T> cholesky(int *info, const Array<T> &in, const bool is_upper)
9495

9596
Array<T> out = copyArray<T>(in);
9697
*info = cholesky_inplace(out, is_upper);
98+
99+
if (is_upper) triangle<T, true >(out, out);
100+
else triangle<T, false>(out, out);
101+
97102
return out;
98103
}
99104

src/backend/opencl/cholesky.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <magma/magma.h>
1414
#include <blas.hpp>
1515
#include <err_opencl.hpp>
16+
#include <triangle.hpp>
1617

1718
#if defined(WITH_OPENCL_LINEAR_ALGEBRA)
1819

@@ -48,6 +49,10 @@ Array<T> cholesky(int *info, const Array<T> &in, const bool is_upper)
4849

4950
Array<T> out = copyArray<T>(in);
5051
*info = cholesky_inplace(out, is_upper);
52+
53+
if (is_upper) triangle<T, true >(out, out);
54+
else triangle<T, false>(out, out);
55+
5156
return out;
5257

5358
} catch (cl::Error &err) {

0 commit comments

Comments
 (0)