6 #ifndef TURI_UNITY_SFRAME_UTILS_H_ 7 #define TURI_UNITY_SFRAME_UTILS_H_ 11 #include <core/storage/sframe_data/sarray.hpp> 12 #include <core/data/flexible_type/flexible_type_base_types.hpp> 14 #include <core/storage/sframe_data/sframe.hpp> 15 #include <core/parallel/pthread_tools.hpp> 27 std::pair<sframe,sframe>
split_sframe_on_index(
const sframe& src, std::function<
bool(
size_t)> switch_function);
34 std::shared_ptr<sarray<flexible_type>>
matrix_to_sarray(
const Eigen::MatrixXd& m);
47 template <
typename GenFunction>
49 const std::vector<flex_type_enum>& column_types,
51 GenFunction&& generator_function) {
58 in_parallel([&](
size_t thread_index,
size_t num_threads) {
59 std::vector<flexible_type> out_values(column_names.size());
61 size_t start_idx = (num_rows * thread_index) / num_threads;
62 size_t end_idx = (num_rows * (thread_index + 1)) / num_threads;
66 for(
size_t i = start_idx; i < end_idx; ++i, ++it_out) {
67 generator_function(i, out_values);
68 DASSERT_EQ(column_names.size(), out_values.size());
iterator get_output_iterator(size_t segmentid)
static size_t cpu_count()
void open_for_write(const std::vector< std::string > &column_names, const std::vector< flex_type_enum > &column_types, const std::string &frame_sidx_file="", size_t nsegments=SFRAME_DEFAULT_NUM_SEGMENTS, bool fail_on_column_names=true)
void in_parallel(const std::function< void(size_t thread_id, size_t num_threads)> &fn)