Turi Create  4.0
ml_data_side_feature_translation.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_ML2_DATA_SIDE_FEATURES_TRANSATION_H_
7 #define TURI_ML2_DATA_SIDE_FEATURES_TRANSATION_H_
8 
9 #include <toolkits/ml_data_2/data_storage/ml_data_row_format.hpp>
10 #include <toolkits/ml_data_2/ml_data_entry.hpp>
11 #include <toolkits/ml_data_2/ml_data_column_modes.hpp>
12 #include <toolkits/ml_data_2/data_storage/internal_metadata.hpp>
13 #include <core/data/flexible_type/flexible_type.hpp>
14 #include <core/util/code_optimization.hpp>
15 #include <type_traits>
16 
17 namespace turi { namespace v2 {
18 
19 class ml_data_side_features;
20 
21 namespace ml_data_internal {
22 
23 /** Write some of the information into a specified output iterator,
24  * with columns shifted by column_index_offset. Meant to be used as
25  * the routine that the side features column uses.
26  */
27 template <typename EntryType>
29 static inline void append_raw_to_entry_row(
30  const row_metadata& rm,
31  entry_value_iterator row_block_ptr,
32  std::vector<EntryType>& x_out,
33  size_t column_index_offset) {
34 
35  read_ml_data_row(
36  rm,
37 
38  /** The data pointer. */
39  row_block_ptr,
40 
41  /** The function to write out the data to x.
42  */
43  [&](ml_column_mode mode, size_t local_column_index,
44  size_t feature_index, double value, size_t index_size, size_t index_offset) {
45 
46  if(LIKELY(feature_index < index_size)) {
47 
48  size_t column_index = column_index_offset + local_column_index;
49 
50  size_t global_index = rm.metadata_vect[local_column_index]->global_index_offset() + feature_index;
51 
52  EntryType e;
53  e = ml_data_full_entry{column_index,
54  feature_index,
55  global_index,
56  value};
57 
58  x_out.push_back(e);
59  }
60  },
61 
62  // Nothing that we need to do at the end of each column.
63  [&](ml_column_mode, size_t, size_t) {},
64 
65  /** No side information here. */
66  std::shared_ptr<ml_data_side_features>());
67 }
68 
69 
70 }}}
71 
72 
73 #endif
#define GL_HOT_INLINE_FLATTEN