C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

indices_impl.h
1 /* file: indices_impl.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 #ifndef __DATA_MANAGEMENT_FEATURES_INTERNAL_INDICES_IMPL_H__
17 #define __DATA_MANAGEMENT_FEATURES_INTERNAL_INDICES_IMPL_H__
18 
19 #include <map>
20 #include <string>
21 
22 #include "services/collection.h"
23 #include "services/internal/utilities.h"
24 #include "services/internal/error_handling_helpers.h"
25 
26 #include "data_management/features/indices.h"
27 
28 namespace daal
29 {
30 namespace data_management
31 {
32 namespace features
33 {
34 namespace internal
35 {
36 
41 class FeatureIndicesList : public FeatureIndices
42 {
43 public:
44  static services::SharedPtr<FeatureIndicesList> create(services::Status *status = NULL)
45  {
46  return services::internal::wrapSharedAndTryThrow<FeatureIndicesList>(new FeatureIndicesList(), status);
47  }
48 
49  virtual size_t size() const DAAL_C11_OVERRIDE
50  {
51  return _indices.size();
52  }
53 
54  virtual bool isPlainRange() const DAAL_C11_OVERRIDE
55  {
56  return false;
57  }
58 
59  virtual bool areRawFeatureIndicesAvailable() const DAAL_C11_OVERRIDE
60  {
61  return true;
62  }
63 
64  virtual FeatureIndex getFirst() const DAAL_C11_OVERRIDE
65  {
66  if (!size()) { return FeatureIndexTraits::invalid(); }
67  return _indices[0];
68  }
69 
70  virtual FeatureIndex getLast() const DAAL_C11_OVERRIDE
71  {
72  if (!size()) { return FeatureIndexTraits::invalid(); }
73  return _indices[_indices.size() - 1];
74  }
75 
76  virtual services::BufferView<FeatureIndex> getRawFeatureIndices() DAAL_C11_OVERRIDE
77  {
78  return services::BufferView<FeatureIndex>(_indices.data(), _indices.size());
79  }
80 
81  services::Status add(FeatureIndex index)
82  {
83  if (index > FeatureIndexTraits::maxIndex() || index == FeatureIndexTraits::invalid())
84  {
85  return services::throwIfPossible(services::ErrorIncorrectDataRange);
86  }
87 
88  if ( !_indices.safe_push_back(index) )
89  {
90  return services::throwIfPossible(services::ErrorMemoryAllocationFailed);
91  }
92 
93  return services::Status();
94  }
95 
96 private:
97  FeatureIndicesList() { }
98 
99  services::Collection<FeatureIndex> _indices;
100 };
101 typedef services::SharedPtr<FeatureIndicesList> FeatureIndicesListPtr;
102 
107 class FeatureIndicesRange : public FeatureIndices
108 {
109 public:
110  static services::SharedPtr<FeatureIndicesRange> create(FeatureIndex begin, FeatureIndex end,
111  services::Status *status = NULL)
112  {
113  if (begin == FeatureIndexTraits::invalid() ||
114  end == FeatureIndexTraits::invalid())
115  {
116  services::internal::tryAssignStatusAndThrow(status, services::ErrorIncorrectIndex);
117  return services::SharedPtr<FeatureIndicesRange>();
118  }
119  return services::internal::wrapSharedAndTryThrow<FeatureIndicesRange>(
120  new FeatureIndicesRange(begin, end), status);
121  }
122 
123  virtual size_t size() const DAAL_C11_OVERRIDE
124  {
125  return services::internal::maxValue(_begin, _end) -
126  services::internal::minValue(_begin, _end) + 1;
127  }
128 
129  virtual bool isPlainRange() const DAAL_C11_OVERRIDE
130  {
131  return true;
132  }
133 
134  virtual bool areRawFeatureIndicesAvailable() const DAAL_C11_OVERRIDE
135  {
136  return false;
137  }
138 
139  virtual FeatureIndex getFirst() const DAAL_C11_OVERRIDE
140  {
141  return _begin;
142  }
143 
144  virtual FeatureIndex getLast() const DAAL_C11_OVERRIDE
145  {
146  return _end;
147  }
148 
149  virtual services::BufferView<FeatureIndex> getRawFeatureIndices() DAAL_C11_OVERRIDE
150  {
151  return services::BufferView<FeatureIndex>();
152  }
153 
154 private:
155  explicit FeatureIndicesRange(FeatureIndex begin, FeatureIndex end) :
156  _begin(begin),
157  _end(end) { }
158 
159  FeatureIndex _begin;
160  FeatureIndex _end;
161 };
162 typedef services::SharedPtr<FeatureIndicesList> FeatureIndicesListPtr;
163 
164 } // namespace internal
165 } // namespace features
166 } // namespace data_management
167 } // namespace daal
168 
169 #endif
daal::data_management::features::internal::FeatureIndicesList
Implementation of FeatureIndices to store a list of feature indices.
Definition: indices_impl.h:41
daal
Definition: algorithm_base_common.h:31
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:146
daal::services::ErrorIncorrectIndex
Definition: error_indexes.h:100
daal::data_management::features::internal::FeatureIndicesRange
Implementation of FeatureIndices to store a range of feature indices.
Definition: indices_impl.h:107
daal::services::ErrorIncorrectDataRange
Definition: error_indexes.h:77

For more complete information about compiler optimizations, see our Optimization Notice.