OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableFunctionsCommon.cpp File Reference
#include "TableFunctionsCommon.hpp"
#include <filesystem>
#include <memory>
#include <regex>
#include <string>
#include <tbb/parallel_for.h>
#include <tbb/task_arena.h>
+ Include dependency graph for TableFunctionsCommon.cpp:

Go to the source code of this file.

Namespaces

 FileUtilities
 

Macros

#define NANOSECONDS_PER_SECOND   1000000000
 

Functions

template<typename T >
NEVER_INLINE HOST std::pair< T, T > get_column_min_max (const Column< T > &col)
 
template NEVER_INLINE HOST
std::pair< int8_t, int8_t > 
get_column_min_max (const Column< int8_t > &col)
 
template NEVER_INLINE HOST
std::pair< int16_t, int16_t > 
get_column_min_max (const Column< int16_t > &col)
 
template NEVER_INLINE HOST
std::pair< int32_t, int32_t > 
get_column_min_max (const Column< int32_t > &col)
 
template NEVER_INLINE HOST
std::pair< int64_t, int64_t > 
get_column_min_max (const Column< int64_t > &col)
 
template NEVER_INLINE HOST
std::pair< float, float > 
get_column_min_max (const Column< float > &col)
 
template NEVER_INLINE HOST
std::pair< double, double > 
get_column_min_max (const Column< double > &col)
 
std::pair< int32_t, int32_t > get_column_min_max (const Column< TextEncodingDict > &col)
 
template<typename T >
NEVER_INLINE HOST double get_column_mean (const T *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const int8_t *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const int16_t *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const int32_t *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const int64_t *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const float *data, const int64_t num_rows)
 
template NEVER_INLINE HOST double get_column_mean (const double *data, const int64_t num_rows)
 
template<typename T >
NEVER_INLINE HOST double get_column_mean (const Column< T > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< int8_t > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< int16_t > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< int32_t > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< int64_t > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< float > &col)
 
template NEVER_INLINE HOST double get_column_mean (const Column< double > &col)
 
template<typename T >
NEVER_INLINE HOST double get_column_std_dev (const Column< T > &col, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const Column< int32_t > &col, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const Column< int64_t > &col, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const Column< float > &col, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const Column< double > &col, const double mean)
 
template<typename T >
NEVER_INLINE HOST double get_column_std_dev (const T *data, const int64_t num_rows, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const int32_t *data, const int64_t num_rows, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const int64_t *data, const int64_t num_rows, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const float *data, const int64_t num_rows, const double mean)
 
template NEVER_INLINE HOST double get_column_std_dev (const double *data, const int64_t num_rows, const double mean)
 
template<typename T >
NEVER_INLINE HOST std::tuple
< T, T, bool > 
get_column_metadata (const Column< T > &col)
 
template NEVER_INLINE HOST
std::tuple< int8_t, int8_t,
bool > 
get_column_metadata (const Column< int8_t > &col)
 
template NEVER_INLINE HOST
std::tuple< int16_t, int16_t,
bool > 
get_column_metadata (const Column< int16_t > &col)
 
template NEVER_INLINE HOST
std::tuple< int32_t, int32_t,
bool > 
get_column_metadata (const Column< int32_t > &col)
 
template NEVER_INLINE HOST
std::tuple< int64_t, int64_t,
bool > 
get_column_metadata (const Column< int64_t > &col)
 
template NEVER_INLINE HOST
std::tuple< float, float, bool > 
get_column_metadata (const Column< float > &col)
 
template NEVER_INLINE HOST
std::tuple< double, double,
bool > 
get_column_metadata (const Column< double > &col)
 
std::tuple< int32_t, int32_t,
bool > 
get_column_metadata (const Column< TextEncodingDict > &col)
 
template<typename T >
void z_std_normalize_col (const T *input_data, T *output_data, const int64_t num_rows, const double mean, const double std_dev)
 
template void z_std_normalize_col (const float *input_data, float *output_data, const int64_t num_rows, const double mean, const double std_dev)
 
