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

covariance_online.h
1 /* file: covariance_online.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 the interface for the correlation or variance-covariance
45 // matrix algorithm in the online processing mode
46 //--
47 */
48 
49 #ifndef __COVARIANCE_ONLINE_H__
50 #define __COVARIANCE_ONLINE_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/covariance/covariance_types.h"
56 
57 namespace daal
58 {
59 namespace algorithms
60 {
61 namespace covariance
62 {
63 
64 namespace interface1
65 {
79 class OnlineContainerIface : public daal::algorithms::AnalysisContainerIface<online>
80 {
81 public:
82  OnlineContainerIface() {};
83  virtual ~OnlineContainerIface() {}
84 
89  virtual services::Status compute() = 0;
90 
95  virtual services::Status finalizeCompute() = 0;
96 };
97 
106 template<typename algorithmFPType, Method method, CpuType cpu>
107 class DAAL_EXPORT OnlineContainer
108 {};
109 
118 template<typename algorithmFPType, CpuType cpu>
119 class DAAL_EXPORT OnlineContainer<algorithmFPType, defaultDense, cpu> : public OnlineContainerIface
120 {
121 public:
127  OnlineContainer(daal::services::Environment::env *daalEnv);
129  virtual ~OnlineContainer();
130 
135  virtual services::Status compute() DAAL_C11_OVERRIDE;
140  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
141 };
142 
151 template<typename algorithmFPType, CpuType cpu>
152 class DAAL_EXPORT OnlineContainer<algorithmFPType, singlePassDense, cpu> : public OnlineContainerIface
153 {
154 public:
160  OnlineContainer(daal::services::Environment::env *daalEnv);
162  virtual ~OnlineContainer();
163 
168  virtual services::Status compute() DAAL_C11_OVERRIDE;
173  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
174 };
175 
184 template<typename algorithmFPType, CpuType cpu>
185 class DAAL_EXPORT OnlineContainer<algorithmFPType, sumDense, cpu> : public OnlineContainerIface
186 {
187 public:
193  OnlineContainer(daal::services::Environment::env *daalEnv);
195  virtual ~OnlineContainer();
196 
201  virtual services::Status compute() DAAL_C11_OVERRIDE;
206  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
207 };
208 
217 template<typename algorithmFPType, CpuType cpu>
218 class DAAL_EXPORT OnlineContainer<algorithmFPType, fastCSR, cpu> : public OnlineContainerIface
219 {
220 public:
226  OnlineContainer(daal::services::Environment::env *daalEnv);
228  virtual ~OnlineContainer();
229 
234  virtual services::Status compute() DAAL_C11_OVERRIDE;
239  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
240 };
241 
250 template<typename algorithmFPType, CpuType cpu>
251 class DAAL_EXPORT OnlineContainer<algorithmFPType, singlePassCSR, cpu> : public OnlineContainerIface
252 {
253 public:
259  OnlineContainer(daal::services::Environment::env *daalEnv);
261  virtual ~OnlineContainer();
262 
267  virtual services::Status compute() DAAL_C11_OVERRIDE;
272  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
273 };
274 
283 template<typename algorithmFPType, CpuType cpu>
284 class DAAL_EXPORT OnlineContainer<algorithmFPType, sumCSR, cpu> : public OnlineContainerIface
285 {
286 public:
292  OnlineContainer(daal::services::Environment::env *daalEnv);
294  virtual ~OnlineContainer();
295 
300  virtual services::Status compute() DAAL_C11_OVERRIDE;
305  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
306 };
307 
313 class DAAL_EXPORT OnlineImpl : public daal::algorithms::Analysis<online>
314 {
315 public:
316  typedef algorithms::covariance::Input InputType;
317  typedef algorithms::covariance::OnlineParameter ParameterType;
318  typedef algorithms::covariance::Result ResultType;
319  typedef algorithms::covariance::PartialResult PartialResultType;
320 
322  OnlineImpl()
323  {
324  initialize();
325  }
326 
334  OnlineImpl(const OnlineImpl &other) : input(other.input), parameter(other.parameter)
335  {
336  initialize();
337  }
338 
339  virtual ~OnlineImpl() {}
340 
345  ResultPtr getResult()
346  {
347  return _result;
348  }
349 
354  virtual services::Status setResult(const ResultPtr &result)
355  {
356  DAAL_CHECK(result, services::ErrorNullResult)
357  _result = result;
358  _res = _result.get();
359  return services::Status();
360  }
361 
366  PartialResultPtr getPartialResult()
367  {
368  return _partialResult;
369  }
370 
376  virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag = false)
377  {
378  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
379  _partialResult = partialResult;
380  _pres = _partialResult.get();
381  setInitFlag(initFlag);
382  return services::Status();
383  }
384 
391  services::SharedPtr<OnlineImpl> clone() const
392  {
393  return services::SharedPtr<OnlineImpl>(cloneImpl());
394  }
395 
396  InputType input;
397  ParameterType parameter;
399 protected:
400  void initialize()
401  {
402  _in = &input;
403  _par = &parameter;
404  _result.reset(new ResultType());
405  _partialResult.reset(new PartialResult());
406  }
407 
408  virtual OnlineImpl * cloneImpl() const DAAL_C11_OVERRIDE = 0;
409 
410  PartialResultPtr _partialResult;
411  ResultPtr _result;
412 };
413 
414 
435 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
436 class DAAL_EXPORT Online : public OnlineImpl
437 {
438 public:
439  typedef OnlineImpl super;
440 
441  typedef typename super::InputType InputType;
442  typedef typename super::ParameterType ParameterType;
443  typedef typename super::ResultType ResultType;
444  typedef typename super::PartialResultType PartialResultType;
445 
447  Online()
448  {
449  initialize();
450  }
451 
459  Online(const Online<algorithmFPType, method> &other) : OnlineImpl(other)
460  {
461  initialize();
462  }
463 
464  virtual ~Online() {}
465 
470  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
471 
478  services::SharedPtr<Online<algorithmFPType, method> > clone() const
479  {
480  return services::SharedPtr<Online<algorithmFPType, method> >(cloneImpl());
481  }
482 
483 protected:
484  virtual Online<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
485  {
486  return new Online<algorithmFPType, method>(*this);
487  }
488 
489  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
490  {
491  services::Status s = _result->allocate<algorithmFPType>(_partialResult.get(), _par, (int)method);
492  _res = _result.get();
493  _pres = _partialResult.get();
494  return services::Status();
495  }
496 
497  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
498  {
499  services::Status s = _partialResult->allocate<algorithmFPType>(&input, _par, (int)method);
500  _pres = _partialResult.get();
501  return s;
502  }
503 
504  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
505  {
506  services::Status s = _partialResult->initialize<algorithmFPType>(&input, _par, (int)method);
507  _pres = _partialResult.get();
508  return services::Status();
509  }
510 
511  void initialize()
512  {
513  this->_ac = new __DAAL_ALGORITHM_CONTAINER(online, OnlineContainer, algorithmFPType, method)(&_env);
514  }
515 };
517 } // namespace interface1
518 using interface1::OnlineContainerIface;
519 using interface1::OnlineContainer;
520 using interface1::OnlineImpl;
521 using interface1::Online;
522 
523 } // namespace daal::algorithms::covariance
524 } // namespace daal::algorithms
525 } // namespace daal
526 #endif
daal::algorithms::covariance::singlePassCSR
Definition: covariance_types.h:80
daal::algorithms::covariance::interface1::OnlineParameter
Parameters of the correlation or variance-covariance matrix algorithm in the online processing mode...
Definition: covariance_types.h:295
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
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::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:79
daal::algorithms::covariance::interface1::OnlineContainer
Provides methods to run implementations of the correlation or variance-covariance matrix algorithm...
Definition: covariance_online.h:107
daal::algorithms::covariance::interface1::OnlineImpl::setPartialResult
virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: covariance_online.h:376
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::covariance::interface1::OnlineImpl::setResult
virtual services::Status setResult(const ResultPtr &result)
Definition: covariance_online.h:354
daal::algorithms::covariance::interface1::OnlineImpl::OnlineImpl
OnlineImpl(const OnlineImpl &other)
Definition: covariance_online.h:334
daal::algorithms::covariance::interface1::OnlineContainerIface
Class that spcifies interfaces of implementations of the correlation or variance-covariance matrix al...
Definition: covariance_online.h:79
daal::algorithms::covariance::interface1::OnlineImpl
Abstract class that specifies interface of the algorithms for computing correlation or variance-covar...
Definition: covariance_online.h:313
daal::algorithms::covariance::interface1::Online::Online
Online(const Online< algorithmFPType, method > &other)
Definition: covariance_online.h:459
daal::algorithms::covariance::interface1::OnlineImpl::parameter
ParameterType parameter
Definition: covariance_online.h:397
daal::algorithms::covariance::interface1::Online::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: covariance_online.h:470
daal::algorithms::covariance::interface1::Online
Computes correlation or variance-covariance matrix in the online processing mode. ...
Definition: covariance_online.h:436
daal::algorithms::covariance::interface1::OnlineContainerIface::compute
virtual services::Status compute()=0
daal::algorithms::covariance::interface1::Input
Input objects of the correlation or variance-covariance matrix algorithm
Definition: covariance_types.h:162
daal_defines.h
daal::algorithms::covariance::sumDense
Definition: covariance_types.h:77
daal::algorithms::covariance::interface1::OnlineImpl::input
InputType input
Definition: covariance_online.h:396
daal::algorithms::covariance::fastCSR
Definition: covariance_types.h:79
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::covariance::interface1::Result
Provides methods to access final results obtained with the compute() method of the correlation or var...
Definition: covariance_types.h:317
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::covariance::sumCSR
Definition: covariance_types.h:82
daal::algorithms::covariance::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the correlation or v...
Definition: covariance_types.h:204
daal::algorithms::covariance::interface1::Online::Online
Online()
Definition: covariance_online.h:447
daal::algorithms::covariance::interface1::OnlineImpl::OnlineImpl
OnlineImpl()
Definition: covariance_online.h:322
daal::algorithms::covariance::interface1::OnlineImpl::getPartialResult
PartialResultPtr getPartialResult()
Definition: covariance_online.h:366
daal::algorithms::covariance::interface1::OnlineContainerIface::finalizeCompute
virtual services::Status finalizeCompute()=0
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::covariance::covariance
Definition: covariance_types.h:114
daal::algorithms::covariance::interface1::Online::clone
services::SharedPtr< Online< algorithmFPType, method > > clone() const
Definition: covariance_online.h:478
daal::online
Definition: daal_defines.h:134
daal::algorithms::covariance::interface1::OnlineImpl::clone
services::SharedPtr< OnlineImpl > clone() const
Definition: covariance_online.h:391
daal::algorithms::covariance::defaultDense
Definition: covariance_types.h:74
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::covariance::singlePassDense
Definition: covariance_types.h:75
daal::algorithms::covariance::interface1::OnlineImpl::getResult
ResultPtr getResult()
Definition: covariance_online.h:345

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