libflame  revision_anchor
Functions
FLA_Bsvd_compute_tol_thresh.c File Reference

(r)

Functions

FLA_Error FLA_Bsvd_compute_tol_thresh (FLA_Obj tolmul, FLA_Obj maxitr, FLA_Obj d, FLA_Obj e, FLA_Obj tol, FLA_Obj thresh)
 
FLA_Error FLA_Bsvd_compute_tol_thresh_ops (int n_A, float tolmul, float maxitr, float *buff_d, int inc_d, float *buff_e, int inc_e, float *tol, float *thresh)
 
FLA_Error FLA_Bsvd_compute_tol_thresh_opd (int n_A, double tolmul, double maxitr, double *buff_d, int inc_d, double *buff_e, int inc_e, double *tol, double *thresh)
 

Function Documentation

◆ FLA_Bsvd_compute_tol_thresh()

FLA_Error FLA_Bsvd_compute_tol_thresh ( FLA_Obj  tolmul,
FLA_Obj  maxitr,
FLA_Obj  d,
FLA_Obj  e,
FLA_Obj  tol,
FLA_Obj  thresh 
)

References FLA_Bsvd_compute_tol_thresh_opd(), FLA_Bsvd_compute_tol_thresh_ops(), FLA_Obj_datatype(), FLA_Obj_vector_dim(), and FLA_Obj_vector_inc().

16 {
17  FLA_Datatype datatype;
18  int n_A;
19  int inc_d;
20  int inc_e;
21 
22  datatype = FLA_Obj_datatype( d );
23 
24  n_A = FLA_Obj_vector_dim( d );
25 
26  inc_d = FLA_Obj_vector_inc( d );
27  inc_e = FLA_Obj_vector_inc( e );
28 
29 
30  switch ( datatype )
31  {
32  case FLA_FLOAT:
33  {
34  float* buff_tolmul = FLA_FLOAT_PTR( tolmul );
35  float* buff_maxitr = FLA_FLOAT_PTR( maxitr );
36  float* buff_d = FLA_FLOAT_PTR( d );
37  float* buff_e = FLA_FLOAT_PTR( e );
38  float* buff_tol = FLA_FLOAT_PTR( tol );
39  float* buff_thresh = FLA_FLOAT_PTR( thresh );
40 
42  *buff_tolmul,
43  *buff_maxitr,
44  buff_d, inc_d,
45  buff_e, inc_e,
46  buff_tol,
47  buff_thresh );
48 
49  break;
50  }
51 
52  case FLA_DOUBLE:
53  {
54  double* buff_tolmul = FLA_DOUBLE_PTR( tolmul );
55  double* buff_maxitr = FLA_DOUBLE_PTR( maxitr );
56  double* buff_d = FLA_DOUBLE_PTR( d );
57  double* buff_e = FLA_DOUBLE_PTR( e );
58  double* buff_tol = FLA_DOUBLE_PTR( tol );
59  double* buff_thresh = FLA_DOUBLE_PTR( thresh );
60 
62  *buff_tolmul,
63  *buff_maxitr,
64  buff_d, inc_d,
65  buff_e, inc_e,
66  buff_tol,
67  buff_thresh );
68 
69  break;
70  }
71  }
72 
73  return FLA_SUCCESS;
74 }
FLA_Error FLA_Bsvd_compute_tol_thresh_opd(int n_A, double tolmul, double maxitr, double *buff_d, int inc_d, double *buff_e, int inc_e, double *tol, double *thresh)
Definition: FLA_Bsvd_compute_tol_thresh.c:137
FLA_Datatype FLA_Obj_datatype(FLA_Obj obj)
Definition: FLA_Query.c:13
dim_t FLA_Obj_vector_dim(FLA_Obj obj)
Definition: FLA_Query.c:137
int FLA_Datatype
Definition: FLA_type_defs.h:49
FLA_Error FLA_Bsvd_compute_tol_thresh_ops(int n_A, float tolmul, float maxitr, float *buff_d, int inc_d, float *buff_e, int inc_e, float *tol, float *thresh)
Definition: FLA_Bsvd_compute_tol_thresh.c:78
dim_t FLA_Obj_vector_inc(FLA_Obj obj)
Definition: FLA_Query.c:145

◆ FLA_Bsvd_compute_tol_thresh_opd()

FLA_Error FLA_Bsvd_compute_tol_thresh_opd ( int  n_A,
double  tolmul,
double  maxitr,
double *  buff_d,
int  inc_d,
double *  buff_e,
int  inc_e,
double *  tol,
double *  thresh 
)

References bl1_d0(), FLA_Mach_params_opd(), and i.