template void z_std_normalize_col (const double *input_data, double *output_data, const int64_t num_rows, const double mean, const double std_dev)
 
template<typename T >
std::vector< std::vector< T > > z_std_normalize_data (const std::vector< T * > &input_data, const int64_t num_rows)
 
template std::vector
< std::vector< float > > 
z_std_normalize_data (const std::vector< float * > &input_data, const int64_t num_rows)
 
template std::vector
< std::vector< double > > 
z_std_normalize_data (const std::vector< double * > &input_data, const int64_t num_rows)
 
template<typename T >
ZStdNormalizationSummaryStats< T > z_std_normalize_data_with_summary_stats (const std::vector< T * > &input_data, const int64_t num_rows)
 
template
ZStdNormalizationSummaryStats
< float > 
z_std_normalize_data_with_summary_stats (const std::vector< float * > &input_data, const int64_t num_rows)
 
template
ZStdNormalizationSummaryStats
< double > 
z_std_normalize_data_with_summary_stats (const std::vector< double * > &input_data, const int64_t num_rows)
 
template<typename T1 , typename T2 >
NEVER_INLINE HOST T1 distance_in_meters (const T1 fromlon, const T1 fromlat, const T2 tolon, const T2 tolat)
 
template NEVER_INLINE HOST float distance_in_meters (const float fromlon, const float fromlat, const float tolon, const float tolat)
 
template NEVER_INLINE HOST float distance_in_meters (const float fromlon, const float fromlat, const double tolon, const double tolat)
 
template NEVER_INLINE HOST double distance_in_meters (const double fromlon, const double fromlat, const float tolon, const float tolat)
 
template NEVER_INLINE HOST double distance_in_meters (const double fromlon, const double fromlat, const double tolon, const double tolat)
 Computes the distance, in meters, between two WGS-84 positions. More...
 
std::regex FileUtilities::glob_to_regex (const std::string &glob, bool case_sensitive=false)
 
std::vector
< std::filesystem::path > 
FileUtilities::get_fs_paths (const std::string &file_or_directory)
 
