Turi Create  4.0
ml_data_entry.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_ENTRY_H_
7 #define TURI_ML2_DATA_ENTRY_H_
8 
9 #include <cstdlib>
10 #include <core/storage/serialization/serialization_includes.hpp>
11 
12 namespace turi { namespace v2 {
13 
14 /**
15  * Information relevant to a single entry of ml_data. The column_index may
16  * refer to a side column.
17  */
19  size_t column_index; /**< Column id .*/
20  size_t feature_index; /**< Local index within the column.*/
21  size_t global_index; /**< Global index, referenced off of the training index sizes. */
22  double value; /**< Value */
23 };
24 
25 /**
26  * Information relevant to a single entry of ml_data. The column_index may
27  * refer to a side column.
28  */
29 struct ml_data_entry {
30  size_t column_index; /**< Column id .*/
31  size_t index; /**< Local index within the column.*/
32  double value; /**< Value */
33 
34  /// Simple equality test
35  bool operator==(const ml_data_entry& other) const {
36  return ((column_index == other.column_index)
37  && (index == other.index)
38  && (value == other.value));
39  }
40 
41  const ml_data_entry& operator=(const ml_data_full_entry& fe) {
42  column_index = fe.column_index;
43  index = fe.feature_index;
44  value = fe.value;
45 
46  return *this;
47  }
48 };
49 
50 
51 /**
52  * Information relevant to a single entry of ml_data. The column_index may
53  * refer to a side column.
54  */
56  size_t global_index; /**< Global index based on training indices. */
57  double value = 1.0; /**< Value */
58 
59  /// Simple equality test
60  bool operator==(const ml_data_entry_global_index& other) const {
61  return ((global_index == other.global_index)
62  && (value == other.value));
63  }
64 
65  const ml_data_entry_global_index& operator=(const ml_data_full_entry& fe) {
66  global_index = fe.global_index;
67  value = fe.value;
68 
69  return *this;
70  }
71 };
72 
73 }}
74 
75 SERIALIZABLE_POD(v2::ml_data_entry);
76 
77 
78 #endif /* TURI_ML2_DATA_ENTRY_H_ */
size_t column_index
double value
size_t column_index
bool operator==(const ml_data_entry_global_index &other) const
Simple equality test.
double value
size_t global_index
size_t feature_index
size_t global_index
double value
size_t index
bool operator==(const ml_data_entry &other) const
Simple equality test.