18 #ifndef __DATA_MANAGEMENT_FEATURES_INTERNAL_HELPERS_H__
19 #define __DATA_MANAGEMENT_FEATURES_INTERNAL_HELPERS_H__
21 #include "services/internal/utilities.h"
22 #include "services/internal/collection.h"
24 #include "data_management/features/indices.h"
28 namespace data_management
36 inline services::Status pickElementsRaw(
const FeatureIndicesIfacePtr &indices,
37 T *elements, T **pickedElements)
39 DAAL_ASSERT( indices );
40 DAAL_ASSERT( elements );
41 DAAL_ASSERT( pickedElements );
43 if (indices->isPlainRange())
45 const size_t first = indices->getFirst();
46 const size_t last = indices->getLast();
51 for (
size_t i = first; i <= last; i++)
53 pickedElements[k++] = &elements[i];
58 for (
size_t i = first + 1; i > last; i--)
60 pickedElements[k++] = &elements[i - 1];
64 else if (indices->areRawFeatureIndicesAvailable())
66 const services::BufferView<FeatureIndex> indicesBuffer = indices->getRawFeatureIndices();
67 const FeatureIndex *rawIndices = indicesBuffer.data();
68 const size_t indicesSize = indicesBuffer.size();
70 for (
size_t i = 0; i < indicesSize; i++)
72 pickedElements[i] = &elements[ rawIndices[i] ];
77 return services::throwIfPossible(services::ErrorMethodNotImplemented);
80 return services::Status();
84 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices, T *elements,
85 services::Status *status = NULL)
87 DAAL_ASSERT( indices );
88 DAAL_ASSERT( elements );
90 services::internal::CollectionPtr<T *> pickedElements =
91 services::internal::HeapAllocatableCollection<T *>::create(indices->size(), status);
92 if (!pickedElements) {
return pickedElements; }
94 services::Status pickElementsStatus = pickElementsRaw<T>(indices, elements, pickedElements->data());
95 if (!pickElementsStatus.ok())
97 services::internal::tryAssignStatusAndThrow(status, pickElementsStatus);
98 return services::internal::CollectionPtr<T *>();
101 return pickedElements;
105 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices,
106 const services::Collection<T> &elements,
107 services::Status *status = NULL)
109 return pickElements(indices, const_cast<T *>(elements.data()), status);
113 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices,
114 const services::internal::CollectionPtr<T> &elements,
115 services::Status *status = NULL)
117 DAAL_ASSERT( elements );
118 return pickElements(indices, const_cast<T *>(elements->data()), status);
131 services::Status pick(
const FeatureIndicesIfacePtr &indices)
133 DAAL_ASSERT( indices );
134 DAAL_ASSERT( _elements );
136 services::Status status;
137 _pickedElements = pickElements(indices, _elements, &status);
142 void setElements(
const services::internal::CollectionPtr<T> &elements)
144 DAAL_ASSERT( elements );
145 _elements = elements;
148 const services::internal::CollectionPtr<T> &getElements()
const
153 const services::internal::CollectionPtr<T *> &getPickedElements()
const
155 return _pickedElements;
159 services::internal::CollectionPtr<T> _elements;
160 services::internal::CollectionPtr<T *> _pickedElements;
167 template<
typename T>
inline IndexNumType getIndexNumType() {
return DAAL_OTHER_T; }
168 template<>
inline IndexNumType getIndexNumType<float>() {
return DAAL_FLOAT32; }
169 template<>
inline IndexNumType getIndexNumType<double>() {
return DAAL_FLOAT64; }
170 template<>
inline IndexNumType getIndexNumType<int>() {
return DAAL_INT32_S; }
171 template<>
inline IndexNumType getIndexNumType<unsigned int>() {
return DAAL_INT32_U; }
172 template<>
inline IndexNumType getIndexNumType<DAAL_INT64>() {
return DAAL_INT64_S; }
173 template<>
inline IndexNumType getIndexNumType<DAAL_UINT64>() {
return DAAL_INT64_U; }
174 template<>
inline IndexNumType getIndexNumType<char>() {
return DAAL_INT8_S; }
175 template<>
inline IndexNumType getIndexNumType<unsigned char>() {
return DAAL_INT8_U; }
176 template<>
inline IndexNumType getIndexNumType<short>() {
return DAAL_INT16_S; }
177 template<>
inline IndexNumType getIndexNumType<unsigned short>() {
return DAAL_INT16_U; }
179 template<>
inline IndexNumType getIndexNumType<long>()
180 {
return (IndexNumType)(DAAL_INT32_S + (
sizeof(long) / 4 - 1) * 2); }
182 #if (defined(__APPLE__) || defined(__MACH__)) && !defined(__x86_64__)
183 template<>
inline IndexNumType getIndexNumType<unsigned long>()
184 {
return (IndexNumType)(DAAL_INT32_U + (
sizeof(
unsigned long) / 4 - 1) * 2); }
187 #if !(defined(_WIN32) || defined(_WIN64)) && defined(__x86_64__)
188 template<>
inline IndexNumType getIndexNumType<size_t>()
189 {
return (IndexNumType)(DAAL_INT32_U + (
sizeof(size_t) / 4 - 1) * 2); }
196 inline PMMLNumType getPMMLNumType() {
return DAAL_GEN_UNKNOWN; }
198 inline PMMLNumType getPMMLNumType<int>() {
return DAAL_GEN_INTEGER; }
200 inline PMMLNumType getPMMLNumType<double>() {
return DAAL_GEN_DOUBLE; }
202 inline PMMLNumType getPMMLNumType<float>() {
return DAAL_GEN_FLOAT; }
204 inline PMMLNumType getPMMLNumType<bool>() {
return DAAL_GEN_BOOLEAN; }
206 inline PMMLNumType getPMMLNumType<char *>() {
return DAAL_GEN_STRING; }
208 inline PMMLNumType getPMMLNumType<std::string>() {
return DAAL_GEN_STRING; }
daal::services::ErrorMethodNotImplemented
Definition: error_indexes.h:419
daal::data_management::features::interface1::FeatureIndex
size_t FeatureIndex
Definition: indices.h:39
daal::services::internal::CollectionPtr
Shared pointer to the Collection object.
Definition: internal/collection.h:138
daal::data_management::features::internal::ElementsPicker
Class that stores collection of elements of specified type and pointers to the elements of that colle...
Definition: helpers.h:128