template<typename T >
NEVER_INLINE HOST bool is_valid_tf_input (const T input, const T bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 
template NEVER_INLINE HOST bool is_valid_tf_input (const int32_t input, const int32_t bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 
template NEVER_INLINE HOST bool is_valid_tf_input (const int64_t input, const int64_t bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 
template NEVER_INLINE HOST bool is_valid_tf_input (const float input, const float bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 
template NEVER_INLINE HOST bool is_valid_tf_input (const double input, const double bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 

Macro Definition Documentation

#define NANOSECONDS_PER_SECOND   1000000000

Definition at line 29 of file TableFunctionsCommon.cpp.

Function Documentation

template<typename T1 , typename T2 >
NEVER_INLINE HOST T1 distance_in_meters ( const T1  fromlon,
const T1  fromlat,
const T2  tolon,
const T2  tolat 
)

Definition at line 452 of file TableFunctionsCommon.cpp.

452  {
453  T1 latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
454  T1 longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
455  T1 latitudeH = sin(latitudeArc * 0.5);
456  latitudeH *= latitudeH;
457  T1 lontitudeH = sin(longitudeArc * 0.5);
458  lontitudeH *= lontitudeH;
459  T1 tmp = cos(fromlat * 0.017453292519943295769236907684886) *
460  cos(tolat * 0.017453292519943295769236907684886);
461  return 6372797.560856 * (2.0 * asin(sqrt(latitudeH + tmp * lontitudeH)));
462 }
template NEVER_INLINE HOST float distance_in_meters ( const float  fromlon,
const float  fromlat,
const float  tolon,
const float  tolat 
)
template NEVER_INLINE HOST float distance_in_meters ( const float  fromlon,
const float  fromlat,
const double  tolon,
const double  tolat 
)
template NEVER_INLINE HOST double distance_in_meters ( const double  fromlon,
const double  fromlat,
const float  tolon,
const float  tolat 
)
template NEVER_INLINE HOST double distance_in_meters ( const double  fromlon,
const double  fromlat,
const double  tolon,
const double  tolat 
)

Computes the distance, in meters, between two WGS-84 positions.

The result is equal to EARTH_RADIUS_IN_METERS*ArcInRadians(from,to)

ArcInRadians is equal to Distance(from,to)/EARTH_RADIUS_IN_METERS = 2*asin(sqrt(h(d/EARTH_RADIUS_IN_METERS )))

where:

  • d is the distance in meters between 'from' and 'to' positions.
  • h is the haversine function: h(x)=sinĀ²(x/2)

code attribution: http://blog.julien.cayzac.name/2008/10/arc-and-distance-between-two-points-on.html

The haversine formula gives: h(d/R) = h(from.lat-to.lat)+h(from.lon-to.lon)+cos(from.lat)*cos(to.lat)

See Also
http://en.wikipedia.org/wiki/Law_of_haversines

Definition at line 433 of file ExtensionFunctions.hpp.

Referenced by GeoRaster< T, Z >::calculate_bins_and_scales(), length_linestring(), ST_Distance_Point_LineString_Geodesic(), and ST_Distance_Point_Point_Geodesic().

436  {
437  double latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
438  double longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
439  double latitudeH = sin(latitudeArc * 0.5);
440  latitudeH *= latitudeH;
441  double lontitudeH = sin(longitudeArc * 0.5);
442  lontitudeH *= lontitudeH;
443  double tmp = cos(fromlat * 0.017453292519943295769236907684886) *
444  cos(tolat * 0.017453292519943295769236907684886);
445  return 6372797.560856 * (2.0 * asin(sqrt(latitudeH + tmp * lontitudeH)));
446 }

+ Here is the caller graph for this function:

template<typename T >
NEVER_INLINE HOST double get_column_mean ( const T *  data,
const int64_t  num_rows 
)

Definition at line 116 of file TableFunctionsCommon.cpp.

References max_inputs_per_thread, threading_serial::parallel_for(), and heavydb.dtypes::T.

Referenced by get_column_mean(), r2_score_impl(), z_std_normalize_data(), and z_std_normalize_data_with_summary_stats().

116  {
117  // const int64_t num_rows = col.size();
118  const size_t max_thread_count = std::thread::hardware_concurrency();
119  const size_t max_inputs_per_thread = 20000;
120  const size_t num_threads = std::min(
121  max_thread_count, ((num_rows + max_inputs_per_thread - 1) / max_inputs_per_thread));
122 
123  std::vector<double> local_col_sums(num_threads, 0.);
124  std::vector<int64_t> local_col_non_null_counts(num_threads, 0L);
125  tbb::task_arena limited_arena(num_threads);
126  limited_arena.execute([&] {
128  tbb::blocked_range<int64_t>(0, num_rows),
129  [&](const tbb::blocked_range<int64_t>& r) {
130  const int64_t start_idx = r.begin();
131  const int64_t end_idx = r.end();
132  double local_col_sum = 0.;
133  int64_t local_col_non_null_count = 0;
134  for (int64_t r = start_idx; r < end_idx; ++r) {
135  const T val = data[r];
136  if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
137  if (std::isnan(val) || std::isinf(val)) {
138  continue;
139  }
140  }
141  if (val == inline_null_value<T>()) {
142  continue;
143  }
144  local_col_sum += data[r];
145  local_col_non_null_count++;
146  }
147  size_t thread_idx = tbb::this_task_arena::current_thread_index();
148  local_col_sums[thread_idx] += local_col_sum;
149  local_col_non_null_counts[thread_idx] += local_col_non_null_count;
150  });
151  });
152 
153  double col_sum = 0.0;
154  int64_t col_non_null_count = 0L;
155 
156  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
157  col_sum += local_col_sums[thread_idx];
158  col_non_null_count += local_col_non_null_counts[thread_idx];
159  }
160 
161  return col_non_null_count == 0 ? 0 : col_sum / col_non_null_count;
162 }
const size_t max_inputs_per_thread
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template NEVER_INLINE HOST double get_column_mean ( const int8_t *  data,
const int64_t  num_rows 
)
template NEVER_INLINE HOST double get_column_mean ( const int16_t *  data,
const int64_t  num_rows 
)
template NEVER_INLINE HOST double get_column_mean ( const int32_t *  data,
const int64_t  num_rows 
)
template NEVER_INLINE HOST double get_column_mean ( const int64_t *  data,
const int64_t  num_rows 
)
template NEVER_INLINE HOST double get_column_mean ( const float *  data,
const int64_t  num_rows 
)
template NEVER_INLINE HOST double get_column_mean ( const double *  data,
const int64_t  num_rows 
)
template<typename T >
NEVER_INLINE HOST double get_column_mean ( const Column< T > &  col)

Definition at line 183 of file TableFunctionsCommon.cpp.

References get_column_mean(), Column< T >::getPtr(), and Column< T >::size().

183  {
184  return get_column_mean(col.getPtr(), col.size());
185 }
DEVICE int64_t size() const
DEVICE T * getPtr() const
NEVER_INLINE HOST double get_column_mean(const T *data, const int64_t num_rows)

+ Here is the call graph for this function:

template NEVER_INLINE HOST double get_column_mean ( const Column< int8_t > &  col)
template NEVER_INLINE HOST double get_column_mean ( const Column< int16_t > &  col)
template NEVER_INLINE HOST double get_column_mean ( const Column< int32_t > &  col)
template NEVER_INLINE HOST double get_column_mean ( const Column< int64_t > &  col)
template NEVER_INLINE HOST double get_column_mean ( const Column< float > &  col)
template NEVER_INLINE HOST double get_column_mean ( const Column< double > &  col)
template<typename T >
NEVER_INLINE HOST std::tuple<T, T, bool> get_column_metadata ( const Column< T > &  col)

Definition at line 276 of file TableFunctionsCommon.cpp.

References Column< T >::isNull(), max_inputs_per_thread, threading_serial::parallel_for(), Column< T >::size(), and heavydb.dtypes::T.

Referenced by get_column_metadata().

276  {
277  T col_min = std::numeric_limits<T>::max();
278  T col_max = std::numeric_limits<T>::lowest();
279  bool has_nulls = false;
280  const int64_t num_rows = col.size();
281  const size_t max_thread_count = std::thread::hardware_concurrency();
282  const size_t max_inputs_per_thread = 200000;
283  const size_t num_threads = std::min(
284  max_thread_count, ((num_rows + max_inputs_per_thread - 1) / max_inputs_per_thread));
285 
286  std::vector<T> local_col_mins(num_threads, std::numeric_limits<T>::max());
287  std::vector<T> local_col_maxes(num_threads, std::numeric_limits<T>::lowest());
288  std::vector<bool> local_col_has_nulls(num_threads, false);
289  tbb::task_arena limited_arena(num_threads);
290 
291  limited_arena.execute([&] {
293  tbb::blocked_range<int64_t>(0, num_rows),
294  [&](const tbb::blocked_range<int64_t>& r) {
295  const int64_t start_idx = r.begin();
296  const int64_t end_idx = r.end();
297  T local_col_min = std::numeric_limits<T>::max();
298  T local_col_max = std::numeric_limits<T>::lowest();
299  bool local_has_nulls = false;
300  for (int64_t r = start_idx; r < end_idx; ++r) {
301  const T val = col[r];
302  if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
303  if (std::isnan(val) || std::isinf(val)) {
304  continue;
305  }
306  }
307  if (col.isNull(r)) {
308  local_has_nulls = true;
309  continue;
310  }
311  if (val < local_col_min) {
312  local_col_min = val;
313  }
314  if (val > local_col_max) {
315  local_col_max = val;
316  }
317  }
318  const size_t thread_idx = tbb::this_task_arena::current_thread_index();
319  if (local_has_nulls) {
320  local_col_has_nulls[thread_idx] = true;
321  }
322  if (local_col_min < local_col_mins[thread_idx]) {
323  local_col_mins[thread_idx] = local_col_min;
324  }
325  if (local_col_max > local_col_maxes[thread_idx]) {
326  local_col_maxes[thread_idx] = local_col_max;
327  }
328  });
329  });
330 
331  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
332  if (local_col_has_nulls[thread_idx]) {
333  has_nulls = true;
334  }
335  if (local_col_mins[thread_idx] < col_min) {
336  col_min = local_col_mins[thread_idx];
337  }
338  if (local_col_maxes[thread_idx] > col_max) {
339  col_max = local_col_maxes[thread_idx];
340  }
341  }
342  return {col_min, col_max, has_nulls};
343 }
DEVICE int64_t size() const
const size_t max_inputs_per_thread
DEVICE bool isNull(int64_t index) const
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template NEVER_INLINE HOST std::tuple<int8_t, int8_t, bool> get_column_metadata ( const Column< int8_t > &  col)
template NEVER_INLINE HOST std::tuple<int16_t, int16_t, bool> get_column_metadata ( const Column< int16_t > &  col)
template NEVER_INLINE HOST std::tuple<int32_t, int32_t, bool> get_column_metadata ( const Column< int32_t > &  col)
template NEVER_INLINE HOST std::tuple<int64_t, int64_t, bool> get_column_metadata ( const Column< int64_t > &  col)
template NEVER_INLINE HOST std::tuple<float, float, bool> get_column_metadata ( const Column< float > &  col)
template NEVER_INLINE HOST std::tuple<double, double, bool> get_column_metadata ( const Column< double > &  col)
std::tuple<int32_t, int32_t, bool> get_column_metadata ( const Column< TextEncodingDict > &  col)

