C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 2

algorithm_types.h
1 /* file: algorithm_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of base classes defining algorithm interface.
45 //--
46 */
47 
48 #ifndef __ALGORITHM_TYPES_H__
49 #define __ALGORITHM_TYPES_H__
50 
51 #include "services/daal_defines.h"
52 #include "data_management/data/data_archive.h"
53 #include "data_management/data/data_serialize.h"
54 #include "data_management/data/data_collection.h"
55 #include "services/error_handling.h"
56 
57 namespace daal
58 {
69 namespace algorithms
70 {
71 
75 namespace interface1
76 {
86 struct Parameter
87 {
88  DAAL_NEW_DELETE();
89 
90  Parameter(){}
91  virtual ~Parameter() {}
92 
93  virtual services::Status check() const { return services::Status(); }
94 };
95 
100 class DAAL_EXPORT Argument
101 {
102 public:
103  DAAL_NEW_DELETE();
104 
106  Argument() : idx(0) {}
107 
112  Argument(const size_t n);
113 
114  virtual ~Argument() {};
115 
121  Argument &operator <<(const data_management::SerializationIfacePtr &val)
122  {
123  (*_storage) << val;
124  return *this;
125  }
126 
131  size_t size() const
132  {
133  return _storage->size();
134  }
135 
136 protected:
141  Argument(const Argument& other);
142 
148  const data_management::SerializationIfacePtr &get(size_t index) const;
149 
156  void set(size_t index, const data_management::SerializationIfacePtr &value);
157 
162  void setStorage(const data_management::DataCollectionPtr& storage);
163 
168  static data_management::DataCollectionPtr& getStorage(Argument& a);
169 
174  static const data_management::DataCollectionPtr& getStorage(const Argument& a);
175 
176 
177  template<typename Archive, bool onDeserialize>
178  services::Status serialImpl(Archive *arch)
179  {
180  arch->set(idx);
181  arch->setObj(_storage.get());
182 
183  return services::Status();
184  }
185 
186 private:
187  size_t idx;
188  data_management::DataCollectionPtr _storage;
189 };
190 
195 class SerializableArgument : public data_management::SerializationIface, public Argument
196 {
197 public:
198  DAAL_NEW_DELETE();
199 
201  SerializableArgument() {}
202 
207  SerializableArgument(const size_t n) : Argument(n) {}
208 
209  virtual ~SerializableArgument() {};
210 };
211 
217 class Input : public Argument
218 {
219 public:
220  DAAL_NEW_DELETE();
221 
223  Input() {}
224 
229  Input(const size_t n) : Argument(n) {}
230 
231  virtual ~Input() {};
232 
238  virtual services::Status check(const Parameter *parameter, int method) const { return services::Status(); }
239 
240 protected:
245  Input(const Input& other) : Argument(other){}
246 };
247 
253 class PartialResult : public SerializableArgument
254 {
255 public:
256  DAAL_NEW_DELETE();
257 
259  PartialResult() : _initFlag(false) {};
260 
265  PartialResult(const size_t n) : SerializableArgument(n), _initFlag(false) {}
266 
267  virtual ~PartialResult() {};
268 
272  virtual int getSerializationTag() const { return 0; }
273 
278  bool getInitFlag() { return _initFlag; }
279 
284  void setInitFlag(bool flag) { _initFlag = flag; }
285 
292  virtual services::Status check(const Input *input, const Parameter *parameter, int method) const
293  {
294  return services::Status();
295  }
296 
302  virtual services::Status check(const Parameter *parameter, int method) const { return services::Status(); }
303 
304 private:
305  bool _initFlag;
306 
307 protected:
309  template<typename Archive, bool onDeserialize>
310  services::Status serialImpl(Archive *arch)
311  {
312  Argument::serialImpl<Archive, onDeserialize>(arch);
313 
314  return services::Status();
315  }
316  virtual services::Status serializeImpl(data_management::InputDataArchive *archive)
317  {
318  return services::Status();
319  }
320  virtual services::Status deserializeImpl(const data_management::OutputDataArchive *archive)
321  {
322  return services::Status();
323  }
324 };
325 
331 class Result : public SerializableArgument
332 {
333 public:
334  DAAL_NEW_DELETE();
335 
337  Result() {}
338 
343  Result(const size_t n) : SerializableArgument(n) {}
344 
345  virtual ~Result() {};
346 
350  virtual int getSerializationTag() const { return 0; }
351 
358  virtual services::Status check(const Input *input, const Parameter *parameter, int method) const
359  {
360  return services::Status();
361  }
362 
369  virtual services::Status check(const PartialResult *partialResult, const Parameter *parameter, int method) const
370  {
371  return services::Status();
372  }
373 
374 
375 protected:
377  template<typename Archive, bool onDeserialize>
378  services::Status serialImpl(Archive *arch)
379  {
380  Argument::serialImpl<Archive, onDeserialize>(arch);
381 
382  return services::Status();
383  }
384  virtual services::Status serializeImpl(data_management::InputDataArchive *archive)
385  {
386  return services::Status();
387  }
388  virtual services::Status deserializeImpl(const data_management::OutputDataArchive *archive)
389  {
390  return services::Status();
391  }
392 };
393 
398 class DAAL_EXPORT OptionalArgument : public SerializableArgument
399 {
400 public:
401  DECLARE_SERIALIZABLE_TAG();
402 
404  OptionalArgument() : SerializableArgument(0) {}
405 
410  OptionalArgument(const size_t n) : SerializableArgument(n) {}
411 
417  const data_management::SerializationIfacePtr &get(size_t index) const { return SerializableArgument::get(index); }
418 
425  void set(size_t index, const data_management::SerializationIfacePtr &value) { return SerializableArgument::set(index, value); }
426 
427 protected:
429  template<typename Archive, bool onDeserialize>
430  services::Status serialImpl(Archive *arch)
431  {
432  Argument::serialImpl<Archive, onDeserialize>(arch);
433 
434  return services::Status();
435  }
436 
437  services::Status serializeImpl(data_management::InputDataArchive *arch) DAAL_C11_OVERRIDE
438  {
439  serialImpl<data_management::InputDataArchive, false>(arch);
440 
441  return services::Status();
442  }
443 
444  services::Status deserializeImpl(const data_management::OutputDataArchive *arch) DAAL_C11_OVERRIDE
445  {
446  serialImpl<const data_management::OutputDataArchive, true>(arch);
447 
448  return services::Status();
449  }
450 };
451 typedef services::SharedPtr<Input> InputPtr;
452 typedef services::SharedPtr<PartialResult> PartialResultPtr;
453 typedef services::SharedPtr<Result> ResultPtr;
454 typedef services::SharedPtr<OptionalArgument> OptionalArgumentPtr;
455 
457 } // namespace interface1
458 using interface1::Parameter;
459 using interface1::Argument;
460 using interface1::Input;
461 using interface1::InputPtr;
462 using interface1::PartialResult;
463 using interface1::PartialResultPtr;
464 using interface1::Result;
465 using interface1::ResultPtr;
466 using interface1::OptionalArgument;
467 using interface1::OptionalArgumentPtr;
468 
469 }
470 }
471 #endif
daal::algorithms::interface1::PartialResult::getSerializationTag
virtual int getSerializationTag() const
Definition: algorithm_types.h:272
daal::algorithms::interface1::Input::Input
Input()
Definition: algorithm_types.h:223
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::interface1::Argument::size
size_t size() const
Definition: algorithm_types.h:131
daal::algorithms::interface1::Result
Base class to represent final results of the computation. Algorithm-specific final results are repres...
Definition: algorithm_types.h:331
daal::data_management::interface1::InputDataArchive
Provides methods to create an archive data object (serialized) and access this object.
Definition: data_archive.h:715
daal::algorithms::interface1::Input::Input
Input(const size_t n)
Definition: algorithm_types.h:229
daal::algorithms::interface1::PartialResult
Base class to represent partial results of the computation. Algorithm-specific partial results are re...
Definition: algorithm_types.h:253
daal::algorithms::interface1::OptionalArgument
Base class to represent argument with serialization methods
Definition: algorithm_types.h:398
daal_defines.h
daal::algorithms::interface1::Result::serializeImpl
virtual services::Status serializeImpl(data_management::InputDataArchive *archive)
Definition: algorithm_types.h:384
daal::algorithms::interface1::Result::Result
Result(const size_t n)
Definition: algorithm_types.h:343
daal::algorithms::interface1::OptionalArgument::deserializeImpl
services::Status deserializeImpl(const data_management::OutputDataArchive *arch) DAAL_C11_OVERRIDE
Definition: algorithm_types.h:444
daal::algorithms::interface1::PartialResult::serializeImpl
virtual services::Status serializeImpl(data_management::InputDataArchive *archive)
Definition: algorithm_types.h:316
daal::algorithms::interface1::Input::Input
Input(const Input &other)
Definition: algorithm_types.h:245
daal::algorithms::interface1::OptionalArgument::OptionalArgument
OptionalArgument()
Definition: algorithm_types.h:404
daal::algorithms::interface1::Parameter
Base class to represent computation parameters. Algorithm-specific parameters are represented as deri...
Definition: algorithm_types.h:86
daal::algorithms::interface1::Result::check
virtual services::Status check(const Input *input, const Parameter *parameter, int method) const
Definition: algorithm_types.h:358
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::interface1::Result::deserializeImpl
virtual services::Status deserializeImpl(const data_management::OutputDataArchive *archive)
Definition: algorithm_types.h:388
daal::algorithms::interface1::OptionalArgument::OptionalArgument
OptionalArgument(const size_t n)
Definition: algorithm_types.h:410
daal::data_management::interface1::OutputDataArchive
Provides methods to restore an object from its serialized counterpart and access the restored object...
Definition: data_archive.h:978
daal::algorithms::interface1::PartialResult::getInitFlag
bool getInitFlag()
Definition: algorithm_types.h:278
daal::algorithms::interface1::Input::check
virtual services::Status check(const Parameter *parameter, int method) const
Definition: algorithm_types.h:238
daal::algorithms::interface1::Result::Result
Result()
Definition: algorithm_types.h:337
daal::algorithms::interface1::OptionalArgument::serializeImpl
services::Status serializeImpl(data_management::InputDataArchive *arch) DAAL_C11_OVERRIDE
Definition: algorithm_types.h:437
daal::algorithms::interface1::Result::check
virtual services::Status check(const PartialResult *partialResult, const Parameter *parameter, int method) const
Definition: algorithm_types.h:369
daal::algorithms::interface1::Argument::Argument
Argument()
Definition: algorithm_types.h:106
daal::algorithms::interface1::PartialResult::check
virtual services::Status check(const Input *input, const Parameter *parameter, int method) const
Definition: algorithm_types.h:292
daal::algorithms::interface1::SerializableArgument
Base class to represent argument with serialization methods
Definition: algorithm_types.h:195
daal::algorithms::math::abs::value
Definition: abs_types.h:112
daal::algorithms::interface1::PartialResult::PartialResult
PartialResult(const size_t n)
Definition: algorithm_types.h:265
daal::algorithms::interface1::SerializableArgument::SerializableArgument
SerializableArgument()
Definition: algorithm_types.h:201
daal::algorithms::interface1::PartialResult::PartialResult
PartialResult()
Definition: algorithm_types.h:259
daal::algorithms::interface1::Argument
Base class to represent computation input and output arguments.
Definition: algorithm_types.h:100
daal::algorithms::interface1::Argument::get
const data_management::SerializationIfacePtr & get(size_t index) const
daal::algorithms::interface1::SerializableArgument::SerializableArgument
SerializableArgument(const size_t n)
Definition: algorithm_types.h:207
daal::data_management::interface1::SerializationIface
Abstract interface class that defines the interface for serialization and deserialization.
Definition: data_serialize.h:76
daal::algorithms::interface1::Input
Base class to represent computation input arguments. Algorithm-specific input arguments are represent...
Definition: algorithm_types.h:217
daal::algorithms::interface1::PartialResult::check
virtual services::Status check(const Parameter *parameter, int method) const
Definition: algorithm_types.h:302
daal::algorithms::interface1::Argument::set
void set(size_t index, const data_management::SerializationIfacePtr &value)
daal::algorithms::interface1::Result::getSerializationTag
virtual int getSerializationTag() const
Definition: algorithm_types.h:350
daal::algorithms::interface1::PartialResult::setInitFlag
void setInitFlag(bool flag)
Definition: algorithm_types.h:284
daal::algorithms::interface1::PartialResult::deserializeImpl
virtual services::Status deserializeImpl(const data_management::OutputDataArchive *archive)
Definition: algorithm_types.h:320

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