7 #ifndef JADE_LAPACK_HPP__
8 #define JADE_LAPACK_HPP__
10 #include "jade.assert.hpp"
17 template <
typename TValue>
24 #ifndef LAPACK_ROW_MAJOR
25 #define LAPACK_ROW_MAJOR 101
28 #ifndef LAPACK_COL_MAJOR
29 #define LAPACK_COL_MAJOR 102
95 col_storage() =
delete;
96 col_storage(
const col_storage &) =
delete;
97 col_storage & operator = (
const col_storage &) =
delete;
106 : _data_ptr (data_ptr)
107 , _stride_ptr (stride_ptr)
108 , _data_0 (*data_ptr)
109 , _stride_0 (size_t(*stride_ptr))
110 , _rows (size_t(rows))
111 , _cols (size_t(cols))
113 assert(
nullptr != data_ptr);
114 assert(
nullptr != *data_ptr);
115 assert(
nullptr != stride_ptr);
116 assert(*stride_ptr > 0);
120 _temp.resize(_rows * _cols);
121 auto t = _temp.data();
123 for (
size_t c = 0; c < _cols; c++)
124 for (
size_t r = 0; r < _rows; r++)
125 *t++ = _data_0[r * _stride_0 + c];
127 *data_ptr = _temp.data();
128 *stride_ptr = int(_rows);
134 *_data_ptr = _data_0;
135 *_stride_ptr = int(_stride_0);
137 auto t = _temp.data();
138 for (
size_t c = 0; c < _cols; c++)
139 for (
size_t r = 0; r < _rows; r++)
140 _data_0[r * _stride_0 + c] = *t++;
150 std::vector<value_type> _temp;
154 static std::unique_ptr<col_storage> init_storage(
163 std::unique_ptr<col_storage> ptr;
167 ptr.reset(
new col_storage(
178 #ifndef DOXYGEN_IGNORE
192 assert(a !=
nullptr);
193 assert(b !=
nullptr);
195 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
196 const auto a_storage = init_storage(layout, &a, &lda, n, n);
197 const auto b_storage = init_storage(layout, &b, &ldb, n, nrhs);
199 ::dgesv_(&n, &nrhs, a, &lda, ipiv, b, &ldb, &info);
201 #elif defined(JADE_USE_NETLIB_PACKAGES)
202 return LAPACKE_dgesv(layout, n, nrhs, a, lda, ipiv, b, ldb);
204 #error Unsupported build environment
220 assert(a !=
nullptr);
221 assert(b !=
nullptr);
223 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
224 const auto a_storage = init_storage(layout, &a, &lda, n, n);
225 const auto b_storage = init_storage(layout, &b, &ldb, n, nrhs);
227 (void)::sgesv_(&n, &nrhs, a, &lda, ipiv, b, &ldb, &info);
229 #elif defined(JADE_USE_NETLIB_PACKAGES)
230 return LAPACKE_sgesv(layout, n, nrhs, a, lda, ipiv, b, ldb);
232 #error Unsupported build environment
245 assert(a !=
nullptr);
247 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
248 const auto storage = init_storage(layout, &a, &lda, n, n);
250 (void)::dpotrf_(&uplo, &n, a, &lda, &info);
252 #elif defined(JADE_USE_NETLIB_PACKAGES)
253 return LAPACKE_dpotrf(layout, uplo, n, a, lda);
255 #error Unsupported build environment
268 assert(a !=
nullptr);
270 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
271 const auto storage = init_storage(layout, &a, &lda, n, n);
273 (void)::spotrf_(&uplo, &n, a, &lda, &info);
275 #elif defined(JADE_USE_NETLIB_PACKAGES)
276 return LAPACKE_spotrf(layout, uplo, n, a, lda);
278 #error Unsupported build environment
291 assert(a !=
nullptr);
293 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
294 const auto storage = init_storage(layout, &a, &lda, n, n);
296 (void)::dpotri_(&uplo, &n, a, &lda, &info);
298 #elif defined(JADE_USE_NETLIB_PACKAGES)
299 return LAPACKE_dpotri(layout, uplo, n, a, lda);
301 #error Unsupported build environment
314 assert(a !=
nullptr);
316 #if defined(JADE_USE_ACCELERATE_FRAMEWORK)
317 const auto storage = init_storage(layout, &a, &lda, n, n);
319 (void)::spotri_(&uplo, &n, a, &lda, &info);
321 #elif defined(JADE_USE_NETLIB_PACKAGES)
322 return LAPACKE_spotri(layout, uplo, n, a, lda);
324 #error Unsupported build environment
328 #endif // DOXYGEN_IGNORE
331 #endif // JADE_LAPACK_HPP__