Definition at line 358 of file TableFunctionsCommon.cpp.

References get_column_metadata(), Column< TextEncodingDict >::getPtr(), and Column< TextEncodingDict >::size().

359  {
360  Column<int32_t> int_alias_col(reinterpret_cast<int32_t*>(col.getPtr()), col.size());
361  return get_column_metadata(int_alias_col);
362 }
DEVICE TextEncodingDict * getPtr() const
NEVER_INLINE HOST std::tuple< T, T, bool > get_column_metadata(const Column< T > &col)
DEVICE int64_t size() const

+ Here is the call graph for this function:

template<typename T >
NEVER_INLINE HOST std::pair<T, T> get_column_min_max ( const Column< T > &  col)

Definition at line 32 of file TableFunctionsCommon.cpp.

References max_inputs_per_thread, threading_serial::parallel_for(), Column< T >::size(), and heavydb.dtypes::T.

Referenced by ct_union_pushdown_stats__cpu_template(), RasterFormat_Namespace::format_raster_data(), GeoRaster< T, Z >::GeoRaster(), get_column_min_max(), get_min_or_max(), get_min_or_max_union(), and TableFunctions_Namespace::OneHotEncoder_Namespace::get_top_k_keys().

32  {
33  T col_min = std::numeric_limits<T>::max();
34  T col_max = std::numeric_limits<T>::lowest();
35  const int64_t num_rows = col.size();
36  const size_t max_thread_count = std::thread::hardware_concurrency();
37  const size_t max_inputs_per_thread = 20000;
38  const size_t num_threads = std::min(
39  max_thread_count, ((num_rows + max_inputs_per_thread - 1) / max_inputs_per_thread));
40 
41  std::vector<T> local_col_mins(num_threads, std::numeric_limits<T>::max());
42  std::vector<T> local_col_maxes(num_threads, std::numeric_limits<T>::lowest());
43  tbb::task_arena limited_arena(num_threads);
44 
45  limited_arena.execute([&] {
47  tbb::blocked_range<int64_t>(0, num_rows),
48  [&](const tbb::blocked_range<int64_t>& r) {
49  const int64_t start_idx = r.begin();
50  const int64_t end_idx = r.end();
51  T local_col_min = std::numeric_limits<T>::max();
52  T local_col_max = std::numeric_limits<T>::lowest();
53  for (int64_t r = start_idx; r < end_idx; ++r) {
54  const T val = col[r];
55  if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
56  if (std::isnan(val) || std::isinf(val)) {
57  continue;
58  }
59  }
60  if (val == inline_null_value<T>()) {
61  continue;
62  }
63  if (val < local_col_min) {
64  local_col_min = val;
65  }
66  if (val > local_col_max) {
67  local_col_max = val;
68  }
69  }
70  size_t thread_idx = tbb::this_task_arena::current_thread_index();
71  if (local_col_min < local_col_mins[thread_idx]) {
72  local_col_mins[thread_idx] = local_col_min;
73  }
74  if (local_col_max > local_col_maxes[thread_idx]) {
75  local_col_maxes[thread_idx] = local_col_max;
76  }
77  });
78  });
79 
80  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
81  if (local_col_mins[thread_idx] < col_min) {
82  col_min = local_col_mins[thread_idx];
83  }
84  if (local_col_maxes[thread_idx] > col_max) {
85  col_max = local_col_maxes[thread_idx];
86  }
87  }
88  return std::make_pair(col_min, col_max);
89 }
DEVICE int64_t size() const
const size_t max_inputs_per_thread
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template NEVER_INLINE HOST std::pair<int8_t, int8_t> get_column_min_max ( const Column< int8_t > &  col)
template NEVER_INLINE HOST std::pair<int16_t, int16_t> get_column_min_max ( const Column< int16_t > &  col)
template NEVER_INLINE HOST std::pair<int32_t, int32_t> get_column_min_max ( const Column< int32_t > &  col)
template NEVER_INLINE HOST std::pair<int64_t, int64_t> get_column_min_max ( const Column< int64_t > &  col)
template NEVER_INLINE HOST std::pair<float, float> get_column_min_max ( const Column< float > &  col)
template NEVER_INLINE HOST std::pair<double, double> get_column_min_max ( const Column< double > &  col)
std::pair<int32_t, int32_t> get_column_min_max ( const Column< TextEncodingDict > &  col)

