1 //=================================================================================================
2 /*!
3 // \file blaze/math/dense/SVD.h
4 // \brief Header file for the dense matrix singular value decomposition (SVD)
5 //
6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 // This file is part of the Blaze library. You can redistribute it and/or modify it under
9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 // forms, with or without modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
16 // of conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // 3. Neither the names of the Blaze development group nor the names of its contributors
19 // may be used to endorse or promote products derived from this software without specific
20 // prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 */
33 //=================================================================================================
34
35 #ifndef _BLAZE_MATH_DENSE_SVD_H_
36 #define _BLAZE_MATH_DENSE_SVD_H_
37
38
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42
43 #include <blaze/math/constraints/Adaptor.h>
44 #include <blaze/math/constraints/BLASCompatible.h>
45 #include <blaze/math/constraints/Computation.h>
46 #include <blaze/math/constraints/MutableDataAccess.h>
47 #include <blaze/math/expressions/DenseMatrix.h>
48 #include <blaze/math/expressions/DenseVector.h>
49 #include <blaze/math/lapack/gesdd.h>
50 #include <blaze/math/lapack/gesvdx.h>
51 #include <blaze/math/typetraits/IsContiguous.h>
52 #include <blaze/math/typetraits/RemoveAdaptor.h>
53 #include <blaze/util/mpl/If.h>
54
55
56 namespace blaze {
57
58 //=================================================================================================
59 //
60 // SINGULAR VALUE DECOMPOSITION FUNCTIONS
61 //
62 //=================================================================================================
63
64 //*************************************************************************************************
65 /*!\name Singular value decomposition functions */
66 //@{
67 template< typename MT, bool SO, typename VT, bool TF >
68 inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s );
69
70 template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3 >
71 inline void svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
72 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V );
73
74 template< typename MT, bool SO, typename VT, bool TF, typename ST >
75 inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp );
76
77 template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3, typename ST >
78 inline size_t svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
79 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, ST low, ST upp );
80 //@}
81 //*************************************************************************************************
82
83
84 //*************************************************************************************************
85 /*!\brief Singular value decomposition (SVD) of the given dense general matrix.
86 // \ingroup dense_matrix
87 //
88 // \param A The given general matrix.
89 // \param s The resulting vector of singular values.
90 // \return void
91 // \exception std::invalid_argument Size of fixed size vector does not match.
92 // \exception std::runtime_error Singular value decomposition failed.
93 //
94 // This function performs the singular value decomposition of a general \a m-by-\a n matrix.
95 // The resulting min(\a m,\a n) singular values are stored in the given vector \a s, which is
96 // resized to the correct size (if possible and necessary).
97 //
98 // The function fails if ...
99 //
100 // - ... the given vector \a s is a fixed size vector and the size doesn't match;
101 // - ... the singular value decomposition fails.
102 //
103 // In all failure cases an exception is thrown.
104 //
105 // Examples:
106
107 \code
108 using blaze::DynamicMatrix;
109 using blaze::DynamicVector;
110 using blaze::rowMajor;
111 using blaze::columnVector;
112
113 DynamicMatrix<double,rowMajor> A( 5UL, 8UL ); // The general matrix A
114 // ... Initialization
115
116 DynamicVector<double,columnVector> s; // The vector for the singular values
117
118 svd( A, s );
119 \endcode
120
121 // \note This function only works for matrices with \c float, \c double, \c complex<float>, or
122 // \c complex<double> element type. The attempt to call the function with matrices of any other
123 // element type results in a compile time error!
124 //
125 // \note This function can only be used if a fitting LAPACK library is available and linked to
126 // the executable. Otherwise a call to this function will result in a linker error.
127 //
128 // \note Further options for computing singular values and singular vectors are available via the
129 // gesvd(), gesdd(), and gesvdx() functions.
130 */
131 template< typename MT // Type of the matrix A
132 , bool SO // Storage order of the matrix A
133 , typename VT // Type of the vector s
134 , bool TF > // Transpose flag of the vector s
svd(const DenseMatrix<MT,SO> & A,DenseVector<VT,TF> & s)135 inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
136 {
137 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT );
138 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT> );
139
140 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( VT );
141 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( VT );
142 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<VT> );
143
144 using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
145 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
146
147 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( ATmp );
148 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( ATmp );
149 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( ATmp );
150 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
151
152 ATmp Atmp( *A );
153 STmp stmp( *s );
154
155 gesdd( Atmp, stmp );
156
157 if( !IsContiguous_v<VT> ) {
158 (*s) = stmp;
159 }
160 }
161 //*************************************************************************************************
162
163
164 //*************************************************************************************************
165 /*!\brief Singular value decomposition (SVD) of the given dense general matrix.
166 // \ingroup dense_matrix
167 //
168 // \param A The given general matrix.
169 // \param U The resulting matrix of left singular vectors.
170 // \param s The resulting vector of singular values.
171 // \param V The resulting matrix of right singular vectors.
172 // \return void
173 // \exception std::invalid_argument Dimensions of fixed size matrix U do not match.
174 // \exception std::invalid_argument Size of fixed size vector does not match.
175 // \exception std::invalid_argument Dimensions of fixed size matrix V do not match.
176 // \exception std::runtime_error Singular value decomposition failed.
177 //
178 // This function performs the singular value decomposition of a general \a m-by-\a n matrix. The
179 // resulting min(\a m,\a n) singular values are stored in the given vector \a s, the resulting
180 // left singular vectors are stored in the given matrix \a U, and the resulting right singular
181 // vectors are stored in the given matrix \a V. \a s, \a U and \a V are resized to the correct
182 // dimensions (if possible and necessary).
183 //
184 // The function fails if ...
185 //
186 // - ... the given matrix \a U is a fixed size matrix and the dimensions don't match;
187 // - ... the given vector \a s is a fixed size vector and the size doesn't match;
188 // - ... the given matrix \a V is a fixed size matrix and the dimensions don't match;
189 // - ... the singular value decomposition fails.
190 //
191 // In all failure cases an exception is thrown.
192 //
193 // Examples:
194
195 \code
196 using blaze::DynamicMatrix;
197 using blaze::DynamicVector;
198 using blaze::rowMajor;
199 using blaze::columnVector;
200
201 DynamicMatrix<double,rowMajor> A( 5UL, 8UL ); // The general matrix A
202 // ... Initialization
203
204 DynamicMatrix<double,rowMajor> U; // The matrix for the left singular vectors
205 DynamicVector<double,columnVector> s; // The vector for the singular values
206 DynamicMatrix<double,rowMajor> V; // The matrix for the right singular vectors
207
208 svd( A, U, s, V );
209 \endcode
210
211 // \note This function only works for matrices with \c float, \c double, \c complex<float>, or
212 // \c complex<double> element type. The attempt to call the function with matrices of any other
213 // element type results in a compile time error!
214 //
215 // \note This function can only be used if a fitting LAPACK library is available and linked to
216 // the executable. Otherwise a call to this function will result in a linker error.
217 //
218 // \note Further options for computing singular values and singular vectors are available via the
219 // gesvd(), gesdd(), and gesvdx() functions.
220 */
221 template< typename MT1 // Type of the matrix A
222 , bool SO // Storage order of all matrices
223 , typename VT // Type of the vector s
224 , bool TF // Transpose flag of the vector s
225 , typename MT2 // Type of the matrix U
226 , typename MT3 > // Type of the matrix V
svd(const DenseMatrix<MT1,SO> & A,DenseMatrix<MT2,SO> & U,DenseVector<VT,TF> & s,DenseMatrix<MT3,SO> & V)227 inline void svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
228 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V )
229 {
230 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT1 );
231 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT1> );
232
233 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( MT2 );
234 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT2 );
235 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( MT2 );
236 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT2> );
237
238 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( VT );
239 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( VT );
240 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<VT> );
241
242 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( MT3 );
243 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT3 );
244 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( MT3 );
245 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT3> );
246
247 using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
248 using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
249 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
250 using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
251
252 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( ATmp );
253 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( ATmp );
254 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( ATmp );
255 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
256
257 ATmp Atmp( *A );
258 UTmp Utmp( *U );
259 STmp stmp( *s );
260 VTmp Vtmp( *V );
261
262 gesdd( Atmp, Utmp, stmp, Vtmp, 'S' );
263
264 if( !IsContiguous_v<MT2> ) {
265 (*U) = Utmp;
266 }
267
268 if( !IsContiguous_v<VT> ) {
269 (*s) = stmp;
270 }
271
272 if( !IsContiguous_v<MT3> ) {
273 (*V) = Vtmp;
274 }
275 }
276 //*************************************************************************************************
277
278
279 //*************************************************************************************************
280 /*!\brief Singular value decomposition (SVD) of the given dense general matrix.
281 // \ingroup dense_matrix
282 //
283 // \param A The given general matrix.
284 // \param s The resulting vector of singular values.
285 // \param low The lower bound of the interval to be searched for singular values.
286 // \param upp The upper bound of the interval to be searched for singular values.
287 // \return The total number of singular values found.
288 // \exception std::invalid_argument Size of fixed size vector does not match.
289 // \exception std::invalid_argument Invalid value range provided.
290 // \exception std::invalid_argument Invalid index range provided.
291 // \exception std::runtime_error Singular value decomposition failed.
292 //
293 // This function computes a specified number of singular values of the given general \a m-by-\a n
294 // matrix. The number of singular values to be computed is specified by the lower bound \a low and
295 // the upper bound \a upp, which either form an integral or a floating point range.
296 //
297 // In case \a low and \a upp are of integral type, the function computes all singular values in
298 // the index range \f$[low..upp]\f$. The \a num resulting real and non-negative singular values
299 // are stored in descending order in the given vector \a s, which is either resized (if possible)
300 // or expected to be a \a num-dimensional vector.
301 //
302 // In case \a low and \a upp are of floating point type, the function computes all singular values
303 // in the half-open interval \f$(low..upp]\f$. The resulting real and non-negative singular values
304 // are stored in descending order in the given vector \a s, which is either resized (if possible)
305 // or expected to be a min(\a m,\a n)-dimensional vector.
306 //
307 // The function fails if ...
308 //
309 // - ... the given vector \a s is a fixed size vector and the size doesn't match;
310 // - ... the given scalar values don't form a proper range;
311 // - ... the singular value decomposition fails.
312 //
313 // In all failure cases an exception is thrown.
314 //
315 // Examples:
316
317 \code
318 using blaze::DynamicMatrix;
319 using blaze::DynamicVector;
320 using blaze::rowMajor;
321 using blaze::columnVector;
322
323 DynamicMatrix<double,rowMajor> A( 5UL, 8UL ); // The general matrix A
324 // ... Initialization
325
326 DynamicVector<double,columnVector> s; // The vector for the singular values
327
328 svd( A, s, 0, 2 );
329 \endcode
330
331 // \note This function only works for matrices with \c float, \c double, \c complex<float>, or
332 // \c complex<double> element type. The attempt to call the function with matrices of any other
333 // element type results in a compile time error!
334 //
335 // \note This function can only be used if a fitting LAPACK library is available and linked to
336 // the executable. Otherwise a call to this function will result in a linker error.
337 //
338 // \note Further options for computing singular values and singular vectors are available via the
339 // gesvd(), gesdd(), and gesvdx() functions.
340 */
341 template< typename MT // Type of the matrix A
342 , bool SO // Storage order of the matrix A
343 , typename VT // Type of the vector s
344 , bool TF // Transpose flag of the vector s
345 , typename ST > // Type of the scalar boundary values
svd(const DenseMatrix<MT,SO> & A,DenseVector<VT,TF> & s,ST low,ST upp)346 inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp )
347 {
348 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT );
349 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT> );
350
351 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( VT );
352 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( VT );
353 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<VT> );
354
355 BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE( ST );
356
357 using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
358 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
359
360 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( ATmp );
361 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( ATmp );
362 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( ATmp );
363 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
364
365 ATmp Atmp( *A );
366 STmp stmp( *s );
367
368 const auto num = gesvdx( Atmp, stmp, low, upp );
369
370 if( !IsContiguous_v<VT> ) {
371 (*s) = stmp;
372 }
373
374 return num;
375 }
376 //*************************************************************************************************
377
378
379 //*************************************************************************************************
380 /*!\brief Singular value decomposition (SVD) of the given dense general matrix.
381 // \ingroup dense_matrix
382 //
383 // \param A The given general matrix.
384 // \param U The resulting matrix of left singular vectors.
385 // \param s The resulting vector of singular values.
386 // \param V The resulting matrix of right singular vectors.
387 // \param low The lower bound of the interval to be searched for singular values.
388 // \param upp The upper bound of the interval to be searched for singular values.
389 // \return The total number of singular values found.
390 // \exception std::invalid_argument Dimensions of fixed size matrix U do not match.
391 // \exception std::invalid_argument Size of fixed size vector does not match.
392 // \exception std::invalid_argument Dimensions of fixed size matrix V do not match.
393 // \exception std::invalid_argument Invalid value range provided.
394 // \exception std::invalid_argument Invalid index range provided.
395 // \exception std::runtime_error Singular value decomposition failed.
396 //
397 // This function computes a specified number of singular values and singular vectors of the given
398 // general \a m-by-\a n matrix. The number of singular values and vectors to be computed is
399 // specified by the lower bound \a low and the upper bound \a upp, which either form an integral
400 // or a floating point range.
401 //
402 // In case \a low and \a upp form are of integral type, the function computes all singular values
403 // in the index range \f$[low..upp]\f$. The \a num resulting real and non-negative singular values
404 // are stored in descending order in the given vector \a s, which is either resized (if possible)
405 // or expected to be a \a num-dimensional vector. The resulting left singular vectors are stored
406 // in the given matrix \a U, which is either resized (if possible) or expected to be a
407 // \a m-by-\a num matrix. The resulting right singular vectors are stored in the given matrix \a V,
408 // which is either resized (if possible) or expected to be a \a num-by-\a n matrix.
409 //
410 // In case \a low and \a upp are of floating point type, the function computes all singular values
411 // in the half-open interval \f$(low..upp]\f$. The resulting real and non-negative singular values
412 // are stored in descending order in the given vector \a s, which is either resized (if possible)
413 // or expected to be a min(\a m,\a n)-dimensional vector. The resulting left singular vectors are
414 // stored in the given matrix \a U, which is either resized (if possible) or expected to be a
415 // \a m-by-min(\a m,\a n) matrix. The resulting right singular vectors are stored in the given
416 // matrix \a V, which is either resized (if possible) or expected to be a \a min(\a m,\a n)-by-\a n
417 // matrix.
418 //
419 // The function fails if ...
420 //
421 // - ... the given matrix \a U is a fixed size matrix and the dimensions don't match;
422 // - ... the given vector \a s is a fixed size vector and the size doesn't match;
423 // - ... the given matrix \a V is a fixed size matrix and the dimensions don't match;
424 // - ... the given scalar values don't form a proper range;
425 // - ... the singular value decomposition fails.
426 //
427 // In all failure cases an exception is thrown.
428 //
429 // Examples:
430
431 \code
432 using blaze::DynamicMatrix;
433 using blaze::DynamicVector;
434 using blaze::rowMajor;
435 using blaze::columnVector;
436
437 DynamicMatrix<double,rowMajor> A( 5UL, 8UL ); // The general matrix A
438 // ... Initialization
439
440 DynamicMatrix<double,rowMajor> U; // The matrix for the left singular vectors
441 DynamicVector<double,columnVector> s; // The vector for the singular values
442 DynamicMatrix<double,rowMajor> V; // The matrix for the right singular vectors
443
444 svd( A, U, s, V, 0, 2 );
445 \endcode
446
447 // \note This function only works for matrices with \c float, \c double, \c complex<float>, or
448 // \c complex<double> element type. The attempt to call the function with matrices of any other
449 // element type results in a compile time error!
450 //
451 // \note This function can only be used if a fitting LAPACK library is available and linked to
452 // the executable. Otherwise a call to this function will result in a linker error.
453 //
454 // \note Further options for computing singular values and singular vectors are available via the
455 // gesvd(), gesdd(), and gesvdx() functions.
456 */
457 template< typename MT1 // Type of the matrix A
458 , bool SO // Storage order of all matrices
459 , typename VT // Type of the vector s
460 , bool TF // Transpose flag of the vector s
461 , typename MT2 // Type of the matrix U
462 , typename MT3 // Type of the matrix V
463 , typename ST > // Type of the scalar boundary values
svd(const DenseMatrix<MT1,SO> & A,DenseMatrix<MT2,SO> & U,DenseVector<VT,TF> & s,DenseMatrix<MT3,SO> & V,ST low,ST upp)464 inline size_t svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
465 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, ST low, ST upp )
466 {
467 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT1 );
468 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT1> );
469
470 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( MT2 );
471 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT2 );
472 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( MT2 );
473 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT2> );
474
475 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( VT );
476 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( VT );
477 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<VT> );
478
479 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( MT3 );
480 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( MT3 );
481 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( MT3 );
482 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<MT3> );
483
484 BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE( ST );
485
486 using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
487 using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
488 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
489 using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
490
491 BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE( ATmp );
492 BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE( ATmp );
493 BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS( ATmp );
494 BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
495
496 ATmp Atmp( *A );
497 UTmp Utmp( *U );
498 STmp stmp( *s );
499 VTmp Vtmp( *V );
500
501 const auto num = gesvdx( Atmp, Utmp, stmp, Vtmp, low, upp );
502
503 if( !IsContiguous_v<MT2> ) {
504 (*U) = Utmp;
505 }
506
507 if( !IsContiguous_v<VT> ) {
508 (*s) = stmp;
509 }
510
511 if( !IsContiguous_v<MT3> ) {
512 (*V) = Vtmp;
513 }
514
515 return num;
516 }
517 //*************************************************************************************************
518
519 } // namespace blaze
520
521 #endif
522