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

covariance_distributed.h
1 /* file: covariance_distributed.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 distributed processing mode
46 //--
47 */
48 
49 #ifndef __COVARIANCE_DISTRIBUTED_H__
50 #define __COVARIANCE_DISTRIBUTED_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 #include "algorithms/covariance/covariance_online.h"
57 
58 namespace daal
59 {
60 namespace algorithms
61 {
62 namespace covariance
63 {
64 
65 namespace interface1
66 {
80 template<ComputeStep step>
81 class DistributedContainerIface
82 {};
83 
92 template<>
93 class DistributedContainerIface<step2Master> : public daal::algorithms::AnalysisContainerIface<distributed>
94 {
95 public:
96  DistributedContainerIface() {};
97  virtual ~DistributedContainerIface() {};
98 
103  virtual services::Status compute() = 0;
108  virtual services::Status finalizeCompute() = 0;
109 };
110 
121 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
122 class DAAL_EXPORT DistributedContainer
123 {};
124 
130 template<typename algorithmFPType, Method method, CpuType cpu>
131 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public DistributedContainerIface<step2Master>
132 {
133 public:
139  DistributedContainer(daal::services::Environment::env *daalEnv);
141  virtual ~DistributedContainer();
146  virtual services::Status compute() DAAL_C11_OVERRIDE;
151  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
152 };
153 
175 template<ComputeStep step>
176 class DAAL_EXPORT DistributedIface : public daal::algorithms::Analysis<distributed>
177 {};
178 
200 template<>
201 class DistributedIface<step1Local> : public OnlineImpl
202 {
203 public:
204  typedef OnlineImpl super;
205 
206  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
207  typedef super::ParameterType ParameterType;
208  typedef super::ResultType ResultType;
209  typedef super::PartialResultType PartialResultType;
210 
212  DistributedIface() : OnlineImpl()
213  {}
214 
222  DistributedIface(const DistributedIface<step1Local> &other) : OnlineImpl(other)
223  {}
224 
231  services::SharedPtr<DistributedIface<step1Local> > clone() const
232  {
233  return services::SharedPtr<DistributedIface<step1Local> >(cloneImpl());
234  }
235 
236 protected:
237  virtual DistributedIface<step1Local> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
238 };
239 
261 template<>
262 class DAAL_EXPORT DistributedIface<step2Master> : public daal::algorithms::Analysis<distributed>
263 {
264 public:
265  typedef algorithms::covariance::DistributedInput<step2Master> InputType;
266  typedef algorithms::covariance::Parameter ParameterType;
267  typedef algorithms::covariance::Result ResultType;
268  typedef algorithms::covariance::PartialResult PartialResultType;
269 
271  DistributedIface()
272  {
273  initialize();
274  };
275 
283  DistributedIface(const DistributedIface<step2Master> &other) : parameter(other.parameter)
284  {
285  initialize();
286  data_management::DataCollectionPtr collection = other.input.get(partialResults);
287  for (size_t i = 0; i < collection->size(); i++)
288  {
289  input.add(partialResults,
290  services::staticPointerCast<PartialResultType, data_management::SerializationIface>((*collection)[i]));
291  }
292  }
293 
294  virtual ~DistributedIface() {}
295 
300  ResultPtr getResult()
301  {
302  return _result;
303  }
304 
309  virtual services::Status setResult(const ResultPtr &result)
310  {
311  DAAL_CHECK(result, services::ErrorNullResult)
312  _result = result;
313  _res = _result.get();
314  return services::Status();
315  }
316 
321  PartialResultPtr getPartialResult()
322  {
323  return _partialResult;
324  }
325 
331  virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag = false)
332  {
333  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
334  _partialResult = partialResult;
335  _pres = _partialResult.get();
336  setInitFlag(initFlag);
337  return services::Status();
338  }
339 
343  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
344  {
345  services::Status s;
346  if(this->_partialResult)
347  {
348  s |= this->_partialResult->check(this->_par, getMethod());
349  if (!s) return s;
350  }
351  else
352  {
353  return services::Status(services::ErrorNullResult);
354  }
355 
356  if(this->_result)
357  {
358  s |= this->_result->check(this->_pres, this->_par, getMethod());
359  if (!s) return s;
360  }
361  else
362  {
363  return services::Status(services::ErrorNullResult);
364  }
365  return s;
366  }
367 
374  services::SharedPtr<DistributedIface<step2Master> > clone() const
375  {
376  return services::SharedPtr<DistributedIface<step2Master> >(cloneImpl());
377  }
378 
379  DistributedInput<step2Master> input;
380  ParameterType parameter;
382 protected:
383  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
384  {
385  return services::Status();
386  }
387 
388  void initialize()
389  {
390  _in = &input;
391  _par = &parameter;
392  _result.reset(new ResultType());
393  _partialResult.reset(new PartialResultType());
394  }
395 
396  virtual DistributedIface<step2Master> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
397 
398  PartialResultPtr _partialResult;
399  ResultPtr _result;
400 };
401 
423 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
424 class DAAL_EXPORT Distributed : public DistributedIface<step>
425 {};
426 
448 template<typename algorithmFPType, Method method>
449 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
450 {
451 public:
452  typedef Online<algorithmFPType, method> super;
453 
454  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
455  typedef typename super::ParameterType ParameterType;
456  typedef typename super::ResultType ResultType;
457  typedef typename super::PartialResultType PartialResultType;
458 
459  Distributed<step1Local, algorithmFPType, method>() : Online<algorithmFPType, method>()
460  {}
461 
469  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
470  Online<algorithmFPType, method>(other)
471  {}
472 
479  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
480  {
481  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
482  }
483 
484 protected:
485  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
486  {
487  return new Distributed<step1Local, algorithmFPType, method>(*this);
488  }
489 };
490 
512 template<typename algorithmFPType, Method method>
513 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public DistributedIface<step2Master>
514 {
515 public:
516  typedef DistributedIface<step2Master> super;
517 
518  typedef typename super::InputType InputType;
519  typedef typename super::ParameterType ParameterType;
520  typedef typename super::ResultType ResultType;
521  typedef typename super::PartialResultType PartialResultType;
522 
524  Distributed()
525  {
526  initialize();
527  }
528 
536  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
537  DistributedIface<step2Master>(other)
538  {
539  initialize();
540  }
541 
542  virtual ~Distributed() {}
543 
548  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
549 
556  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
557  {
558  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
559  }
560 
561 protected:
562  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
563  {
564  return new Distributed<step2Master, algorithmFPType, method>(*this);
565  }
566 
567  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
568  {
569  ResultPtr result = this->getResult();
570  services::Status s = result->template allocate<algorithmFPType>(this->_partialResult.get(), this->_par, (int)method);
571  this->_res = this->_result.get();
572  this->_pres = this->_partialResult.get();
573  return s;
574  }
575 
576  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
577  {
578  services::Status s = this->_partialResult->template allocate<algorithmFPType>(&(this->input), this->_par, (int)method);
579  this->_pres = this->_partialResult.get();
580  return s;
581  }
582 
583  void initialize()
584  {
585  this->_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
586  }
587 };
589 } // namespace interface1
590 using interface1::DistributedContainerIface;
591 using interface1::DistributedContainer;
592 using interface1::DistributedIface;
593 using interface1::Distributed;
594 
595 }
596 }
597 }
598 #endif // __COVARIANCE_DISTRIBUTED_H__
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setResult
virtual services::Status setResult(const ResultPtr &result)
Definition: covariance_distributed.h:309
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::algorithms::covariance::interface1::DistributedIface< step2Master >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:262
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface(const DistributedIface< step2Master > &other)
Definition: covariance_distributed.h:283
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::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: covariance_distributed.h:469
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::parameter
ParameterType parameter
Definition: covariance_distributed.h:380
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::covariance::interface1::Parameter
Parameters of the correlation or variance-covariance matrix algorithm.
Definition: covariance_types.h:284
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::DistributedIface< step1Local >::clone
services::SharedPtr< DistributedIface< step1Local > > clone() const
Definition: covariance_distributed.h:231
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::DistributedInput
Input parameters of the distributed Covariance algorithm.
Definition: covariance_types.h:393
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >
Computes correlation or variance-covariance matrix in the second step of the distributed processing m...
Definition: covariance_distributed.h:513
daal::algorithms::covariance::interface1::DistributedContainer
Provides methods to run implementations of the correlation or variance-covariance matrix algorithm in...
Definition: covariance_distributed.h:122
daal::algorithms::covariance::interface1::DistributedIface
Interface for the correlation or variance-covariance matrix algorithm in the distributed processing m...
Definition: covariance_distributed.h:176
daal_defines.h
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:548
daal::algorithms::kmeans::init::interface1::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:281
daal::distributed
Definition: daal_defines.h:133
daal::algorithms::covariance::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(MasterInputId id) const
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::input
DistributedInput< step2Master > input
Definition: covariance_distributed.h:379
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: covariance_distributed.h:524
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::partialResults
Definition: covariance_types.h:136
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setPartialResult
virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: covariance_distributed.h:331
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::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:479
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::clone
services::SharedPtr< DistributedIface< step2Master > > clone() const
Definition: covariance_distributed.h:374
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getPartialResult
PartialResultPtr getPartialResult()
Definition: covariance_distributed.h:321
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:212
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >
Computes correlation or variance-covariance matrix in the first step of the distributed processing mo...
Definition: covariance_distributed.h:449
daal::algorithms::covariance::interface1::DistributedContainerIface
Class that spcifies interfaces of the correlation or variance-covariance matrix algorithm. This class is associated with daal::algorithms::covariance::DistributedIface class.
Definition: covariance_distributed.h:81
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getResult
ResultPtr getResult()
Definition: covariance_distributed.h:300
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:271
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::kmeans::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Provides methods to run implementations of the K-Means algorithm. This class is associated with the d...
Definition: kmeans_distributed.h:81
daal::step1Local
Definition: daal_defines.h:143
daal::step2Master
Definition: daal_defines.h:144
daal::algorithms::covariance::interface1::Distributed
Computes correlation or variance-covariance matrix in the distributed processing mode.
Definition: covariance_distributed.h:424
daal::algorithms::covariance::interface1::DistributedIface< step1Local >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:201
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface(const DistributedIface< step1Local > &other)
Definition: covariance_distributed.h:222
daal::algorithms::covariance::interface1::DistributedInput< step2Master >
Input parameters of the distributed Covariance algorithm. Represents inputs of the algorithm on maste...
Definition: covariance_types.h:419
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:343
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:556
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: covariance_distributed.h:536

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