Definition at line 104 of file TableFunctionsCommon.cpp.

References get_column_min_max(), Column< TextEncodingDict >::getPtr(), and Column< TextEncodingDict >::size().

104  {
105  Column<int32_t> int_alias_col(reinterpret_cast<int32_t*>(col.getPtr()), col.size());
106  return get_column_min_max(int_alias_col);
107 }
NEVER_INLINE HOST std::pair< T, T > get_column_min_max(const Column< T > &col)
DEVICE TextEncodingDict * getPtr() const
DEVICE int64_t size() const

+ Here is the call graph for this function:

template<typename T >
NEVER_INLINE HOST double get_column_std_dev ( const Column< T > &  col,
const double  mean 
)

Definition at line 195 of file TableFunctionsCommon.cpp.

References get_column_std_dev(), Column< T >::getPtr(), and Column< T >::size().

Referenced by get_column_std_dev(), z_std_normalize_data(), and z_std_normalize_data_with_summary_stats().

195  {
196  return get_column_std_dev(col.getPtr(), col.size(), mean);
197 }
DEVICE int64_t size() const
DEVICE T * getPtr() const
NEVER_INLINE HOST double get_column_std_dev(const Column< T > &col, const double mean)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template NEVER_INLINE HOST double get_column_std_dev ( const Column< int32_t > &  col,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const Column< int64_t > &  col,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const Column< float > &  col,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const Column< double > &  col,
const double  mean 
)
template<typename T >
NEVER_INLINE HOST double get_column_std_dev ( const T *  data,
const int64_t  num_rows,
const double  mean 
)

