libflame  revision_anchor
Functions
FLA_Sort.c File Reference

(r)

Functions

int fla_scomp_f (const void *a, const void *b)
 
int fla_scomp_b (const void *a, const void *b)
 
int fla_dcomp_f (const void *a, const void *b)
 
int fla_dcomp_b (const void *a, const void *b)
 
FLA_Error FLA_Sort (FLA_Direct direct, FLA_Obj x)
 
FLA_Error FLA_Sort_f_ops (int m_x, float *x, int inc_x)
 
FLA_Error FLA_Sort_b_ops (int m_x, float *x, int inc_x)
 
FLA_Error FLA_Sort_f_opd (int m_x, double *x, int inc_x)
 
FLA_Error FLA_Sort_b_opd (int m_x, double *x, int inc_x)
 

Function Documentation

◆ fla_dcomp_b()

int fla_dcomp_b ( const void *  a,
const void *  b 
)

Referenced by FLA_Sort_b_opd().

176 {
177  double* da = ( double* ) a;
178  double* db = ( double* ) b;
179  int r_val;
180 
181  if ( *da < *db ) r_val = 1;
182  else if ( *da > *db ) r_val = -1;
183  else r_val = 0;
184 
185  return r_val;
186 }

◆ fla_dcomp_f()

int fla_dcomp_f ( const void *  a,
const void *  b 
)

Referenced by FLA_Sort_f_opd().

163 {
164  double* da = ( double* ) a;
165  double* db = ( double* ) b;
166  int r_val;
167 
168  if ( *da < *db ) r_val = -1;
169  else if ( *da > *db ) r_val = 1;
170  else r_val = 0;
171 
172  return r_val;
173 }

◆ fla_scomp_b()

int fla_scomp_b ( const void *  a,
const void *  b 
)

Referenced by FLA_Sort_b_ops().

150 {
151  float* da = ( float* ) a;
152  float* db = ( float* ) b;
153  int r_val;
154 
155  if ( *da < *db ) r_val = 1;
156  else if ( *da > *db ) r_val = -1;
157  else r_val = 0;
158 
159  return r_val;
160 }

◆ fla_scomp_f()

int fla_scomp_f ( const void *  a,
const void *  b 
)

Referenced by FLA_Sort_f_ops().

137 {
138  float* da = ( float* ) a;
139  float* db = ( float* ) b;
140  int r_val;
141 
142  if ( *da < *db ) r_val = -1;
143  else if ( *da > *db ) r_val = 1;
144  else r_val = 0;
145 
146  return r_val;
147 }

◆ FLA_Sort()

FLA_Error FLA_Sort ( FLA_Direct  direct,
FLA_Obj  x 
)

References FLA_Check_error_level(), FLA_Copy(), FLA_Obj_create_copy_of(), FLA_Obj_datatype(), FLA_Obj_free(), FLA_Obj_vector_dim(), FLA_Obj_vector_inc(), FLA_Sort_b_opd(), FLA_Sort_b_ops(), FLA_Sort_check(), FLA_Sort_f_opd(), and FLA_Sort_f_ops().

Referenced by FLA_Fill_with_cluster_dist(), and FLA_Sort_bsvd_ext().