Referenced by FLA_Bsvd_compute_tol_thresh(), FLA_Bsvd_ext_opd_var1(), FLA_Bsvd_ext_opz_var1(), FLA_Bsvd_v_opd_var1(), FLA_Bsvd_v_opd_var2(), FLA_Bsvd_v_opz_var1(), and FLA_Bsvd_v_opz_var2().

144 {
145  double zero = bl1_d0();
146  double smin;
147  double eps, unfl;
148  double mu;
149  int i;
150 
151  // Query machine epsilon and the safe minimum.
152  eps = FLA_Mach_params_opd( FLA_MACH_EPS );
153  unfl = FLA_Mach_params_opd( FLA_MACH_SFMIN );
154 
155  // Compute tol as the product of machine epsilon and tolmul.
156  *tol = tolmul * eps;
157 
158  // Compute the approximate maximum singular value.
159  // NOT NEEDED unless we're supporting absolute accuracy.
160  //FLA_Bsvd_sinval_find_max( n_A,
161  // buff_d, inc_d,
162  // buff_e, inc_e,
163  // &smax );
164 
165  // Compute the approximate minimum singular value.
166  smin = fabs( *buff_d );
167 
168  // Skip the accumulation of smin if the first element is zero.
169  if ( smin != zero )
170  {
171  mu = smin;
172  for ( i = 1; i < n_A; ++i )
173  {
174  double* epsilon1 = buff_e + (i-1)*inc_e;
175  double* delta2 = buff_d + (i )*inc_d;
176 
177  mu = fabs( *delta2 ) * ( mu / ( mu + fabs( *epsilon1 ) ) );
178  smin = min( smin, mu );
179 
180  // Stop early if we encountered a zero.
181  if ( smin == zero ) break;
182  }
183  }
184 
185  // Compute thresh either in terms of tol or as a function of the
186  // maximum total number of iterations, the problem size, and the
187  // safe minimum.
188  smin = smin / sqrt( ( double ) n_A );
189  *thresh = max( *tol * smin, maxitr * n_A * n_A * unfl );
190 
191  return FLA_SUCCESS;
192 }
double FLA_Mach_params_opd(FLA_Machval machval)
Definition: FLA_Mach_params.c:74
double bl1_d0(void)
Definition: bl1_constants.c:118
int i
Definition: bl1_axmyv2.c:145

◆ FLA_Bsvd_compute_tol_thresh_ops()

FLA_Error FLA_Bsvd_compute_tol_thresh_ops ( int  n_A,
float  tolmul,
float  maxitr,
float *  buff_d,
int  inc_d,
float *  buff_e,
int  inc_e,
float *  tol,
float *  thresh 
)

References bl1_s0(), FLA_Mach_params_ops(), and i.

Referenced by FLA_Bsvd_compute_tol_thresh(), FLA_Bsvd_ext_opc_var1(), FLA_Bsvd_ext_ops_var1(), FLA_Bsvd_v_opc_var1(), and FLA_Bsvd_v_ops_var1().

85 {
86  float zero = bl1_s0();
87  float smin;
88  float eps, unfl;
89  float mu;
90  int i;
91 
92  // Query machine epsilon and the safe minimum.
93  eps = FLA_Mach_params_ops( FLA_MACH_EPS );
94  unfl = FLA_Mach_params_ops( FLA_MACH_SFMIN );
95 
96  // Compute tol as the product of machine epsilon and tolmul.
97  *tol = tolmul * eps;
98 
99  // Compute the approximate maximum singular value.
100  // NOT NEEDED unless we're supporting absolute accuracy.
101  //FLA_Bsvd_sinval_find_max( n_A,
102  // buff_d, inc_d,
103  // buff_e, inc_e,
104  // &smax );
105 
106  // Compute the approximate minimum singular value.
107  smin = fabsf( *buff_d );
108 
109  // Skip the accumulation of smin if the first element is zero.
110  if ( smin != zero )
111  {
112  mu = smin;
113  for ( i = 1; i < n_A; ++i )
114  {
115  float* epsilon1 = buff_e + (i-1)*inc_e;
116  float* delta2 = buff_d + (i )*inc_d;
117 
118  mu = fabsf( *delta2 ) * ( mu / ( mu + fabsf( *epsilon1 ) ) );
119  smin = min( smin, mu );
120 
121  // Stop early if we encountered a zero.
122  if ( smin == zero ) break;
123  }
124  }
125 
126  // Compute thresh either in terms of tol or as a function of the
127  // maximum total number of iterations, the problem size, and the
128  // safe minimum.
129  smin = smin / sqrtf( ( float ) n_A );
130  *thresh = max( *tol * smin, maxitr * n_A * n_A * unfl );
131 
132  return FLA_SUCCESS;
133 }
int i
Definition: bl1_axmyv2.c:145
float FLA_Mach_params_ops(FLA_Machval machval)
Definition: FLA_Mach_params.c:47
float bl1_s0(void)
Definition: bl1_constants.c:111