C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

covariance_distributed.h
1 /* file: covariance_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of the interface for the correlation or variance-covariance
21 // matrix algorithm in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __COVARIANCE_DISTRIBUTED_H__
26 #define __COVARIANCE_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/covariance/covariance_types.h"
32 #include "algorithms/covariance/covariance_online.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
38 namespace covariance
39 {
40 
41 namespace interface1
42 {
56 template<ComputeStep step>
57 class DistributedContainerIface
58 {};
59 
68 template<>
69 class DistributedContainerIface<step2Master> : public daal::algorithms::AnalysisContainerIface<distributed>
70 {
71 public:
72  DistributedContainerIface() {}
73  virtual ~DistributedContainerIface() {}
74 
79  virtual services::Status compute() = 0;
84  virtual services::Status finalizeCompute() = 0;
85 };
86 
97 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
98 class DistributedContainer
99 {};
100 
106 template<typename algorithmFPType, Method method, CpuType cpu>
107 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public DistributedContainerIface<step2Master>
108 {
109 public:
115  DistributedContainer(daal::services::Environment::env *daalEnv);
117  virtual ~DistributedContainer();
122  virtual services::Status compute() DAAL_C11_OVERRIDE;
127  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE;
128 };
129 
151 template<ComputeStep step>
152 class DAAL_EXPORT DistributedIface : public daal::algorithms::Analysis<distributed>
153 {};
154 
176 template<>
177 class DistributedIface<step1Local> : public OnlineImpl
178 {
179 public:
180  typedef OnlineImpl super;
181 
182  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
183  typedef super::ParameterType ParameterType;
184  typedef super::ResultType ResultType;
185  typedef super::PartialResultType PartialResultType;
186 
188  DistributedIface() : OnlineImpl()
189  {}
190 
198  DistributedIface(const DistributedIface<step1Local> &other) : OnlineImpl(other)
199  {}
200 
207  services::SharedPtr<DistributedIface<step1Local> > clone() const
208  {
209  return services::SharedPtr<DistributedIface<step1Local> >(cloneImpl());
210  }
211 
212 protected:
213  virtual DistributedIface<step1Local> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
214 };
215 
237 template<>
238 class DAAL_EXPORT DistributedIface<step2Master> : public daal::algorithms::Analysis<distributed>
239 {
240 public:
241  typedef algorithms::covariance::DistributedInput<step2Master> InputType;
242  typedef algorithms::covariance::Parameter ParameterType;
243  typedef algorithms::covariance::Result ResultType;
244  typedef algorithms::covariance::PartialResult PartialResultType;
245 
247  DistributedIface()
248  {
249  initialize();
250  }
251 
259  DistributedIface(const DistributedIface<step2Master> &other) : parameter(other.parameter)
260  {
261  initialize();
262  data_management::DataCollectionPtr collection = other.input.get(partialResults);
263  for (size_t i = 0; i < collection->size(); i++)
264  {
265  input.add(partialResults,
266  services::staticPointerCast<PartialResultType, data_management::SerializationIface>((*collection)[i]));
267  }
268  }
269 
270  virtual ~DistributedIface() {}
271 
276  ResultPtr getResult()
277  {
278  return _result;
279  }
280 
285  virtual services::Status setResult(const ResultPtr &result)
286  {
287  DAAL_CHECK(result, services::ErrorNullResult)
288  _result = result;
289  _res = _result.get();
290  return services::Status();
291  }
292 
297  PartialResultPtr getPartialResult()
298  {
299  return _partialResult;
300  }
301 
307  virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag = false)
308  {
309  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
310  _partialResult = partialResult;
311  _pres = _partialResult.get();
312  setInitFlag(initFlag);
313  return services::Status();
314  }
315 
319  services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
320  {
321  services::Status s;
322  if(this->_partialResult)
323  {
324  s |= this->_partialResult->check(this->_par, getMethod());
325  if (!s) return s;
326  }
327  else
328  {
329  return services::Status(services::ErrorNullResult);
330  }
331 
332  if(this->_result)
333  {
334  s |= this->_result->check(this->_pres, this->_par, getMethod());
335  if (!s) return s;
336  }
337  else
338  {
339  return services::Status(services::ErrorNullResult);
340  }
341  return s;
342  }
343 
350  services::SharedPtr<DistributedIface<step2Master> > clone() const
351  {
352  return services::SharedPtr<DistributedIface<step2Master> >(cloneImpl());
353  }
354 
355  DistributedInput<step2Master> input;
356  ParameterType parameter;
358 protected:
359  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
360  {
361  return services::Status();
362  }
363 
364  void initialize()
365  {
366  _in = &input;
367  _par = &parameter;
368  _result.reset(new ResultType());
369  _partialResult.reset(new PartialResultType());
370  }
371 
372  virtual DistributedIface<step2Master> * cloneImpl() const DAAL_C11_OVERRIDE = 0;
373 
374  PartialResultPtr _partialResult;
375  ResultPtr _result;
376 };
377 
399 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
400 class DAAL_EXPORT Distributed : public DistributedIface<step>
401 {};
402 
424 template<typename algorithmFPType, Method method>
425 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
426 {
427 public:
428  typedef Online<algorithmFPType, method> super;
429 
430  typedef algorithms::covariance::DistributedInput<step1Local> InputType;
431  typedef typename super::ParameterType ParameterType;
432  typedef typename super::ResultType ResultType;
433  typedef typename super::PartialResultType PartialResultType;
434 
435  Distributed<step1Local, algorithmFPType, method>() : Online<algorithmFPType, method>()
436  {}
437 
445  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
446  Online<algorithmFPType, method>(other)
447  {}
448 
455  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
456  {
457  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
458  }
459 
460 protected:
461  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
462  {
463  return new Distributed<step1Local, algorithmFPType, method>(*this);
464  }
465 };
466 
488 template<typename algorithmFPType, Method method>
489 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public DistributedIface<step2Master>
490 {
491 public:
492  typedef DistributedIface<step2Master> super;
493 
494  typedef typename super::InputType InputType;
495  typedef typename super::ParameterType ParameterType;
496  typedef typename super::ResultType ResultType;
497  typedef typename super::PartialResultType PartialResultType;
498 
500  Distributed()
501  {
502  initialize();
503  }
504 
512  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) :
513  DistributedIface<step2Master>(other)
514  {
515  initialize();
516  }
517 
518  virtual ~Distributed() {}
519 
524  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
525 
532  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
533  {
534  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
535  }
536 
537 protected:
538  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
539  {
540  return new Distributed<step2Master, algorithmFPType, method>(*this);
541  }
542 
543  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
544  {
545  ResultPtr result = this->getResult();
546  services::Status s = result->template allocate<algorithmFPType>(this->_partialResult.get(), this->_par, (int)method);
547  this->_res = this->_result.get();
548  this->_pres = this->_partialResult.get();
549  return s;
550  }
551 
552  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
553  {
554  services::Status s = this->_partialResult->template allocate<algorithmFPType>(&(this->input), this->_par, (int)method);
555  this->_pres = this->_partialResult.get();
556  return s;
557  }
558 
559  void initialize()
560  {
561  this->_ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
562  }
563 };
565 } // namespace interface1
566 using interface1::DistributedContainerIface;
567 using interface1::DistributedContainer;
568 using interface1::DistributedIface;
569 using interface1::Distributed;
570 
571 }
572 }
573 }
574 #endif // __COVARIANCE_DISTRIBUTED_H__
daal::algorithms::covariance::interface1::DistributedIface< step1Local >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:177
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::clone
services::SharedPtr< DistributedIface< step2Master > > clone() const
Definition: covariance_distributed.h:350
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:57
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getPartialResult
PartialResultPtr getPartialResult()
Definition: covariance_distributed.h:297
daal::algorithms::covariance::interface1::DistributedIface< step2Master >
Interface for correlation or variance-covariance matrix computation algorithms in the distributed pro...
Definition: covariance_distributed.h:238
daal::algorithms::covariance::covariance
Definition: covariance_types.h:90
daal::algorithms::covariance::interface1::Distributed
Computes correlation or variance-covariance matrix in the distributed processing mode.
Definition: covariance_distributed.h:400
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::clone
services::SharedPtr< DistributedIface< step1Local > > clone() const
Definition: covariance_distributed.h:207
daal::algorithms::covariance::Method
Method
Definition: covariance_types.h:48
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:188
daal::algorithms::covariance::partialResults
Definition: covariance_types.h:112
daal::algorithms::covariance::defaultDense
Definition: covariance_types.h:50
daal::services::ErrorNullResult
Definition: error_indexes.h:98
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:489
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:455
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface()
Definition: covariance_distributed.h:247
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setPartialResult
virtual services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: covariance_distributed.h:307
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
daal::algorithms::covariance::interface1::DistributedInput< step2Master >
Input parameters of the distributed Covariance algorithm. Represents inputs of the algorithm on maste...
Definition: covariance_types.h:395
daal::algorithms::covariance::interface1::DistributedIface
Interface for the correlation or variance-covariance matrix algorithm in the distributed processing m...
Definition: covariance_distributed.h:152
daal_defines.h
daal::algorithms::covariance::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(MasterInputId id) const
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::parameter
ParameterType parameter
Definition: covariance_distributed.h:356
daal::algorithms::covariance::interface1::OnlineImpl
Abstract class that specifies interface of the algorithms for computing correlation or variance-covar...
Definition: covariance_online.h:289
daal::algorithms::covariance::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: covariance_distributed.h:445
daal::ComputeStep
ComputeStep
Definition: daal_defines.h:121
daal::algorithms::covariance::interface1::Online
Computes correlation or variance-covariance matrix in the online processing mode. ...
Definition: covariance_online.h:412
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: covariance_distributed.h:500
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:425
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:524
daal::algorithms::covariance::interface1::DistributedContainer
Provides methods to run implementations of the correlation or variance-covariance matrix algorithm in...
Definition: covariance_distributed.h:98
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::input
DistributedInput< step2Master > input
Definition: covariance_distributed.h:355
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: covariance_distributed.h:512
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::checkFinalizeComputeParams
services::Status checkFinalizeComputeParams() DAAL_C11_OVERRIDE
Definition: covariance_distributed.h:319
daal::algorithms::covariance::interface1::DistributedIface< step1Local >::DistributedIface
DistributedIface(const DistributedIface< step1Local > &other)
Definition: covariance_distributed.h:198
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::DistributedIface
DistributedIface(const DistributedIface< step2Master > &other)
Definition: covariance_distributed.h:259
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::getResult
ResultPtr getResult()
Definition: covariance_distributed.h:276
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::covariance::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: covariance_distributed.h:532
daal::algorithms::covariance::interface1::DistributedIface< step2Master >::setResult
virtual services::Status setResult(const ResultPtr &result)
Definition: covariance_distributed.h:285

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