1 /*
2 
3     Copyright (C) 2014, The University of Texas at Austin
4 
5     This file is part of libflame and is available under the 3-Clause
6     BSD license, which can be found in the LICENSE file at the top-level
7     directory, or at http://opensource.org/licenses/BSD-3-Clause
8 
9 */
10 
11 #include "FLAME.h"
12 
13 
14 static unsigned int fla_error_checking_level = FLA_INTERNAL_ERROR_CHECKING_LEVEL;
15 
16 
17 
FLA_Check_error_level()18 unsigned int FLA_Check_error_level()
19 {
20   return fla_error_checking_level;
21 }
22 
FLA_Check_error_level_set(unsigned int new_level)23 unsigned int FLA_Check_error_level_set( unsigned int new_level )
24 {
25   FLA_Error    e_val;
26   unsigned int old_level;
27 
28   e_val = FLA_Check_valid_error_level( new_level );
29   FLA_Check_error_code( e_val );
30 
31   old_level = fla_error_checking_level;
32 
33   fla_error_checking_level = new_level;
34 
35   return old_level;
36 }
37 
FLA_Check_error_code_helper(int code,char * file,int line)38 FLA_Error FLA_Check_error_code_helper( int code, char* file, int line )
39 {
40   if ( code == FLA_SUCCESS )
41     return code;
42 
43   //if ( /* fatal error checking enabled */ )
44   if ( TRUE )
45   {
46     if ( FLA_ERROR_CODE_MAX <= code && code <= FLA_ERROR_CODE_MIN )
47     {
48       FLA_Print_message( FLA_Error_string_for_code( code ),
49                          file, line );
50       FLA_Abort();
51     }
52     else
53     {
54       FLA_Print_message( FLA_Error_string_for_code( FLA_UNDEFINED_ERROR_CODE ),
55                          file, line );
56       FLA_Abort();
57     }
58   }
59 
60   return code;
61 }
62 
FLA_Check_valid_side(FLA_Side side)63 FLA_Error FLA_Check_valid_side( FLA_Side side )
64 {
65   FLA_Error e_val = FLA_SUCCESS;
66 
67   if ( side != FLA_LEFT &&
68        side != FLA_RIGHT &&
69        side != FLA_TOP &&
70        side != FLA_BOTTOM )
71     e_val = FLA_INVALID_SIDE;
72 
73   return e_val;
74 }
75 
FLA_Check_valid_uplo(FLA_Uplo uplo)76 FLA_Error FLA_Check_valid_uplo( FLA_Uplo uplo )
77 {
78   FLA_Error e_val = FLA_SUCCESS;
79 
80   if ( uplo != FLA_LOWER_TRIANGULAR &&
81        uplo != FLA_UPPER_TRIANGULAR )
82     e_val = FLA_INVALID_UPLO;
83 
84   return e_val;
85 }
86 
FLA_Check_valid_trans(FLA_Trans trans)87 FLA_Error FLA_Check_valid_trans( FLA_Trans trans )
88 {
89   FLA_Error e_val = FLA_SUCCESS;
90 
91   if ( trans != FLA_NO_TRANSPOSE &&
92        trans != FLA_TRANSPOSE &&
93        trans != FLA_CONJ_TRANSPOSE &&
94        trans != FLA_CONJ_NO_TRANSPOSE )
95     e_val = FLA_INVALID_TRANS;
96 
97   return e_val;
98 }
99 
FLA_Check_valid_diag(FLA_Diag diag)100 FLA_Error FLA_Check_valid_diag( FLA_Diag diag )
101 {
102   FLA_Error e_val = FLA_SUCCESS;
103 
104   if ( diag != FLA_NONUNIT_DIAG &&
105        diag != FLA_UNIT_DIAG &&
106        diag != FLA_ZERO_DIAG )
107     e_val = FLA_INVALID_DIAG;
108 
109   return e_val;
110 }
111 
FLA_Check_valid_conj(FLA_Conj conj)112 FLA_Error FLA_Check_valid_conj( FLA_Conj conj )
113 {
114   FLA_Error e_val = FLA_SUCCESS;
115 
116   if ( conj != FLA_NO_CONJUGATE &&
117        conj != FLA_CONJUGATE )
118     e_val = FLA_INVALID_CONJ;
119 
120   return e_val;
121 }
122 
FLA_Check_valid_direct(FLA_Direct direct)123 FLA_Error FLA_Check_valid_direct( FLA_Direct direct )
124 {
125   FLA_Error e_val = FLA_SUCCESS;
126 
127   if ( direct != FLA_FORWARD &&
128        direct != FLA_BACKWARD )
129     e_val = FLA_INVALID_DIRECT;
130 
131   return e_val;
132 }
133 
FLA_Check_valid_storev(FLA_Store storev)134 FLA_Error FLA_Check_valid_storev( FLA_Store storev )
135 {
136   FLA_Error e_val = FLA_SUCCESS;
137 
138   if ( storev != FLA_COLUMNWISE &&
139        storev != FLA_ROWWISE )
140     e_val = FLA_INVALID_STOREV;
141 
142   return e_val;
143 }
144 
FLA_Check_valid_inverse(FLA_Inv inv)145 FLA_Error FLA_Check_valid_inverse( FLA_Inv inv )
146 {
147   FLA_Error e_val = FLA_SUCCESS;
148 
149   if ( inv != FLA_NO_INVERSE &&
150        inv != FLA_INVERSE )
151     e_val = FLA_INVALID_INVERSE;
152 
153   return e_val;
154 }
155 
FLA_Check_valid_datatype(FLA_Datatype datatype)156 FLA_Error FLA_Check_valid_datatype( FLA_Datatype datatype )
157 {
158   FLA_Error e_val = FLA_SUCCESS;
159 
160   if ( datatype != FLA_INT &&
161        datatype != FLA_FLOAT &&
162        datatype != FLA_DOUBLE &&
163        datatype != FLA_COMPLEX &&
164        datatype != FLA_DOUBLE_COMPLEX &&
165        datatype != FLA_CONSTANT )
166     e_val = FLA_INVALID_DATATYPE;
167 
168   return e_val;
169 }
170 
FLA_Check_valid_object_datatype(FLA_Obj A)171 FLA_Error FLA_Check_valid_object_datatype( FLA_Obj A )
172 {
173   FLA_Error    e_val;
174   FLA_Datatype datatype;
175 
176   datatype = FLA_Obj_datatype( A );
177 
178   e_val = FLA_Check_valid_datatype( datatype );
179 
180   return e_val;
181 }
182 
FLA_Check_floating_datatype(FLA_Datatype datatype)183 FLA_Error FLA_Check_floating_datatype( FLA_Datatype datatype )
184 {
185   FLA_Error e_val = FLA_SUCCESS;
186 
187   if ( datatype != FLA_CONSTANT &&
188        datatype != FLA_FLOAT &&
189        datatype != FLA_DOUBLE &&
190        datatype != FLA_COMPLEX &&
191        datatype != FLA_DOUBLE_COMPLEX )
192     e_val = FLA_INVALID_FLOATING_DATATYPE;
193 
194   return e_val;
195 }
196 
FLA_Check_int_datatype(FLA_Datatype datatype)197 FLA_Error FLA_Check_int_datatype( FLA_Datatype datatype )
198 {
199   FLA_Error e_val = FLA_SUCCESS;
200 
201   if ( datatype != FLA_CONSTANT &&
202        datatype != FLA_INT )
203     e_val = FLA_INVALID_INTEGER_DATATYPE;
204 
205   return e_val;
206 }
207 
FLA_Check_real_datatype(FLA_Datatype datatype)208 FLA_Error FLA_Check_real_datatype( FLA_Datatype datatype )
209 {
210   FLA_Error e_val = FLA_SUCCESS;
211 
212   if ( datatype != FLA_CONSTANT &&
213        datatype != FLA_FLOAT &&
214        datatype != FLA_DOUBLE )
215     e_val = FLA_INVALID_REAL_DATATYPE;
216 
217   return e_val;
218 }
219 
FLA_Check_complex_datatype(FLA_Datatype datatype)220 FLA_Error FLA_Check_complex_datatype( FLA_Datatype datatype )
221 {
222   FLA_Error e_val = FLA_SUCCESS;
223 
224   if ( datatype != FLA_CONSTANT &&
225        datatype != FLA_COMPLEX &&
226        datatype != FLA_DOUBLE_COMPLEX )
227     e_val = FLA_INVALID_COMPLEX_DATATYPE;
228 
229   return e_val;
230 }
231 
FLA_Check_floating_object(FLA_Obj A)232 FLA_Error FLA_Check_floating_object( FLA_Obj A )
233 {
234   FLA_Error    e_val = FLA_SUCCESS;
235   FLA_Datatype datatype;
236 
237   datatype = FLA_Obj_datatype( A );
238 
239   if ( FLA_Check_floating_datatype( datatype ) != FLA_SUCCESS )
240     e_val = FLA_OBJECT_NOT_FLOATING_POINT;
241 
242   return e_val;
243 }
244 
FLA_Check_int_object(FLA_Obj A)245 FLA_Error FLA_Check_int_object( FLA_Obj A )
246 {
247   FLA_Error    e_val = FLA_SUCCESS;
248   FLA_Datatype datatype;
249 
250   datatype = FLA_Obj_datatype( A );
251 
252   if ( FLA_Check_int_datatype( datatype ) != FLA_SUCCESS )
253     e_val = FLA_OBJECT_NOT_INTEGER;
254 
255   return e_val;
256 }
257 
FLA_Check_real_object(FLA_Obj A)258 FLA_Error FLA_Check_real_object( FLA_Obj A )
259 {
260   FLA_Error    e_val = FLA_SUCCESS;
261   FLA_Datatype datatype;
262 
263   datatype = FLA_Obj_datatype( A );
264 
265   if ( FLA_Check_real_datatype( datatype ) != FLA_SUCCESS )
266     e_val = FLA_OBJECT_NOT_REAL;
267 
268   return e_val;
269 }
270 
FLA_Check_comparable_object(FLA_Obj A)271 FLA_Error FLA_Check_comparable_object( FLA_Obj A )
272 {
273   FLA_Error    e_val = FLA_SUCCESS;
274   FLA_Datatype datatype;
275 
276   datatype = FLA_Obj_datatype( A );
277 
278   if ( FLA_Check_int_datatype( datatype ) != FLA_SUCCESS &&
279        FLA_Check_real_datatype( datatype ) != FLA_SUCCESS )
280     e_val = FLA_OBJECT_NOT_COMPARABLE;
281 
282   return e_val;
283 }
284 
FLA_Check_complex_object(FLA_Obj A)285 FLA_Error FLA_Check_complex_object( FLA_Obj A )
286 {
287   FLA_Error    e_val = FLA_SUCCESS;
288   FLA_Datatype datatype;
289 
290   datatype = FLA_Obj_datatype( A );
291 
292   if ( FLA_Check_complex_datatype( datatype ) != FLA_SUCCESS )
293     e_val = FLA_OBJECT_NOT_COMPLEX;
294 
295   return e_val;
296 }
297 
FLA_Check_identical_object_precision(FLA_Obj A,FLA_Obj B)298 FLA_Error FLA_Check_identical_object_precision( FLA_Obj A, FLA_Obj B )
299 {
300   FLA_Error    e_val = FLA_SUCCESS;
301   FLA_Datatype datatype_A;
302   FLA_Datatype datatype_B;
303   dim_t        precision_A;
304   dim_t        precision_B;
305 
306   datatype_A = FLA_Obj_datatype( A );
307   datatype_B = FLA_Obj_datatype( B );
308 
309   if ( datatype_A == FLA_CONSTANT ||
310        datatype_B == FLA_CONSTANT )
311   {
312     return FLA_SUCCESS;
313   }
314 
315   if ( FLA_Check_floating_object( A ) != FLA_SUCCESS ||
316        FLA_Check_floating_object( B ) != FLA_SUCCESS )
317   {
318     return FLA_OBJECT_NOT_FLOATING_POINT;
319   }
320 
321   datatype_A = FLA_Obj_datatype( A );
322   datatype_B = FLA_Obj_datatype( B );
323 
324   precision_A = FLA_Obj_datatype_size( datatype_A );
325   precision_B = FLA_Obj_datatype_size( datatype_B );
326 
327   if ( FLA_Obj_is_complex( A ) )
328     precision_A = precision_A / 2;
329 
330   if ( FLA_Obj_is_complex( B ) )
331     precision_B = precision_B / 2;
332 
333   if ( precision_A != precision_B )
334     e_val = FLA_INCONSISTENT_OBJECT_PRECISION;
335 
336   return e_val;
337 }
338 
FLA_Check_consistent_object_datatype(FLA_Obj A,FLA_Obj B)339 FLA_Error FLA_Check_consistent_object_datatype( FLA_Obj A, FLA_Obj B )
340 {
341   FLA_Error e_val = FLA_SUCCESS;
342 
343   if ( FLA_Obj_datatype( A ) != FLA_CONSTANT &&
344        FLA_Obj_datatype( B ) != FLA_CONSTANT )
345     if ( FLA_Obj_datatype( A ) != FLA_Obj_datatype( B ) )
346       e_val = FLA_INCONSISTENT_DATATYPES;
347 
348   return e_val;
349 }
350 
FLA_Check_consistent_datatype(FLA_Datatype datatype,FLA_Obj A)351 FLA_Error FLA_Check_consistent_datatype( FLA_Datatype datatype, FLA_Obj A )
352 {
353   FLA_Error e_val = FLA_SUCCESS;
354 
355   if ( FLA_Obj_datatype( A ) != FLA_CONSTANT &&
356                     datatype != FLA_CONSTANT )
357     if ( FLA_Obj_datatype( A ) != datatype )
358       e_val = FLA_INCONSISTENT_DATATYPES;
359 
360   return e_val;
361 }
362 
FLA_Check_square(FLA_Obj A)363 FLA_Error FLA_Check_square( FLA_Obj A )
364 {
365   FLA_Error e_val = FLA_SUCCESS;
366 
367   if ( FLA_Obj_length( A ) != FLA_Obj_width( A ) )
368     e_val = FLA_OBJECT_NOT_SQUARE;
369 
370   return e_val;
371 }
372 
FLA_Check_if_scalar(FLA_Obj A)373 FLA_Error FLA_Check_if_scalar( FLA_Obj A )
374 {
375   FLA_Error e_val = FLA_SUCCESS;
376 
377   if ( FLA_Obj_length( A ) != 1 || FLA_Obj_width( A ) != 1 )
378     e_val = FLA_OBJECT_NOT_SCALAR;
379 
380   return e_val;
381 }
382 
FLA_Check_if_vector(FLA_Obj A)383 FLA_Error FLA_Check_if_vector( FLA_Obj A )
384 {
385   FLA_Error e_val = FLA_SUCCESS;
386 
387   if ( FLA_Obj_length( A ) != 1 && FLA_Obj_width( A ) != 1 )
388     e_val = FLA_OBJECT_NOT_VECTOR;
389 
390   return e_val;
391 }
392 
FLA_Check_conformal_dims(FLA_Trans trans,FLA_Obj A,FLA_Obj B)393 FLA_Error FLA_Check_conformal_dims( FLA_Trans trans, FLA_Obj A, FLA_Obj B )
394 {
395   FLA_Error e_val = FLA_SUCCESS;
396 
397   if ( trans == FLA_NO_TRANSPOSE || trans == FLA_CONJ_NO_TRANSPOSE )
398   {
399     if ( FLA_Obj_length( A ) != FLA_Obj_length( B ) )
400       e_val = FLA_NONCONFORMAL_DIMENSIONS;
401 
402     if ( FLA_Obj_width( A ) != FLA_Obj_width( B ) )
403       e_val = FLA_NONCONFORMAL_DIMENSIONS;
404   }
405   else
406   {
407     if ( FLA_Obj_width( A ) != FLA_Obj_length( B ) )
408       e_val = FLA_NONCONFORMAL_DIMENSIONS;
409 
410     if ( FLA_Obj_length( A ) != FLA_Obj_width( B ) )
411       e_val = FLA_NONCONFORMAL_DIMENSIONS;
412   }
413 
414   return e_val;
415 }
416 
FLA_Check_matrix_matrix_dims(FLA_Trans transa,FLA_Trans transb,FLA_Obj A,FLA_Obj B,FLA_Obj C)417 FLA_Error FLA_Check_matrix_matrix_dims( FLA_Trans transa, FLA_Trans transb, FLA_Obj A, FLA_Obj B, FLA_Obj C )
418 {
419   FLA_Error e_val = FLA_SUCCESS;
420   dim_t     k_A, k_B;
421   dim_t     m_A, m_C;
422   dim_t     n_B, n_C;
423 
424   m_A = ( transa == FLA_NO_TRANSPOSE ||
425           transa == FLA_CONJ_NO_TRANSPOSE ? FLA_Obj_length( A ) :
426                                             FLA_Obj_width( A )  );
427   k_A = ( transa == FLA_NO_TRANSPOSE ||
428           transa == FLA_CONJ_NO_TRANSPOSE ? FLA_Obj_width( A )  :
429                                             FLA_Obj_length( A ) );
430 
431   k_B = ( transb == FLA_NO_TRANSPOSE ||
432           transb == FLA_CONJ_NO_TRANSPOSE ? FLA_Obj_length( B ) :
433                                             FLA_Obj_width( B )  );
434   n_B = ( transb == FLA_NO_TRANSPOSE ||
435           transb == FLA_CONJ_NO_TRANSPOSE ? FLA_Obj_width( B )  :
436                                             FLA_Obj_length( B ) );
437 
438   m_C = FLA_Obj_length( C );
439   n_C = FLA_Obj_width( C );
440 
441   if ( m_A != m_C )
442     e_val = FLA_NONCONFORMAL_DIMENSIONS;
443 
444   if ( k_A != k_B )
445     e_val = FLA_NONCONFORMAL_DIMENSIONS;
446 
447   if ( n_B != n_C )
448     e_val = FLA_NONCONFORMAL_DIMENSIONS;
449 
450   return e_val;
451 }
452 
FLA_Check_matrix_vector_dims(FLA_Trans trans,FLA_Obj A,FLA_Obj x,FLA_Obj y)453 FLA_Error FLA_Check_matrix_vector_dims( FLA_Trans trans, FLA_Obj A, FLA_Obj x, FLA_Obj y )
454 {
455   FLA_Error e_val = FLA_SUCCESS;
456 
457   if ( trans == FLA_NO_TRANSPOSE || trans == FLA_CONJ_NO_TRANSPOSE )
458   {
459     if ( FLA_Obj_width( A ) != FLA_Obj_vector_dim( x ) )
460       e_val = FLA_NONCONFORMAL_DIMENSIONS;
461 
462     if ( FLA_Obj_length( A ) != FLA_Obj_vector_dim( y ) )
463       e_val = FLA_NONCONFORMAL_DIMENSIONS;
464   }
465   else
466   {
467     if ( FLA_Obj_length( A ) != FLA_Obj_vector_dim( x ) )
468       e_val = FLA_NONCONFORMAL_DIMENSIONS;
469 
470     if ( FLA_Obj_width( A ) != FLA_Obj_vector_dim( y ) )
471       e_val = FLA_NONCONFORMAL_DIMENSIONS;
472   }
473 
474   return e_val;
475 }
476 
FLA_Check_equal_vector_dims(FLA_Obj x,FLA_Obj y)477 FLA_Error FLA_Check_equal_vector_dims( FLA_Obj x, FLA_Obj y )
478 {
479   FLA_Error e_val = FLA_SUCCESS;
480 
481   if ( FLA_Obj_vector_dim( x ) != FLA_Obj_vector_dim( y ) )
482     e_val = FLA_UNEQUAL_VECTOR_DIMS;
483 
484   return e_val;
485 }
486 
FLA_Check_conj1_trans_and_datatype(FLA_Trans trans,FLA_Obj A)487 FLA_Error FLA_Check_conj1_trans_and_datatype( FLA_Trans trans, FLA_Obj A )
488 {
489   FLA_Error e_val = FLA_SUCCESS;
490 
491   if ( trans == FLA_CONJ_TRANSPOSE || trans == FLA_CONJ_NO_TRANSPOSE ){
492     if ( FLA_Obj_is_complex( A ) == FALSE )
493       e_val = FLA_INVALID_TRANS_GIVEN_DATATYPE;
494   }
495 
496   return e_val;
497 }
498 
FLA_Check_hess_indices(FLA_Obj A,int ilo,int ihi)499 FLA_Error FLA_Check_hess_indices( FLA_Obj A, int ilo, int ihi )
500 {
501   FLA_Error e_val = FLA_SUCCESS;
502 
503   if ( FLA_Obj_width( A ) == 0 && ilo != 0 && ihi != -1 )
504     e_val = FLA_INVALID_HESSENBERG_INDICES;
505 
506   if ( ilo < 0 || FLA_Obj_width( A ) - 1 < ilo )
507     e_val = FLA_INVALID_HESSENBERG_INDICES;
508 
509   if ( ihi < 0 || FLA_Obj_width( A ) - 1 < ihi )
510     e_val = FLA_INVALID_HESSENBERG_INDICES;
511 
512   if ( ihi < ilo )
513     e_val = FLA_INVALID_HESSENBERG_INDICES;
514 
515   return e_val;
516 }
517 
FLA_Check_null_pointer(void * ptr)518 FLA_Error FLA_Check_null_pointer( void* ptr )
519 {
520   FLA_Error e_val = FLA_SUCCESS;
521 
522   if ( ptr == NULL )
523     e_val = FLA_NULL_POINTER;
524 
525   return e_val;
526 }
527 
FLA_Check_object_dims(FLA_Trans trans,dim_t m,dim_t n,FLA_Obj A)528 FLA_Error FLA_Check_object_dims( FLA_Trans trans, dim_t m, dim_t n, FLA_Obj A )
529 {
530   FLA_Error e_val = FLA_SUCCESS;
531 
532   if ( trans == FLA_NO_TRANSPOSE || trans == FLA_CONJ_NO_TRANSPOSE )
533   {
534     if ( FLA_Obj_length( A ) != m )
535       e_val = FLA_SPECIFIED_OBJ_DIM_MISMATCH;
536 
537     if ( FLA_Obj_width( A ) != n )
538       e_val = FLA_SPECIFIED_OBJ_DIM_MISMATCH;
539   }
540   else
541   {
542     if ( FLA_Obj_length( A ) != n )
543       e_val = FLA_SPECIFIED_OBJ_DIM_MISMATCH;
544 
545     if ( FLA_Obj_width( A ) != m )
546       e_val = FLA_SPECIFIED_OBJ_DIM_MISMATCH;
547   }
548 
549   return e_val;
550 }
551 
FLA_Check_valid_pivot_type(FLA_Pivot_type ptype)552 FLA_Error FLA_Check_valid_pivot_type( FLA_Pivot_type ptype )
553 {
554   FLA_Error e_val = FLA_SUCCESS;
555 
556   if ( ptype != FLA_NATIVE_PIVOTS && ptype != FLA_LAPACK_PIVOTS )
557     e_val = FLA_INVALID_PIVOT_TYPE;
558 
559   return e_val;
560 }
561 
FLA_Check_malloc_pointer(void * ptr)562 FLA_Error FLA_Check_malloc_pointer( void* ptr )
563 {
564   FLA_Error e_val = FLA_SUCCESS;
565 
566   if ( ptr == NULL )
567     e_val = FLA_MALLOC_RETURNED_NULL_POINTER;
568 
569   return e_val;
570 }
571 
FLA_Check_base_buffer_mismatch(FLA_Obj A,FLA_Obj B)572 FLA_Error FLA_Check_base_buffer_mismatch( FLA_Obj A, FLA_Obj B )
573 {
574   FLA_Error e_val = FLA_SUCCESS;
575 
576   if ( A.base->buffer != B.base->buffer )
577     e_val = FLA_OBJECT_BASE_BUFFER_MISMATCH;
578 
579   return e_val;
580 }
581 
FLA_Check_adjacent_objects_2x2(FLA_Obj ATL,FLA_Obj ATR,FLA_Obj ABL,FLA_Obj ABR)582 FLA_Error FLA_Check_adjacent_objects_2x2( FLA_Obj ATL, FLA_Obj ATR,
583                                           FLA_Obj ABL, FLA_Obj ABR )
584 {
585   FLA_Error e_val = FLA_SUCCESS;
586 
587   if ( FLA_Obj_length( ATL ) != FLA_Obj_length( ATR ) ||
588        FLA_Obj_length( ABL ) != FLA_Obj_length( ABR ) ||
589        FLA_Obj_width( ATL )  != FLA_Obj_width( ABL )  ||
590        FLA_Obj_width( ATR )  != FLA_Obj_width( ABR ) )
591     e_val = FLA_ADJACENT_OBJECT_DIM_MISMATCH;
592 
593   if ( ATL.offm != ABL.offm + FLA_Obj_length( ABL ) ||
594        ATR.offm != ABR.offm + FLA_Obj_length( ABL ) )
595     e_val = FLA_OBJECTS_NOT_VERTICALLY_ADJ;
596 
597   if ( ATL.offn != ABL.offn ||
598        ATR.offn != ABR.offn )
599     e_val = FLA_OBJECTS_NOT_VERTICALLY_ALIGNED;
600 
601   if ( ATL.offn != ATR.offn + FLA_Obj_width( ATR ) ||
602        ABL.offn != ABR.offn + FLA_Obj_width( ATR ) )
603     e_val = FLA_OBJECTS_NOT_HORIZONTALLY_ADJ;
604 
605   if ( ATL.offm != ATR.offm ||
606        ABL.offm != ABR.offm )
607     e_val = FLA_OBJECTS_NOT_HORIZONTALLY_ALIGNED;
608 
609   return e_val;
610 }
611 
FLA_Check_adjacent_objects_2x1(FLA_Obj AT,FLA_Obj AB)612 FLA_Error FLA_Check_adjacent_objects_2x1( FLA_Obj AT,
613                                           FLA_Obj AB )
614 {
615   FLA_Error e_val = FLA_SUCCESS;
616 
617   if ( FLA_Obj_width( AT ) != FLA_Obj_width( AB ) )
618     e_val = FLA_ADJACENT_OBJECT_DIM_MISMATCH;
619 
620   if ( AB.offm != AT.offm + FLA_Obj_length( AT ) )
621     e_val = FLA_OBJECTS_NOT_VERTICALLY_ADJ;
622 
623   if ( AB.offn != AT.offn )
624     e_val = FLA_OBJECTS_NOT_VERTICALLY_ALIGNED;
625 
626   return e_val;
627 }
628 
FLA_Check_adjacent_objects_1x2(FLA_Obj AL,FLA_Obj AR)629 FLA_Error FLA_Check_adjacent_objects_1x2( FLA_Obj AL, FLA_Obj AR )
630 {
631   FLA_Error e_val = FLA_SUCCESS;
632 
633   if ( FLA_Obj_length( AL ) != FLA_Obj_length( AR ) )
634     e_val = FLA_ADJACENT_OBJECT_DIM_MISMATCH;
635 
636   if ( AR.offn != AL.offn + FLA_Obj_width( AL ) )
637     e_val = FLA_OBJECTS_NOT_HORIZONTALLY_ADJ;
638 
639   if ( AL.offm != AR.offm )
640     e_val = FLA_OBJECTS_NOT_HORIZONTALLY_ALIGNED;
641 
642   return e_val;
643 }
644 
FLA_Check_blocksize_value(dim_t b)645 FLA_Error FLA_Check_blocksize_value( dim_t b )
646 {
647   FLA_Error e_val = FLA_SUCCESS;
648 
649   if ( b <= 0 )
650     e_val = FLA_INVALID_BLOCKSIZE_VALUE;
651 
652   return e_val;
653 }
654 
FLA_Check_blocksize_object(FLA_Datatype datatype,fla_blocksize_t * bp)655 FLA_Error FLA_Check_blocksize_object( FLA_Datatype datatype, fla_blocksize_t* bp )
656 {
657   FLA_Error e_val = FLA_SUCCESS;
658   dim_t     b;
659 
660   b = FLA_Blocksize_extract( datatype, bp );
661   if ( b <= 0 )
662     e_val = FLA_INVALID_BLOCKSIZE_OBJ;
663 
664   return e_val;
665 }
666 
FLA_Check_file_descriptor(int fd)667 FLA_Error FLA_Check_file_descriptor( int fd )
668 {
669   FLA_Error e_val = FLA_SUCCESS;
670 
671   if ( fd == -1 )
672     e_val = FLA_OPEN_RETURNED_ERROR;
673 
674   return e_val;
675 }
676 
FLA_Check_lseek_result(int requested_offset,int lseek_r_val)677 FLA_Error FLA_Check_lseek_result( int requested_offset, int lseek_r_val )
678 {
679   FLA_Error e_val = FLA_SUCCESS;
680 
681   if ( lseek_r_val != requested_offset )
682     e_val = FLA_LSEEK_RETURNED_ERROR;
683 
684   return e_val;
685 }
686 
FLA_Check_close_result(int close_r_val)687 FLA_Error FLA_Check_close_result( int close_r_val )
688 {
689   FLA_Error e_val = FLA_SUCCESS;
690 
691   if ( close_r_val == -1 )
692     e_val = FLA_CLOSE_RETURNED_ERROR;
693 
694   return e_val;
695 }
696 
FLA_Check_unlink_result(int unlink_r_val)697 FLA_Error FLA_Check_unlink_result( int unlink_r_val )
698 {
699   FLA_Error e_val = FLA_SUCCESS;
700 
701   if ( unlink_r_val == -1 )
702     e_val = FLA_UNLINK_RETURNED_ERROR;
703 
704   return e_val;
705 }
706 
FLA_Check_read_result(int requested_size,int read_r_val)707 FLA_Error FLA_Check_read_result( int requested_size, int read_r_val )
708 {
709   FLA_Error e_val = FLA_SUCCESS;
710 
711   if ( read_r_val == -1 )
712     e_val = FLA_READ_RETURNED_ERROR;
713 
714   return e_val;
715 }
716 
FLA_Check_write_result(int requested_size,int write_r_val)717 FLA_Error FLA_Check_write_result( int requested_size, int write_r_val )
718 {
719   FLA_Error e_val = FLA_SUCCESS;
720 
721   if ( write_r_val != requested_size )
722     e_val = FLA_WRITE_RETURNED_ERROR;
723 
724   return e_val;
725 }
726 
FLA_Check_valid_quadrant(FLA_Quadrant quad)727 FLA_Error FLA_Check_valid_quadrant( FLA_Quadrant quad )
728 {
729   FLA_Error e_val = FLA_SUCCESS;
730 
731   if ( quad != FLA_TL &&
732        quad != FLA_TR &&
733        quad != FLA_BL &&
734        quad != FLA_BR )
735     e_val = FLA_INVALID_QUADRANT;
736 
737   return e_val;
738 }
739 
FLA_Check_vector_dim_min(FLA_Obj x,dim_t min_dim)740 FLA_Error FLA_Check_vector_dim_min( FLA_Obj x, dim_t min_dim )
741 {
742   FLA_Error e_val = FLA_SUCCESS;
743 
744   if ( FLA_Obj_vector_dim( x ) < min_dim )
745     e_val = FLA_VECTOR_DIM_BELOW_MIN;
746 
747   return e_val;
748 }
749 
FLA_Check_pthread_create_result(int pthread_create_r_val)750 FLA_Error FLA_Check_pthread_create_result( int pthread_create_r_val )
751 {
752   FLA_Error e_val = FLA_SUCCESS;
753 
754   if ( pthread_create_r_val != 0 )
755     e_val = FLA_PTHREAD_CREATE_RETURNED_ERROR;
756 
757   return e_val;
758 }
759 
FLA_Check_pthread_join_result(int pthread_join_r_val)760 FLA_Error FLA_Check_pthread_join_result( int pthread_join_r_val )
761 {
762   FLA_Error e_val = FLA_SUCCESS;
763 
764   if ( pthread_join_r_val != 0 )
765     e_val = FLA_PTHREAD_JOIN_RETURNED_ERROR;
766 
767   return e_val;
768 }
769 
FLA_Check_valid_isgn_value(FLA_Obj isgn)770 FLA_Error FLA_Check_valid_isgn_value( FLA_Obj isgn )
771 {
772   FLA_Error e_val = FLA_SUCCESS;
773 
774   if ( !FLA_Obj_is( isgn, FLA_ONE ) &&
775        !FLA_Obj_is( isgn, FLA_MINUS_ONE ) )
776     e_val = FLA_INVALID_ISGN_VALUE;
777 
778   return e_val;
779 }
780 
FLA_Check_sylv_matrix_dims(FLA_Obj A,FLA_Obj B,FLA_Obj C)781 FLA_Error FLA_Check_sylv_matrix_dims( FLA_Obj A, FLA_Obj B, FLA_Obj C )
782 {
783   FLA_Error e_val = FLA_SUCCESS;
784   dim_t     m_A, m_C;
785   dim_t     n_B, n_C;
786 
787   m_A = FLA_Obj_length( A );
788 
789   n_B = FLA_Obj_width( B );
790 
791   m_C = FLA_Obj_length( C );
792   n_C = FLA_Obj_width( C );
793 
794   if ( m_A != m_C )
795     e_val = FLA_NONCONFORMAL_DIMENSIONS;
796 
797   if ( n_B != n_C )
798     e_val = FLA_NONCONFORMAL_DIMENSIONS;
799 
800   return e_val;
801 }
802 
FLA_Check_chol_failure(FLA_Error r_val)803 FLA_Error FLA_Check_chol_failure( FLA_Error r_val )
804 {
805   FLA_Error e_val = FLA_SUCCESS;
806 
807   if ( r_val > 0 )
808     e_val = FLA_CHOL_FAILED_MATRIX_NOT_SPD;
809 
810   return e_val;
811 }
812 
FLA_Check_valid_elemtype(FLA_Elemtype elemtype)813 FLA_Error FLA_Check_valid_elemtype( FLA_Elemtype elemtype )
814 {
815   FLA_Error e_val = FLA_SUCCESS;
816 
817   if ( elemtype != FLA_SCALAR &&
818        elemtype != FLA_MATRIX )
819     e_val = FLA_INVALID_ELEMTYPE;
820 
821   return e_val;
822 }
823 
FLA_Check_posix_memalign_failure(int r_val)824 FLA_Error FLA_Check_posix_memalign_failure( int r_val )
825 {
826   FLA_Error e_val = FLA_SUCCESS;
827 
828   if ( r_val != 0 )
829     e_val = FLA_POSIX_MEMALIGN_FAILED;
830 
831   return e_val;
832 }
833 
FLA_Check_submatrix_dims_and_offset(dim_t m,dim_t n,dim_t i,dim_t j,FLA_Obj A)834 FLA_Error FLA_Check_submatrix_dims_and_offset( dim_t m, dim_t n, dim_t i, dim_t j, FLA_Obj A )
835 {
836   FLA_Error e_val = FLA_SUCCESS;
837   dim_t     m_A, n_A;
838 
839   if ( FLA_Obj_elemtype( A ) == FLA_MATRIX )
840   {
841     m_A = FLASH_Obj_scalar_length( A );
842     n_A = FLASH_Obj_scalar_width( A );
843   }
844   else
845   {
846     m_A = FLA_Obj_length( A );
847     n_A = FLA_Obj_width( A );
848   }
849 
850   if      ( i     > m_A || j     > n_A )
851     e_val = FLA_INVALID_SUBMATRIX_OFFSET;
852   else if ( i + m > m_A || j + n > n_A )
853     e_val = FLA_INVALID_SUBMATRIX_DIMS;
854 
855   return e_val;
856 }
857 
FLA_Check_object_scalar_elemtype(FLA_Obj A)858 FLA_Error FLA_Check_object_scalar_elemtype( FLA_Obj A )
859 {
860   FLA_Error     e_val = FLA_SUCCESS;
861   FLA_Elemtype  elemtype;
862 
863   elemtype = FLA_Obj_elemtype( A );
864 
865   if ( elemtype != FLA_SCALAR )
866     e_val = FLA_OBJECT_NOT_SCALAR_ELEMTYPE;
867 
868   return e_val;
869 }
870 
FLA_Check_object_matrix_elemtype(FLA_Obj A)871 FLA_Error FLA_Check_object_matrix_elemtype( FLA_Obj A )
872 {
873   FLA_Error     e_val = FLA_SUCCESS;
874   FLA_Elemtype  elemtype;
875 
876   elemtype = FLA_Obj_elemtype( A );
877 
878   if ( elemtype != FLA_MATRIX )
879     e_val = FLA_OBJECT_NOT_MATRIX_ELEMTYPE;
880 
881   return e_val;
882 }
883 
FLA_Check_num_threads(unsigned int n_threads)884 FLA_Error FLA_Check_num_threads( unsigned int n_threads )
885 {
886   FLA_Error e_val = FLA_SUCCESS;
887 
888   if ( n_threads < 1 )
889     e_val = FLA_ENCOUNTERED_NON_POSITIVE_NTHREADS;
890 
891   return e_val;
892 }
893 
FLA_Check_conj_and_datatype(FLA_Conj conj,FLA_Obj A)894 FLA_Error FLA_Check_conj_and_datatype( FLA_Conj conj, FLA_Obj A )
895 {
896   FLA_Error e_val = FLA_SUCCESS;
897 
898   if ( conj == FLA_CONJUGATE ){
899     if ( FLA_Obj_is_complex( A ) == FALSE )
900       e_val = FLA_INVALID_CONJ_GIVEN_DATATYPE;
901   }
902 
903   return e_val;
904 }
905 
FLA_Check_valid_complex_trans(FLA_Trans trans)906 FLA_Error FLA_Check_valid_complex_trans( FLA_Trans trans )
907 {
908   FLA_Error e_val = FLA_SUCCESS;
909 
910   if ( trans != FLA_NO_TRANSPOSE &&
911        trans != FLA_CONJ_TRANSPOSE )
912     e_val = FLA_INVALID_COMPLEX_TRANS;
913 
914   return e_val;
915 }
916 
FLA_Check_valid_real_trans(FLA_Trans trans)917 FLA_Error FLA_Check_valid_real_trans( FLA_Trans trans )
918 {
919   FLA_Error e_val = FLA_SUCCESS;
920 
921   if ( trans != FLA_NO_TRANSPOSE &&
922        trans != FLA_TRANSPOSE )
923     e_val = FLA_INVALID_REAL_TRANS;
924 
925   return e_val;
926 }
927 
FLA_Check_valid_blas_trans(FLA_Trans trans)928 FLA_Error FLA_Check_valid_blas_trans( FLA_Trans trans )
929 {
930   FLA_Error e_val = FLA_SUCCESS;
931 
932   if ( trans != FLA_NO_TRANSPOSE &&
933        trans != FLA_TRANSPOSE &&
934        trans != FLA_CONJ_TRANSPOSE )
935     e_val = FLA_INVALID_BLAS_TRANS;
936 
937   return e_val;
938 }
939 
FLA_Check_nonconstant_datatype(FLA_Datatype datatype)940 FLA_Error FLA_Check_nonconstant_datatype( FLA_Datatype datatype )
941 {
942   FLA_Error e_val = FLA_SUCCESS;
943 
944   if ( datatype != FLA_INT &&
945        datatype != FLA_FLOAT &&
946        datatype != FLA_DOUBLE &&
947        datatype != FLA_COMPLEX &&
948        datatype != FLA_DOUBLE_COMPLEX )
949     e_val = FLA_INVALID_NONCONSTANT_DATATYPE;
950 
951   return e_val;
952 }
953 
FLA_Check_nonconstant_object(FLA_Obj A)954 FLA_Error FLA_Check_nonconstant_object( FLA_Obj A )
955 {
956   FLA_Error    e_val = FLA_SUCCESS;
957   FLA_Datatype datatype;
958 
959   datatype = FLA_Obj_datatype( A );
960 
961   if ( FLA_Check_nonconstant_datatype( datatype ) != FLA_SUCCESS )
962     e_val = FLA_OBJECT_NOT_NONCONSTANT;
963 
964   return e_val;
965 }
966 
FLA_Check_identical_object_datatype(FLA_Obj A,FLA_Obj B)967 FLA_Error FLA_Check_identical_object_datatype( FLA_Obj A, FLA_Obj B )
968 {
969   FLA_Error e_val = FLA_SUCCESS;
970 
971   if ( FLA_Obj_datatype( A ) != FLA_Obj_datatype( B ) )
972     e_val = FLA_OBJECT_DATATYPES_NOT_EQUAL;
973 
974   return e_val;
975 }
976 
FLA_Check_divide_by_zero(FLA_Obj alpha)977 FLA_Error FLA_Check_divide_by_zero( FLA_Obj alpha )
978 {
979   FLA_Error e_val = FLA_SUCCESS;
980 
981   if ( FLA_Obj_equals( alpha, FLA_ZERO ) )
982     e_val = FLA_DIVIDE_BY_ZERO;
983 
984   return e_val;
985 }
986 
FLA_Check_identical_object_elemtype(FLA_Obj A,FLA_Obj B)987 FLA_Error FLA_Check_identical_object_elemtype( FLA_Obj A, FLA_Obj B )
988 {
989   FLA_Error e_val = FLA_SUCCESS;
990 
991   if ( FLA_Obj_elemtype( A ) != FLA_Obj_elemtype( B ) )
992     e_val = FLA_OBJECT_ELEMTYPES_NOT_EQUAL;
993 
994   return e_val;
995 }
996 
FLA_Check_pivot_index_range(FLA_Obj p,dim_t k1,dim_t k2)997 FLA_Error FLA_Check_pivot_index_range( FLA_Obj p, dim_t k1, dim_t k2 )
998 {
999   FLA_Error e_val = FLA_SUCCESS;
1000 
1001   if ( FLA_Obj_has_zero_dim( p ) )
1002     return e_val;
1003 
1004   // FGVZ: Note that we don't need to test if k1 < 0 since the type is an
1005   // unsigned integer. Same goes for k2 < 0. If we ever wanted to allow
1006   // the caller to specify the index range k1:k2 == -1:0, which would
1007   // result in no action. If this "no-op" behavior is needed, then k1 and
1008   // k2 should be type re-declared as ints.
1009   //if ( k1 < 0 || FLA_Obj_length( p ) - 1 < k1 )
1010   if ( FLA_Obj_length( p ) - 1 < k1 )
1011     e_val = FLA_INVALID_PIVOT_INDEX_RANGE;
1012 
1013   //if ( k2 < 0 || FLA_Obj_length( p ) - 1 < k2 )
1014   if ( FLA_Obj_length( p ) - 1 < k2 )
1015     e_val = FLA_INVALID_PIVOT_INDEX_RANGE;
1016 
1017   if ( k2 < k1 )
1018     e_val = FLA_INVALID_PIVOT_INDEX_RANGE;
1019 
1020   return e_val;
1021 }
1022 
FLA_Check_householder_panel_dims(FLA_Obj A,FLA_Obj T)1023 FLA_Error FLA_Check_householder_panel_dims( FLA_Obj A, FLA_Obj T )
1024 {
1025   FLA_Error e_val = FLA_SUCCESS;
1026   dim_t     nb_alg;
1027 
1028   nb_alg = FLA_Query_blocksize( FLA_Obj_datatype( A ), FLA_DIMENSION_MIN );
1029 
1030   if ( FLA_Obj_length( T ) < nb_alg )
1031     e_val = FLA_HOUSEH_PANEL_MATRIX_TOO_SMALL;
1032 
1033   if ( FLA_Obj_width( T ) < FLA_Obj_min_dim( A ) )
1034     e_val = FLA_HOUSEH_PANEL_MATRIX_TOO_SMALL;
1035 
1036   return e_val;
1037 }
1038 
FLA_Check_object_length_equals(FLA_Obj A,dim_t m)1039 FLA_Error FLA_Check_object_length_equals( FLA_Obj A, dim_t m )
1040 {
1041   FLA_Error e_val = FLA_SUCCESS;
1042 
1043   if ( FLA_Obj_length( A ) != m )
1044     e_val = FLA_INVALID_OBJECT_LENGTH;
1045 
1046   return e_val;
1047 }
1048 
FLA_Check_object_width_equals(FLA_Obj A,dim_t n)1049 FLA_Error FLA_Check_object_width_equals( FLA_Obj A, dim_t n )
1050 {
1051   FLA_Error e_val = FLA_SUCCESS;
1052 
1053   if ( FLA_Obj_width( A ) != n )
1054     e_val = FLA_INVALID_OBJECT_WIDTH;
1055 
1056   return e_val;
1057 }
1058 
FLA_Check_object_length_min(FLA_Obj A,dim_t m)1059 FLA_Error FLA_Check_object_length_min( FLA_Obj A, dim_t m )
1060 {
1061   FLA_Error e_val = FLA_SUCCESS;
1062 
1063   if ( FLA_Obj_length( A ) < m )
1064     e_val = FLA_INVALID_OBJECT_LENGTH;
1065 
1066   return e_val;
1067 }
1068 
FLA_Check_object_width_min(FLA_Obj A,dim_t n)1069 FLA_Error FLA_Check_object_width_min( FLA_Obj A, dim_t n )
1070 {
1071   FLA_Error e_val = FLA_SUCCESS;
1072 
1073   if ( FLA_Obj_width( A ) < n )
1074     e_val = FLA_INVALID_OBJECT_WIDTH;
1075 
1076   return e_val;
1077 }
1078 
FLA_Check_valid_error_level(unsigned int level)1079 FLA_Error FLA_Check_valid_error_level( unsigned int level )
1080 {
1081   FLA_Error e_val = FLA_SUCCESS;
1082 
1083   if ( level != FLA_NO_ERROR_CHECKING &&
1084        level != FLA_MIN_ERROR_CHECKING &&
1085        level != FLA_FULL_ERROR_CHECKING )
1086     e_val = FLA_INVALID_ERROR_CHECKING_LEVEL;
1087 
1088   return e_val;
1089 }
1090 
FLA_Check_attempted_repart_2x2(FLA_Obj A_quad,dim_t b_m,dim_t b_n)1091 FLA_Error FLA_Check_attempted_repart_2x2( FLA_Obj A_quad, dim_t b_m, dim_t b_n )
1092 {
1093   FLA_Error e_val = FLA_SUCCESS;
1094 
1095   if ( b_m > FLA_Obj_length( A_quad ) )
1096     e_val = FLA_ATTEMPTED_OVER_REPART_2X2;
1097 
1098   if ( b_n > FLA_Obj_width( A_quad ) )
1099     e_val = FLA_ATTEMPTED_OVER_REPART_2X2;
1100 
1101   return e_val;
1102 }
1103 
FLA_Check_attempted_repart_2x1(FLA_Obj A_side,dim_t b_m)1104 FLA_Error FLA_Check_attempted_repart_2x1( FLA_Obj A_side, dim_t b_m )
1105 {
1106   FLA_Error e_val = FLA_SUCCESS;
1107 
1108   if ( b_m > FLA_Obj_length( A_side ) )
1109     e_val = FLA_ATTEMPTED_OVER_REPART_2X1;
1110 
1111   return e_val;
1112 }
1113 
FLA_Check_attempted_repart_1x2(FLA_Obj A_side,dim_t b_n)1114 FLA_Error FLA_Check_attempted_repart_1x2( FLA_Obj A_side, dim_t b_n )
1115 {
1116   FLA_Error e_val = FLA_SUCCESS;
1117 
1118   if ( b_n > FLA_Obj_width( A_side ) )
1119     e_val = FLA_ATTEMPTED_OVER_REPART_1X2;
1120 
1121   return e_val;
1122 }
1123 
FLA_Check_valid_leftright_side(FLA_Side side)1124 FLA_Error FLA_Check_valid_leftright_side( FLA_Side side )
1125 {
1126   FLA_Error e_val = FLA_SUCCESS;
1127 
1128   if ( side != FLA_LEFT &&
1129        side != FLA_RIGHT )
1130     e_val = FLA_INVALID_SIDE;
1131 
1132   return e_val;
1133 }
1134 
FLA_Check_valid_topbottom_side(FLA_Side side)1135 FLA_Error FLA_Check_valid_topbottom_side( FLA_Side side )
1136 {
1137   FLA_Error e_val = FLA_SUCCESS;
1138 
1139   if ( side != FLA_TOP &&
1140        side != FLA_BOTTOM )
1141     e_val = FLA_INVALID_SIDE;
1142 
1143   return e_val;
1144 }
1145 
FLA_Check_matrix_strides(dim_t m,dim_t n,dim_t rs,dim_t cs)1146 FLA_Error FLA_Check_matrix_strides( dim_t m, dim_t n, dim_t rs, dim_t cs )
1147 {
1148   FLA_Error e_val = FLA_SUCCESS;
1149 
1150   // Note: The default case (whereby we interpret rs == cs == 0 as a request
1151   // for column-major order) is handled prior to calling this function, so we
1152   // never see zero strides here.
1153 
1154   // Disallow either of the strides to be zero.
1155   if ( ( rs == 0 || cs == 0 ) )
1156     return FLA_INVALID_STRIDE_COMBINATION;
1157 
1158   // Check stride consistency in cases of general stride.
1159   if ( rs != 1 && cs != 1 )
1160   {
1161     // We apply different tests depending on which way the strides "tilt".
1162     if      ( rs == cs )
1163     {
1164       // If rs == cs, then we must be dealing with an m-by-1 or a 1-by-n matrix
1165       // and thus at least one of the dimensions, m or n, must be unit (even if
1166       // the other is zero).
1167       if ( m != 1 && n != 1 )
1168         return FLA_INVALID_STRIDE_COMBINATION;
1169     }
1170     else if ( rs < cs )
1171     {
1172       // For column-major tilt, cs must be equal or larger than m * rs.
1173       if ( m * rs > cs )
1174         return FLA_INVALID_STRIDE_COMBINATION;
1175     }
1176     else if ( cs < rs )
1177     {
1178       // For row-major tilt, rs must be equal or larger than n * cs.
1179       if ( n * cs > rs )
1180         return FLA_INVALID_STRIDE_COMBINATION;
1181     }
1182   }
1183 
1184   if ( rs == 1 && cs == 1 )
1185   {
1186     // Only allow rs == cs == 1 for scalars and "empty" objects.
1187     if ( !( m == 1 && n == 1 ) &&
1188          !( m == 0 )           &&
1189          !( n == 0 )           )
1190       return FLA_INVALID_STRIDE_COMBINATION;
1191   }
1192   else // perform additional stride/dimension checks on non-scalars.
1193   {
1194     if ( rs == 1 )
1195     {
1196       // For column-major storage, don't allow the column stride to be less than
1197       // the m dimension.
1198       if ( cs < m )
1199         e_val = FLA_INVALID_COL_STRIDE;
1200     }
1201     else if ( cs == 1 )
1202     {
1203       // For row-major storage, don't allow the row stride to be less than
1204       // the n dimension.
1205       if ( rs < n )
1206         e_val = FLA_INVALID_ROW_STRIDE;
1207     }
1208   }
1209 
1210   return e_val;
1211 }
1212 
FLA_Check_vector_dim(FLA_Obj x,dim_t expected_length)1213 FLA_Error FLA_Check_vector_dim( FLA_Obj x, dim_t expected_length )
1214 {
1215   FLA_Error e_val = FLA_SUCCESS;
1216 
1217   if ( FLA_Obj_vector_dim( x ) != expected_length )
1218     e_val = FLA_INVALID_VECTOR_DIM;
1219 
1220   return e_val;
1221 }
1222 
FLA_Check_row_vector(FLA_Obj x)1223 FLA_Error FLA_Check_row_vector( FLA_Obj x )
1224 {
1225   FLA_Error e_val = FLA_SUCCESS;
1226 
1227   if ( FLA_Obj_length( x ) != 1 )
1228     e_val = FLA_EXPECTED_ROW_VECTOR;
1229 
1230   return e_val;
1231 }
1232 
FLA_Check_col_vector(FLA_Obj x)1233 FLA_Error FLA_Check_col_vector( FLA_Obj x )
1234 {
1235   FLA_Error e_val = FLA_SUCCESS;
1236 
1237   if ( FLA_Obj_width( x ) != 1 )
1238     e_val = FLA_EXPECTED_COL_VECTOR;
1239 
1240   return e_val;
1241 }
1242 
FLA_Check_valid_evd_type(FLA_Evd_type evd_type)1243 FLA_Error FLA_Check_valid_evd_type( FLA_Evd_type evd_type )
1244 {
1245   FLA_Error e_val = FLA_SUCCESS;
1246 
1247   if ( evd_type != FLA_EVD_WITHOUT_VECTORS &&
1248        evd_type != FLA_EVD_WITH_VECTORS )
1249     e_val = FLA_INVALID_EVD_TYPE;
1250 
1251   return e_val;
1252 }
1253 
FLA_Check_valid_svd_type(FLA_Svd_type svd_type)1254 FLA_Error FLA_Check_valid_svd_type( FLA_Svd_type svd_type )
1255 {
1256   FLA_Error e_val = FLA_SUCCESS;
1257 
1258   if ( svd_type != FLA_SVD_VECTORS_ALL &&
1259        svd_type != FLA_SVD_VECTORS_MIN_COPY &&
1260        svd_type != FLA_SVD_VECTORS_MIN_OVERWRITE &&
1261        svd_type != FLA_SVD_VECTORS_NONE )
1262     e_val = FLA_INVALID_SVD_TYPE;
1263 
1264   return e_val;
1265 }
1266 
FLA_Check_valid_svd_type_combination(FLA_Svd_type svd_type_u,FLA_Svd_type svd_type_v)1267 FLA_Error FLA_Check_valid_svd_type_combination( FLA_Svd_type svd_type_u, FLA_Svd_type svd_type_v )
1268 {
1269   FLA_Error e_val = FLA_SUCCESS;
1270 
1271   if ( svd_type_u == FLA_SVD_VECTORS_MIN_OVERWRITE &&
1272        svd_type_v == FLA_SVD_VECTORS_MIN_OVERWRITE )
1273     e_val = FLA_INVALID_SVD_TYPE_COMBINATION;
1274 
1275   return e_val;
1276 }
1277 
FLA_Check_valid_svd_type_and_trans_combination(FLA_Svd_type svd_type_u,FLA_Trans transu,FLA_Svd_type svd_type_v,FLA_Trans transv)1278 FLA_Error FLA_Check_valid_svd_type_and_trans_combination( FLA_Svd_type svd_type_u, FLA_Trans transu,
1279                                                           FLA_Svd_type svd_type_v, FLA_Trans transv )
1280 {
1281   FLA_Error e_val = FLA_SUCCESS;
1282 
1283   if ( svd_type_u == FLA_SVD_VECTORS_MIN_OVERWRITE )
1284     if ( transu == FLA_TRANSPOSE ||
1285          transu == FLA_CONJ_TRANSPOSE )
1286       e_val = FLA_INVALID_SVD_TYPE_AND_TRANS_COMBINATION;
1287   if ( svd_type_v == FLA_SVD_VECTORS_MIN_OVERWRITE )
1288     if ( transv == FLA_NO_TRANSPOSE ||
1289          transv == FLA_CONJ_NO_TRANSPOSE )
1290       e_val = FLA_INVALID_SVD_TYPE_AND_TRANS_COMBINATION;
1291 
1292   return e_val;
1293 }
1294 
FLA_Check_valid_machval(FLA_Machval val)1295 FLA_Error FLA_Check_valid_machval( FLA_Machval val )
1296 {
1297   FLA_Error e_val = FLA_SUCCESS;
1298 
1299   if ( val != FLA_MACH_EPS      &&
1300        val != FLA_MACH_SFMIN    &&
1301        val != FLA_MACH_BASE     &&
1302        val != FLA_MACH_PREC     &&
1303        val != FLA_MACH_NDIGMANT &&
1304        val != FLA_MACH_RND      &&
1305        val != FLA_MACH_EMIN     &&
1306        val != FLA_MACH_RMIN     &&
1307        val != FLA_MACH_EMAX     &&
1308        val != FLA_MACH_RMAX     &&
1309        val != FLA_MACH_EPS2 )
1310     e_val = FLA_INVALID_MACHVAL;
1311 
1312   return e_val;
1313 }
1314 
FLA_Check_valid_diag_offset(FLA_Obj A,FLA_Diag_off offset)1315 FLA_Error FLA_Check_valid_diag_offset( FLA_Obj A, FLA_Diag_off offset )
1316 {
1317   FLA_Error e_val = FLA_SUCCESS;
1318 
1319   if ( FLA_Obj_min_dim( A ) <= f2c_abs( offset ) )
1320     e_val = FLA_INVALID_DIAG_OFFSET;
1321 
1322   return e_val;
1323 }
1324 
FLA_Check_col_storage(FLA_Obj A)1325 FLA_Error FLA_Check_col_storage( FLA_Obj A )
1326 {
1327   FLA_Error e_val = FLA_SUCCESS;
1328 
1329   if ( FLA_Obj_row_stride( A ) != 1 )
1330     e_val = FLA_EXPECTED_COL_STORAGE;
1331 
1332   return e_val;
1333 }
1334 
FLA_Check_row_storage(FLA_Obj A)1335 FLA_Error FLA_Check_row_storage( FLA_Obj A )
1336 {
1337   FLA_Error e_val = FLA_SUCCESS;
1338 
1339   if ( FLA_Obj_col_stride( A ) != 1 )
1340     e_val = FLA_EXPECTED_ROW_STORAGE;
1341 
1342   return e_val;
1343 }
1344 
1345