32 const int64_t num_rows = input.
size();
34 for (int64_t r = 0; r < num_rows; ++r) {
36 out[r] = input[r] * multiplier;
47 const float multiplier,
51 const double multiplier,
55 const int32_t multiplier,
59 const int64_t multiplier,
69 : null_value_(std::numeric_limits<
T>::lowest())
70 , null_value_mapped_(map_null_value(nulls_last)) {}
72 return nulls_last ? std::numeric_limits<T>::max() : std::numeric_limits<T>::lowest();
75 return val == null_value_ ? null_value_mapped_ : val;
77 bool operator()(
const T&
a,
const T& b) {
return mapValue(a) < mapValue(b); }
85 : null_value_(std::numeric_limits<
T>::lowest())
86 , null_value_mapped_(map_null_value(nulls_last)) {}
88 return nulls_last ? std::numeric_limits<T>::lowest() : std::numeric_limits<T>::max();
92 return val == null_value_ ? null_value_mapped_ : val;
95 bool operator()(
const T&
a,
const T& b) {
return mapValue(a) > mapValue(b); }
100 template <
typename T>
103 const bool sort_ascending,
104 const bool nulls_last,
106 const int64_t num_rows = input.
size();
109 if (sort_ascending) {
114 if (limit < 0 || limit > num_rows) {
124 const bool sort_ascending,
125 const bool nulls_last,
130 const bool sort_ascending,
131 const bool nulls_last,
136 const bool sort_ascending,
137 const bool nulls_last,
142 const bool sort_ascending,
143 const bool nulls_last,
148 const bool sort_ascending,
149 const bool nulls_last,
154 const bool sort_ascending,
155 const bool nulls_last,
160 template <
typename T>
163 if (y > (std::numeric_limits<T>::max() - x)) {
164 throw std::overflow_error(
"Addition overflow detected");
167 if (y < (std::numeric_limits<T>::min() - x)) {
168 throw std::underflow_error(
"Addition underflow detected");
176 template <
typename T>
179 int32_t output_num_rows = input.
numCols();
181 for (
int i = 0; i < output_num_rows; i++) {
184 for (
int j = 0; j < col.size(); j++) {
187 }
catch (
const std::exception& e) {
195 return output_num_rows;
212 #endif // #ifndef __CUDACC__
216 output[0] = std::chrono::duration_cast<std::chrono::milliseconds>(
217 std::chrono::system_clock::now().time_since_epoch())
221 output[2] = std::hash<std::thread::id>()(std::this_thread::get_id()) & 0xffff;
223 std::this_thread::sleep_for(std::chrono::seconds(seconds));
225 output[1] = std::chrono::duration_cast<std::chrono::milliseconds>(
226 std::chrono::system_clock::now().time_since_epoch())
242 mgr->set_output_row_size(3);
252 if (output.
size() == 0) {
275 mgr0->set_output_row_size(3);
276 }
catch (std::exception& e) {
277 return mgr.ERROR_MESSAGE(e.what());
282 return mgr.ERROR_MESSAGE(
"unexpected mode");
284 if (output.
size() == 0) {
285 return mgr.ERROR_MESSAGE(
"unspecified output columns row size");
290 template <
typename T>
294 int64_t num_rows = input.
size();
296 for (int64_t r = 0; r < num_rows; ++r) {
297 if (input[r] > 100) {
298 return mgr.ERROR_MESSAGE(
"Values greater than 100 not allowed");
300 output[r] = input[r];
319 for (int32_t i = 0; i < input.
size(); i++) {
320 output[i] = input[i] + input.
size();
322 return output.
size();
331 auto size = input1.
size();
333 for (int32_t i = 0; i < size; i++) {
334 output1[i] = input1[i] + size;
335 output2[i] = input2[i] * alpha;
357 std::set<int32_t, std::less<int32_t>> x12;
359 std::map<int32_t, int32_t, std::less<int32_t>> i1, i2;
361 for (int32_t i = 0; i < x1.
size(); i++) {
365 for (int32_t i = 0; i < x2.
size(); i++) {
369 auto size = x12.size();
373 for (
auto x_ : x12) {
375 auto i1_ = i1.find(x_);
376 auto i2_ = i2.find(x_);
377 if (i1_ != i1.end()) {
378 if (i2_ != i2.end()) {
379 d[k] = d1[i1_->second] + d2[i2_->second];
381 d[k] = d1[i1_->second] + f2;
383 }
else if (i2_ != i2.end()) {
384 d[k] = f1 + d2[i2_->second];
394 #endif // #ifndef __CUDACC__
399 ct_cuda_enumerate_threads__gpu_(
const int32_t output_size,
403 int32_t local_thread_id = threadIdx.x;
404 int32_t block_id = blockIdx.x;
405 int32_t global_thread_id = threadIdx.x + blockDim.x * blockIdx.x;
406 out_local_thread_id[global_thread_id] = local_thread_id;
407 out_block_id[global_thread_id] = block_id;
408 out_global_thread_id[global_thread_id] = global_thread_id;
417 for (
int i = 0; i < input.
size(); i++) {
442 int size = input.
size();
444 for (
int i = 0; i < size; ++i) {
456 ns[i] = input[i].getNanoseconds();
457 us[i] = input[i].getMicroseconds();
458 ms[i] = input[i].getMilliseconds();
459 s[i] = input[i].getSeconds();
460 m[i] = input[i].getMinutes();
461 h[i] = input[i].getHours();
462 d[i] = input[i].getDay();
463 mo[i] = input[i].getMonth();
464 y[i] = input[i].getYear();
475 int size = input.
size();
477 for (
int i = 0; i < size; ++i) {
481 out[i] = input[i] + offset;
505 const int32_t multiplier,
508 out[0] = input[0] + offset;
516 const int32_t multiplier,
519 int size = input.
size();
520 for (
int i = 0; i < size; ++i) {
524 out[i] = input[i] + input2[i] +
Timestamp(dummy);
551 int size = input.
size();
553 for (
int i = 0; i < size; ++i) {
554 y[i] = input[i].truncateToYear();
555 mo[i] = input[i].truncateToMonth();
556 d[i] = input[i].truncateToDay();
557 h[i] = input[i].truncateToHours();
558 m[i] = input[i].truncateToMinutes();
559 s[i] = input[i].truncateToSeconds();
560 ms[i] = input[i].truncateToMilliseconds();
561 us[i] = input[i].truncateToMicroseconds();
567 template <
typename T>
573 int size = input.
size();
575 for (
int i = 0; i < size; ++i) {
576 out[i] = inter + input[i];
594 #endif // ifndef __CUDACC__
599 int32_t output_row_count = copy_multiplier * input_col.
size();
600 if (output_row_count > 100) {
604 if (output_col.
size() != output_row_count) {
609 int32_t start = threadIdx.x + blockDim.x * blockIdx.x;
610 int32_t stop =
static_cast<int32_t
>(input_col.
size());
611 int32_t step = blockDim.x * gridDim.x;
614 auto stop = input_col.
size();
618 for (
auto i = start; i < stop; i += step) {
619 for (
int c = 0; c < copy_multiplier; c++) {
620 output_col[i + (c * input_col.
size())] = input_col[i];
624 return output_row_count;
633 if (copy_multiplier == -1) {
638 if (copy_multiplier == -2) {
644 if (copy_multiplier == -3) {
647 throw std::runtime_error(
"row_copier2: throw before calling set_output_row_size");
649 if (copy_multiplier == -4) {
653 throw std::runtime_error(
"row_copier2: throw after calling set_output_row_size");
656 if (copy_multiplier == -5) {
660 int32_t output_row_count = copy_multiplier * input_col.
size();
674 int32_t output_row_count = 0;
675 for (
int i = 0; i < cols.
numCols(); ++i) {
676 output_row_count += cols[i].
size();
680 for (
int i = 0; i < cols.
numCols(); ++i) {
681 for (
int j = 0; j < cols[i].
size(); ++j) {
682 output_col[idx++] = cols[i][j];
685 return output_row_count;
688 #endif // #ifndef __CUDACC__
693 int32_t output_row_count = copy_multiplier * input_col.
size();
694 if (output_row_count > 100) {
698 if (output_col.
size() != output_row_count) {
703 int32_t start = threadIdx.x + blockDim.x * blockIdx.x;
704 int32_t stop =
static_cast<int32_t
>(input_col.
size());
705 int32_t step = blockDim.x * gridDim.x;
708 auto stop = input_col.
size();
712 for (
auto i = start; i < stop; i += step) {
713 for (
int c = 0; c < copy_multiplier; c++) {
714 output_col[i + (c * input_col.
size())] = input_col[i];
718 return output_row_count;
725 int32_t output_row_count = copy_multiplier * input_col1.
size();
726 if (output_row_count > 100) {
730 if (output_col.
size() != output_row_count) {
735 int32_t start = threadIdx.x + blockDim.x * blockIdx.x;
736 int32_t stop =
static_cast<int32_t
>(input_col1.
size());
737 int32_t step = blockDim.x * gridDim.x;
740 auto stop = input_col1.
size();
743 auto stride = input_col1.
size();
744 for (
auto i = start; i < stop; i += step) {
745 for (
int c = 0; c < copy_multiplier; c++) {
747 output_col.
setNull(i + (c * stride));
749 output_col[i + (c * stride)] = input_col1[i] + input_col2[i];
754 return output_row_count;
762 int32_t output_row_count = copy_multiplier * input_col1.
size();
763 if (output_row_count > 100) {
767 if ((output_col1.
size() != output_row_count) ||
768 (output_col2.
size() != output_row_count)) {
773 int32_t start = threadIdx.x + blockDim.x * blockIdx.x;
774 int32_t stop =
static_cast<int32_t
>(input_col1.
size());
775 int32_t step = blockDim.x * gridDim.x;
778 auto stop = input_col1.
size();
781 auto stride = input_col1.
size();
782 for (
auto i = start; i < stop; i += step) {
783 for (
int c = 0; c < copy_multiplier; c++) {
784 output_col1[i + (c * stride)] = input_col1[i] + input_col2[i];
785 output_col2[i + (c * stride)] = input_col1[i] - input_col2[i];
788 return output_row_count;
797 if ((output_max_col.
size() != 1) || output_max_row_col.
size() != 1) {
801 auto stop = input_col.
size();
804 int curr_max = -2147483648;
805 int curr_max_row = -1;
806 for (
auto i = start; i < stop; i += step) {
807 if (input_col[i] > curr_max) {
808 curr_max = input_col[i];
812 output_max_col[0] = curr_max;
813 output_max_row_col[0] = curr_max_row;
817 #endif // #ifndef __CUDACC__
825 col = col_list[index];
829 #endif // #ifndef __CUDACC__
836 col2 = col_list[col_list.
numCols() - 1];
844 int32_t output_num_rows = input.
numCols();
846 for (
int i = 0; i < output_num_rows; i++) {
849 for (
int j = 0; j < col.size(); j++) {
854 return output_num_rows;
917 }
catch (
const std::runtime_error& ex) {
918 return mgr.ERROR_MESSAGE(ex.what());
923 bool result = (i8 == 1) && (i16 == 2) && (i32 == 3) && (i64 == 4) && (
f == 5.0f) &&
926 return mgr.ERROR_MESSAGE(
"Metadata return values are incorrect");
942 }
catch (
const std::runtime_error& ex) {
943 return mgr.ERROR_MESSAGE(ex.what());
951 #endif // #ifndef __CUDACC__
960 const int32_t multiplier,
968 const int32_t multiplier,
975 template <
typename T>
982 size_t output_row_count = input_col.
size() * reps;
986 auto stop = input_col.
size();
989 for (
auto i = start; i < stop; i += step) {
990 for (
int c = 0; c < reps; c++) {
991 output_col[i + (stop * c)] = input_col[i];
1034 #endif // #ifndef __CUDACC__
EXTENSION_NOINLINE_HOST int32_t ct_copy_and_add_size(TableFunctionManager &mgr, const Column< int32_t > &input, Column< int32_t > &output)
NEVER_INLINE HOST int32_t column_list_safe_row_sum__cpu_template(const ColumnList< T > &input, Column< T > &out)
void set_output_row_size(int64_t num_rows)
const T null_value_mapped_
NEVER_INLINE HOST int32_t ct_binding_scalar_multiply__cpu_template(const Column< T > &input, const T multiplier, Column< T > &out)
EXTENSION_NOINLINE_HOST void set_output_row_size(int64_t num_rows)
#define EXTENSION_NOINLINE
EXTENSION_NOINLINE_HOST int32_t row_copier_columnlist__cpu__(TableFunctionManager &mgr, const ColumnList< double > &cols, Column< double > &output_col)
static T map_null_value(const bool nulls_last)
void get_metadata(const std::string &key, T &value)
DEVICE int64_t size() const
EXTENSION_NOINLINE int32_t ct_test_nullable(const Column< int32_t > &input, const int32_t i, Column< int32_t > &out)
EXTENSION_NOINLINE int32_t ct_test_func__cpu_1(const Column< int32_t > &input1, const int32_t x, const int32_t multiplier, Column< int32_t > &out)
DEVICE int64_t numCols() const
NEVER_INLINE HOST int32_t tf_metadata_getter_bad__cpu_template(TableFunctionManager &mgr, const Column< bool > &input, Column< bool > &success)
DEVICE void sort(ARGS &&...args)
EXTENSION_NOINLINE_HOST int32_t ct_add_size_and_mul_alpha(TableFunctionManager &mgr, const Column< int32_t > &input1, const Column< int32_t > &input2, int32_t alpha, Column< int32_t > &output1, Column< int32_t > &output2)
SortAsc(const bool nulls_last)
SortDesc(const bool nulls_last)
EXTENSION_NOINLINE int32_t row_addsub(const int copy_multiplier, const Column< double > &input_col1, const Column< double > &input_col2, Column< double > &output_col1, Column< double > &output_col2)
EXTENSION_NOINLINE int32_t column_list_first_last(const ColumnList< double > &col_list, const int m, Column< double > &col1, Column< double > &col2)
EXTENSION_NOINLINE_HOST int32_t ct_timestamp_add_offset_cpu_only(const Column< Timestamp > &input, const int32_t multiplier, const Timestamp offset, Column< Timestamp > &out)
EXTENSION_NOINLINE int32_t row_copier(const Column< double > &input_col, int copy_multiplier, Column< double > &output_col)
#define EXTENSION_NOINLINE_HOST
NEVER_INLINE HOST int32_t sort_column_limit__cpu_template(const Column< T > &input, const int32_t limit, const bool sort_ascending, const bool nulls_last, Column< T > &output)
EXTENSION_NOINLINE_HOST int32_t ct_sleep2(TableFunctionManager &mgr, int32_t seconds, int32_t mode, Column< int32_t > &output)
EXTENSION_NOINLINE int32_t row_copier_text(const Column< TextEncodingDict > &input_col, int copy_multiplier, Column< TextEncodingDict > &output_col)
TEMPLATE_NOINLINE int32_t row_repeater__cpu_template(TableFunctionManager &mgr, const Column< T > &input_col, const int reps, Column< T > &output_col)
EXTENSION_NOINLINE_HOST int32_t ct_sleep1__cpu_(int32_t seconds, int32_t mode, Column< int32_t > &output)
NEVER_INLINE HOST int32_t ct_timestamp_add_interval__template(TableFunctionManager &mgr, const Column< Timestamp > &input, const T inter, Column< Timestamp > &out)
EXTENSION_NOINLINE_HOST int32_t column_list_row_sum__cpu_(const ColumnList< int32_t > &input, Column< int32_t > &out)
bool operator()(const T &a, const T &b)
NEVER_INLINE HOST int32_t ct_throw_if_gt_100__cpu_template(TableFunctionManager &mgr, const Column< T > &input, Column< T > &output)
DEVICE bool isNull(int64_t index) const
NEVER_INLINE HOST int32_t tf_metadata_getter__cpu_template(TableFunctionManager &mgr, const Column< bool > &input, Column< bool > &success)
DEVICE void setNull(int64_t index)
EXTENSION_NOINLINE_HOST int32_t get_max_with_row_offset__cpu_(const Column< int > &input_col, Column< int > &output_max_col, Column< int > &output_max_row_col)
const T null_value_mapped_
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
EXTENSION_NOINLINE int32_t ct_sleep_worker(int32_t seconds, Column< int32_t > &output)
EXTENSION_NOINLINE int32_t row_adder(const int copy_multiplier, const Column< double > &input_col1, const Column< double > &input_col2, Column< double > &output_col)
T safe_addition(T x, T y)
EXTENSION_NOINLINE_HOST int32_t ct_timestamp_extract(TableFunctionManager &mgr, const Column< Timestamp > &input, Column< int64_t > &ns, Column< int64_t > &us, Column< int64_t > &ms, Column< int64_t > &s, Column< int64_t > &m, Column< int64_t > &h, Column< int64_t > &d, Column< int64_t > &mo, Column< int64_t > &y)
NEVER_INLINE HOST int32_t tf_metadata_setter__cpu_template(TableFunctionManager &mgr, Column< bool > &success)
static T map_null_value(const bool nulls_last)
void set_metadata(const std::string &key, const T &value)
bool operator()(const T &a, const T &b)
EXTENSION_NOINLINE int32_t ct_test_func__cpu_2(const Column< int32_t > &input1, const Column< int32_t > &input2, const int32_t multiplier, Column< int32_t > &out)
#define TABLE_FUNCTION_ERROR(MSG)
NEVER_INLINE HOST int32_t tf_metadata_setter_size_mismatch__cpu_template(TableFunctionManager &mgr, Column< bool > &success)
EXTENSION_NOINLINE int32_t ct_timestamp_test_columns_and_scalars__cpu(const Column< Timestamp > &input, const int64_t dummy, const int32_t multiplier, const Column< Timestamp > &input2, Column< Timestamp > &out)
DEVICE int64_t size() const
DEVICE int64_t size() const
EXTENSION_NOINLINE_HOST int32_t column_list_get__cpu_(const ColumnList< double > &col_list, const int index, const int m, Column< double > &col)
EXTENSION_NOINLINE_HOST int32_t ct_timestamp_add_offset(TableFunctionManager &mgr, const Column< Timestamp > &input, const Timestamp offset, Column< Timestamp > &out)
EXTENSION_NOINLINE_HOST int32_t ct_timestamp_column_list_input(TableFunctionManager &mgr, const ColumnList< int64_t > &input, const Column< Timestamp > &input2, Column< int64_t > &out)
EXTENSION_NOINLINE_HOST int32_t row_copier2__cpu__(const Column< double > &input_col, int copy_multiplier, Column< double > &output_col, Column< double > &output_col2)
NEVER_INLINE HOST int32_t tf_metadata_setter_repeated__cpu_template(TableFunctionManager &mgr, Column< bool > &success)
static TableFunctionManager * get_singleton()
EXTENSION_NOINLINE_HOST int32_t ct_timestamp_truncate(TableFunctionManager &mgr, const Column< Timestamp > &input, Column< Timestamp > &y, Column< Timestamp > &mo, Column< Timestamp > &d, Column< Timestamp > &h, Column< Timestamp > &m, Column< Timestamp > &s, Column< Timestamp > &ms, Column< Timestamp > &us)
#define TEMPLATE_NOINLINE
EXTENSION_NOINLINE int32_t ct_gpu_default_init__gpu_(Column< int32_t > &output_buffer)
EXTENSION_NOINLINE_HOST int32_t ct_sparse_add(TableFunctionManager &mgr, const Column< int32_t > &x1, const Column< int32_t > &d1, int32_t f1, const Column< int32_t > &x2, const Column< int32_t > &d2, int32_t f2, Column< int32_t > &x, Column< int32_t > &d)