6 #ifndef TURI_DML_DATA_ROW_REFERENCE_H_ 7 #define TURI_DML_DATA_ROW_REFERENCE_H_ 9 #include <core/logging/assertions.hpp> 10 #include <ml/ml_data/data_storage/ml_data_row_format.hpp> 11 #include <ml/ml_data/data_storage/ml_data_block_manager.hpp> 12 #include <ml/ml_data/ml_data.hpp> 13 #include <core/util/code_optimization.hpp> 15 #include <Eigen/SparseCore> 19 #include <type_traits> 23 typedef Eigen::Matrix<double, Eigen::Dynamic,1> DenseVector;
24 typedef Eigen::SparseVector<double> SparseVector;
119 template <
typename Entry>
121 inline void fill(std::vector<Entry>& x)
const;
140 template <
typename EigenXpr>
144 typename std::enable_if<std::is_convertible<EigenXpr, DenseVector>::value >::type* = 0)
const {
158 template <
typename EigenXpr>
186 template <
typename ElementWriteFunction,
187 typename ColumnEndFunction>
189 void unpack(ElementWriteFunction&& ewf, ColumnEndFunction&& cef)
const {
191 if(UNLIKELY(!has_translated_columns))
196 DASSERT_TRUE(data_block->translated_rows.entry_data.size() != 0);
201 read_ml_data_row(rm, row_block_ptr, ewf, cef);
209 return get_target_value(data_block->rm, current_data_iter());
216 return get_target_index(data_block->rm, current_data_iter());
222 const std::shared_ptr<ml_metadata>&
metadata()
const {
223 return data_block->metadata;
229 std::shared_ptr<ml_data_internal::ml_data_block> data_block;
230 size_t current_in_block_index = size_t(-1);
231 size_t current_in_block_row_index = size_t(-1);
232 bool has_translated_columns =
false;
233 bool has_untranslated_columns =
false;
240 if(data_block->translated_rows.entry_data.empty()) {
241 ASSERT_EQ(current_in_block_index, 0);
243 ASSERT_LT(current_in_block_index, data_block->translated_rows.entry_data.size());
248 return data_block->translated_rows.entry_data.data() + current_in_block_index;
257 template <
typename Entry>
266 size_t feature_index,
double value,
269 size_t global_index = (LIKELY(feature_index < index_size)
270 ? index_offset + feature_index
285 template <
typename EigenXpr>
296 size_t feature_index,
double value,
297 size_t index_size,
size_t index_offset) {
299 if(UNLIKELY(feature_index >= index_size))
302 size_t idx = index_offset + feature_index;
305 DASSERT_LT(idx,
size_t(x.size()));
306 x.coeffRef(idx) = value;
312 [&](
ml_column_mode mode,
size_t column_index,
size_t index_size) {});
GL_HOT_INLINE_FLATTEN void fill_eigen(EigenXpr &&x) const
double target_value() const GL_HOT_INLINE_FLATTEN
GL_HOT_INLINE_FLATTEN void unpack(ElementWriteFunction &&ewf, ColumnEndFunction &&cef) const
const std::shared_ptr< ml_metadata > & metadata() const
size_t target_index() const GL_HOT_INLINE_FLATTEN
void fill_untranslated_values(std::vector< flexible_type > &x) const
GL_HOT_INLINE void fill(std::vector< Entry > &x) const
#define GL_HOT_INLINE_FLATTEN
static GL_HOT ml_data_row_reference from_row(const std::shared_ptr< ml_metadata > &metadata, const flex_dict &row, ml_missing_value_action none_action=ml_missing_value_action::USE_NAN)
std::vector< std::pair< flexible_type, flexible_type > > flex_dict
GL_HOT_INLINE_FLATTEN void fill(EigenXpr &&x, typename std::enable_if< std::is_convertible< EigenXpr, DenseVector >::value >::type *=0) const
#define DASSERT_TRUE(cond)