Definition at line 209 of file TableFunctionsCommon.cpp.

References max_inputs_per_thread, threading_serial::parallel_for(), and heavydb.dtypes::T.

211  {
212  // const int64_t num_rows = col.size();
213  const size_t max_thread_count = std::thread::hardware_concurrency();
214  const size_t max_inputs_per_thread = 200000;
215  const size_t num_threads = std::min(
216  max_thread_count, ((num_rows + max_inputs_per_thread - 1) / max_inputs_per_thread));
217 
218  std::vector<double> local_col_squared_residuals(num_threads, 0.);
219  std::vector<int64_t> local_col_non_null_counts(num_threads, 0L);
220  tbb::task_arena limited_arena(num_threads);
221 
222  limited_arena.execute([&] {
224  tbb::blocked_range<int64_t>(0, num_rows),
225  [&](const tbb::blocked_range<int64_t>& r) {
226  const int64_t start_idx = r.begin();
227  const int64_t end_idx = r.end();
228  double local_col_squared_residual = 0.;
229  int64_t local_col_non_null_count = 0;
230  for (int64_t r = start_idx; r < end_idx; ++r) {
231  const T val = data[r];
232  if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>) {
233  if (std::isnan(val) || std::isinf(val)) {
234  continue;
235  }
236  }
237  if (val == inline_null_value<T>()) {
238  continue;
239  }
240  const double residual = val - mean;
241  local_col_squared_residual += (residual * residual);
242  local_col_non_null_count++;
243  }
244  size_t thread_idx = tbb::this_task_arena::current_thread_index();
245  local_col_squared_residuals[thread_idx] += local_col_squared_residual;
246  local_col_non_null_counts[thread_idx] += local_col_non_null_count;
247  });
248  });
249 
250  double col_sum_squared_residual = 0.0;
251  int64_t col_non_null_count = 0;
252 
253  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
254  col_sum_squared_residual += local_col_squared_residuals[thread_idx];
255  col_non_null_count += local_col_non_null_counts[thread_idx];
256  }
257 
258  return col_non_null_count == 0 ? 0
259  : sqrt(col_sum_squared_residual / col_non_null_count);
260 }
const size_t max_inputs_per_thread
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