19 {
20  FLA_Datatype datatype;
21  FLA_Obj x_use;
22  dim_t m_x;
23  dim_t inc_x;
24 
25  if ( FLA_Check_error_level() >= FLA_MIN_ERROR_CHECKING )
26  FLA_Sort_check( direct, x );
27 
28  datatype = FLA_Obj_datatype( x );
29 
30  m_x = FLA_Obj_vector_dim( x );
31  inc_x = FLA_Obj_vector_inc( x );
32 
33  // If the vector does not have unit stride, copy it to a temporary vector
34  // that does have unit stride.
35  if ( inc_x != 1 )
36  {
37  FLA_Obj_create_copy_of( FLA_NO_TRANSPOSE, x, &x_use );
38  inc_x = FLA_Obj_vector_inc( x_use );
39  }
40  else
41  {
42  x_use = x;
43  }
44 
45  switch ( datatype )
46  {
47  case FLA_FLOAT:
48  {
49  float* x_p = ( float* ) FLA_FLOAT_PTR( x_use );
50 
51  if ( direct == FLA_FORWARD )
52  FLA_Sort_f_ops( m_x,
53  x_p, inc_x );
54  else // if ( direct == FLA_BACKWARD )
55  FLA_Sort_b_ops( m_x,
56  x_p, inc_x );
57 
58  break;
59  }
60 
61  case FLA_DOUBLE:
62  {
63  double* x_p = ( double* ) FLA_DOUBLE_PTR( x_use );
64 
65  if ( direct == FLA_FORWARD )
66  FLA_Sort_f_opd( m_x,
67  x_p, inc_x );
68  else // if ( direct == FLA_BACKWARD )
69  FLA_Sort_b_opd( m_x,
70  x_p, inc_x );
71 
72  break;
73  }
74 
75  }
76 
77  if ( inc_x != 1 )
78  {
79  FLA_Copy( x_use, x );
80  FLA_Obj_free( &x_use );
81  }
82 
83  return FLA_SUCCESS;
84 }
FLA_Error FLA_Sort_f_opd(int m_x, double *x, int inc_x)
Definition: FLA_Sort.c:110
unsigned long dim_t
Definition: FLA_type_defs.h:71
FLA_Error FLA_Obj_free(FLA_Obj *obj)
Definition: FLA_Obj.c:588
FLA_Error FLA_Sort_b_ops(int m_x, float *x, int inc_x)
Definition: FLA_Sort.c:99
FLA_Error FLA_Copy(FLA_Obj A, FLA_Obj B)
Definition: FLA_Copy.c:15
FLA_Error FLA_Obj_create_copy_of(FLA_Trans trans, FLA_Obj old, FLA_Obj *obj)
Definition: FLA_Obj.c:345
FLA_Datatype FLA_Obj_datatype(FLA_Obj obj)
Definition: FLA_Query.c:13
FLA_Error FLA_Sort_b_opd(int m_x, double *x, int inc_x)
Definition: FLA_Sort.c:121
FLA_Error FLA_Sort_f_ops(int m_x, float *x, int inc_x)
Definition: FLA_Sort.c:88
Definition: FLA_type_defs.h:158
FLA_Error FLA_Sort_check(FLA_Direct direct, FLA_Obj x)
Definition: FLA_Sort_check.c:13
dim_t FLA_Obj_vector_dim(FLA_Obj obj)
Definition: FLA_Query.c:137
unsigned int FLA_Check_error_level(void)
Definition: FLA_Check.c:18
int FLA_Datatype
Definition: FLA_type_defs.h:49
dim_t FLA_Obj_vector_inc(FLA_Obj obj)
Definition: FLA_Query.c:145

◆ FLA_Sort_b_opd()

FLA_Error FLA_Sort_b_opd ( int  m_x,
double *  x,
int  inc_x 
)

References fla_dcomp_b().

Referenced by FLA_Sort().

123 {
124  qsort( x,
125  m_x,
126  sizeof( double ),
127  fla_dcomp_b );
128 
129  return FLA_SUCCESS;
130 }
int fla_dcomp_b(const void *a, const void *b)
Definition: FLA_Sort.c:175

◆ FLA_Sort_b_ops()

FLA_Error FLA_Sort_b_ops ( int  m_x,
float *  x,
int  inc_x 
)

References fla_scomp_b().

Referenced by FLA_Sort().

101 {
102  qsort( x,
103  m_x,
104  sizeof( float ),
105  fla_scomp_b );
106 
107  return FLA_SUCCESS;
108 }
int fla_scomp_b(const void *a, const void *b)
Definition: FLA_Sort.c:149

◆ FLA_Sort_f_opd()

FLA_Error FLA_Sort_f_opd ( int  m_x,
double *  x,
int  inc_x 
)

References fla_dcomp_f().

Referenced by FLA_Sort().

112 {
113  qsort( x,
114  m_x,
115  sizeof( double ),
116  fla_dcomp_f );
117 
118  return FLA_SUCCESS;
119 }
int fla_dcomp_f(const void *a, const void *b)
Definition: FLA_Sort.c:162

◆ FLA_Sort_f_ops()

FLA_Error FLA_Sort_f_ops ( int  m_x,
float *  x,
int  inc_x 
)

References fla_scomp_f().

Referenced by FLA_Sort().

90 {
91  qsort( x,
92  m_x,
93  sizeof( float ),
94  fla_scomp_f );
95 
96  return FLA_SUCCESS;
97 }
int fla_scomp_f(const void *a, const void *b)
Definition: FLA_Sort.c:136