16 #ifndef __DATA_MANAGEMENT_FEATURES_INTERNAL_HELPERS_H__
17 #define __DATA_MANAGEMENT_FEATURES_INTERNAL_HELPERS_H__
19 #include "services/internal/utilities.h"
20 #include "services/internal/collection.h"
22 #include "data_management/features/indices.h"
26 namespace data_management
34 inline services::Status pickElementsRaw(
const FeatureIndicesIfacePtr &indices,
35 T *elements, T **pickedElements)
37 DAAL_ASSERT( indices );
38 DAAL_ASSERT( elements );
39 DAAL_ASSERT( pickedElements );
41 if (indices->isPlainRange())
43 const size_t first = indices->getFirst();
44 const size_t last = indices->getLast();
49 for (
size_t i = first; i <= last; i++)
51 pickedElements[k++] = &elements[i];
56 for (
size_t i = first; i >= last; i--)
58 pickedElements[k++] = &elements[i];
62 else if (indices->areRawFeatureIndicesAvailable())
64 const services::BufferView<FeatureIndex> indicesBuffer = indices->getRawFeatureIndices();
65 const FeatureIndex *rawIndices = indicesBuffer.data();
66 const size_t indicesSize = indicesBuffer.size();
68 for (
size_t i = 0; i < indicesSize; i++)
70 pickedElements[i] = &elements[ rawIndices[i] ];
75 return services::throwIfPossible(services::ErrorMethodNotImplemented);
78 return services::Status();
82 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices, T *elements,
83 services::Status *status = NULL)
85 DAAL_ASSERT( indices );
86 DAAL_ASSERT( elements );
88 services::internal::CollectionPtr<T *> pickedElements =
89 services::internal::HeapAllocatableCollection<T *>::create(indices->size(), status);
90 if (!pickedElements) {
return pickedElements; }
92 services::Status pickElementsStatus = pickElementsRaw<T>(indices, elements, pickedElements->data());
93 if (!pickElementsStatus.ok())
95 services::internal::tryAssignStatusAndThrow(status, pickElementsStatus);
96 return services::internal::CollectionPtr<T *>();
99 return pickedElements;
103 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices,
104 const services::Collection<T> &elements,
105 services::Status *status = NULL)
107 return pickElements(indices, const_cast<T *>(elements.data()), status);
111 inline services::internal::CollectionPtr<T *> pickElements(
const FeatureIndicesIfacePtr &indices,
112 const services::internal::CollectionPtr<T> &elements,
113 services::Status *status = NULL)
115 DAAL_ASSERT( elements );
116 return pickElements(indices, const_cast<T *>(elements->data()), status);
129 services::Status pick(
const FeatureIndicesIfacePtr &indices)
131 DAAL_ASSERT( indices );
132 DAAL_ASSERT( _elements );
134 services::Status status;
135 _pickedElements = pickElements(indices, _elements, &status);
140 void setElements(
const services::internal::CollectionPtr<T> &elements)
142 DAAL_ASSERT( elements );
143 _elements = elements;
146 const services::internal::CollectionPtr<T> &getElements()
const
151 const services::internal::CollectionPtr<T *> &getPickedElements()
const
153 return _pickedElements;
157 services::internal::CollectionPtr<T> _elements;
158 services::internal::CollectionPtr<T *> _pickedElements;
165 template<
typename T>
inline IndexNumType getIndexNumType() {
return DAAL_OTHER_T; }
166 template<>
inline IndexNumType getIndexNumType<float>() {
return DAAL_FLOAT32; }
167 template<>
inline IndexNumType getIndexNumType<double>() {
return DAAL_FLOAT64; }
168 template<>
inline IndexNumType getIndexNumType<int>() {
return DAAL_INT32_S; }
169 template<>
inline IndexNumType getIndexNumType<unsigned int>() {
return DAAL_INT32_U; }
170 template<>
inline IndexNumType getIndexNumType<DAAL_INT64>() {
return DAAL_INT64_S; }
171 template<>
inline IndexNumType getIndexNumType<DAAL_UINT64>() {
return DAAL_INT64_U; }
172 template<>
inline IndexNumType getIndexNumType<char>() {
return DAAL_INT8_S; }
173 template<>
inline IndexNumType getIndexNumType<unsigned char>() {
return DAAL_INT8_U; }
174 template<>
inline IndexNumType getIndexNumType<short>() {
return DAAL_INT16_S; }
175 template<>
inline IndexNumType getIndexNumType<unsigned short>() {
return DAAL_INT16_U; }
177 template<>
inline IndexNumType getIndexNumType<long>()
178 {
return (IndexNumType)(DAAL_INT32_S + (
sizeof(long) / 4 - 1) * 2); }
180 #if (defined(__APPLE__) || defined(__MACH__)) && !defined(__x86_64__)
181 template<>
inline IndexNumType getIndexNumType<unsigned long>()
182 {
return (IndexNumType)(DAAL_INT32_U + (
sizeof(
unsigned long) / 4 - 1) * 2); }
185 #if !(defined(_WIN32) || defined(_WIN64)) && defined(__x86_64__)
186 template<>
inline IndexNumType getIndexNumType<size_t>()
187 {
return (IndexNumType)(DAAL_INT32_U + (
sizeof(size_t) / 4 - 1) * 2); }
194 inline PMMLNumType getPMMLNumType() {
return DAAL_GEN_UNKNOWN; }
196 inline PMMLNumType getPMMLNumType<int>() {
return DAAL_GEN_INTEGER; }
198 inline PMMLNumType getPMMLNumType<double>() {
return DAAL_GEN_DOUBLE; }
200 inline PMMLNumType getPMMLNumType<float>() {
return DAAL_GEN_FLOAT; }
202 inline PMMLNumType getPMMLNumType<bool>() {
return DAAL_GEN_BOOLEAN; }
204 inline PMMLNumType getPMMLNumType<char *>() {
return DAAL_GEN_STRING; }
206 inline PMMLNumType getPMMLNumType<std::string>() {
return DAAL_GEN_STRING; }
daal::data_management::features::interface1::FeatureIndex
size_t FeatureIndex
Definition: indices.h:37
daal
Definition: algorithm_base_common.h:31
daal::services::internal::CollectionPtr
Shared pointer to the Collection object.
Definition: internal/collection.h:136
daal::services::ErrorMethodNotImplemented
Definition: error_indexes.h:405
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:126