template NEVER_INLINE HOST double get_column_std_dev ( const int32_t *  data,
const int64_t  num_rows,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const int64_t *  data,
const int64_t  num_rows,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const float *  data,
const int64_t  num_rows,
const double  mean 
)
template NEVER_INLINE HOST double get_column_std_dev ( const double *  data,
const int64_t  num_rows,
const double  mean 
)
template<typename T >
NEVER_INLINE HOST bool is_valid_tf_input ( const T  input,
const T  bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)

Definition at line 556 of file TableFunctionsCommon.cpp.

References Exclusive, Inclusive, Max, Min, and UNREACHABLE.

559  {
560  switch (bounds_type) {
561  case BoundsType::Min:
562  switch (interval_type) {
564  return input >= bounds_val;
566  return input > bounds_val;
567  default:
568  UNREACHABLE();
569  }
570  case BoundsType::Max:
571  switch (interval_type) {
573  return input <= bounds_val;
575  return input < bounds_val;
576  default:
577  UNREACHABLE();
578  }
579  break;
580  default:
581  UNREACHABLE();
582  }
583  UNREACHABLE();
584  return false; // To address compiler warning
585 }
#define UNREACHABLE()
Definition: Logger.h:338
template NEVER_INLINE HOST bool is_valid_tf_input ( const int32_t  input,
const int32_t  bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)
template NEVER_INLINE HOST bool is_valid_tf_input ( const int64_t  input,
const int64_t  bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)
template NEVER_INLINE HOST bool is_valid_tf_input ( const float  input,
const float  bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)
template NEVER_INLINE HOST bool is_valid_tf_input ( const double  input,
const double  bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)
template<typename T >
void z_std_normalize_col ( const T *  input_data,
T *  output_data,
const int64_t  num_rows,
const double  mean,
const double  std_dev 
)

Definition at line 365 of file TableFunctionsCommon.cpp.

References threading_serial::parallel_for().

Referenced by z_std_normalize_data(), and z_std_normalize_data_with_summary_stats().

369  {
370  if (std_dev <= 0.0) {
371  throw std::runtime_error("Standard deviation cannot be <= 0");
372  }
373  const double inv_std_dev = 1.0 / std_dev;
374 
375  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_rows),
376  [&](const tbb::blocked_range<int64_t>& r) {
377  const int64_t start_idx = r.begin();
378  const int64_t end_idx = r.end();
379  for (int64_t row_idx = start_idx; row_idx < end_idx; ++row_idx) {
380  output_data[row_idx] = (input_data[row_idx] - mean) * inv_std_dev;
381  }
382  });
383 }
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template void z_std_normalize_col ( const float *  input_data,
float *  output_data,
const int64_t  num_rows,
const double  mean,
const double  std_dev 
)
template void z_std_normalize_col ( const double *  input_data,
double *  output_data,
const int64_t  num_rows,
const double  mean,
const double  std_dev 
)
template<typename T >
std::vector<std::vector<T> > z_std_normalize_data ( const std::vector< T * > &  input_data,
const int64_t  num_rows 
)

Definition at line 397 of file TableFunctionsCommon.cpp.

References get_column_mean(), get_column_std_dev(), and z_std_normalize_col().

Referenced by dbscan__cpu_template(), and kmeans__cpu_template().

398  {
399  const int64_t num_features = input_data.size();
400  std::vector<std::vector<T>> normalized_data(num_features);
401  for (int64_t feature_idx = 0; feature_idx < num_features; ++feature_idx) {
402  const auto mean = get_column_mean(input_data[feature_idx], num_rows);
403  const auto std_dev = get_column_std_dev(input_data[feature_idx], num_rows, mean);
404  normalized_data[feature_idx].resize(num_rows);
405  z_std_normalize_col(input_data[feature_idx],
406  normalized_data[feature_idx].data(),
407  num_rows,
408  mean,
409  std_dev);
410  }
411  return normalized_data;
412 }
void z_std_normalize_col(const T *input_data, T *output_data, const int64_t num_rows, const double mean, const double std_dev)
NEVER_INLINE HOST double get_column_std_dev(const Column< T > &col, const double mean)
NEVER_INLINE HOST double get_column_mean(const T *data, const int64_t num_rows)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template std::vector<std::vector<float> > z_std_normalize_data ( const std::vector< float * > &  input_data,
const int64_t  num_rows 
)
template std::vector<std::vector<double> > z_std_normalize_data ( const std::vector< double * > &  input_data,
const int64_t  num_rows 
)
template<typename T >
ZStdNormalizationSummaryStats<T> z_std_normalize_data_with_summary_stats ( const std::vector< T * > &  input_data,
const int64_t  num_rows 
)

Definition at line 422 of file TableFunctionsCommon.cpp.

References get_column_mean(), get_column_std_dev(), and z_std_normalize_col().

Referenced by pca_fit_impl().

424  {
425  const int64_t num_features = input_data.size();
426  std::vector<std::vector<T>> normalized_data(num_features);
427  std::vector<T> means(num_features);
428  std::vector<T> std_devs(num_features);
429  for (int64_t feature_idx = 0; feature_idx < num_features; ++feature_idx) {
430  means[feature_idx] = get_column_mean(input_data[feature_idx], num_rows);
431  std_devs[feature_idx] =
432  get_column_std_dev(input_data[feature_idx], num_rows, means[feature_idx]);
433  normalized_data[feature_idx].resize(num_rows);
434  z_std_normalize_col(input_data[feature_idx],
435  normalized_data[feature_idx].data(),
436  num_rows,
437  means[feature_idx],
438  std_devs[feature_idx]);
439  }
440  return ZStdNormalizationSummaryStats<T>(normalized_data, means, std_devs);
441 }
void z_std_normalize_col(const T *input_data, T *output_data, const int64_t num_rows, const double mean, const double std_dev)
NEVER_INLINE HOST double get_column_std_dev(const Column< T > &col, const double mean)
NEVER_INLINE HOST double get_column_mean(const T *data, const int64_t num_rows)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template ZStdNormalizationSummaryStats<float> z_std_normalize_data_with_summary_stats ( const std::vector< float * > &  input_data,
const int64_t  num_rows 
)
template ZStdNormalizationSummaryStats<double> z_std_normalize_data_with_summary_stats ( const std::vector< double * > &  input_data,
const int64_t  num_rows 
)