C++ API Reference for Intel® Data Analytics Acceleration Library 2019

precomputed_batch.h
1 /* file: precomputed_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the of the objective function with precomputed characteristics.
19 //--
20 */
21 
22 #ifndef __PRECOMPUTED_BATCH_H__
23 #define __PRECOMPUTED_BATCH_H__
24 
25 #include "algorithms/algorithm.h"
26 #include "services/daal_defines.h"
27 #include "objective_function_batch.h"
28 #include "sum_of_functions_batch.h"
29 #include "precomputed_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace optimization_solver
36 {
37 namespace precomputed
38 {
39 namespace interface1
40 {
56 template<typename algorithmFPType, Method method>
57 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
58 {
59 public:
65  BatchContainer(daal::services::Environment::env *daalEnv) {}
66  virtual ~BatchContainer() {}
72  virtual services::Status compute()
73  {
74  /* empty compute */
75  return services::Status();
76  }
77 };
78 
93 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
94 class DAAL_EXPORT Batch : public sum_of_functions::Batch
95 {
96 public:
97  typedef sum_of_functions::Batch super;
98 
99  typedef typename super::InputType InputType;
100  typedef typename super::ParameterType ParameterType;
101  typedef typename super::ResultType ResultType;
102 
103  InputType input;
105  ParameterType parameter;
110  Batch() : parameter(1), super(1, &input, &parameter)
111  {
112  initialize();
113  }
114 
115  virtual ~Batch() {}
116 
123  Batch(const Batch<algorithmFPType, method> &other) :
124  parameter(other.parameter), super(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
125  {
126  initialize();
127  const ResultType *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
128  if (otherResult)
129  {
130  bool isResultInitialized = false;
131  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
132  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
133  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
134  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
135  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
136  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
137  if (isResultInitialized)
138  {
139  _res = _result.get();
140  }
141  }
142  }
143 
148  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
149 
155  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
156  {
157  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
158  }
159 
165  services::Status allocate()
166  {
167  return allocateResult();
168  }
169 
170 protected:
171  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
172  {
173  return new Batch<algorithmFPType, method>(*this);
174  }
175 
176  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
177  {
178  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
179  _res = _result.get();
180  return s;
181  }
182 
183  void initialize()
184  {
185  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
186  _in = &input;
187  _par = &parameter;
188  _result = objective_function::ResultPtr(new ResultType());
189  }
190 };
192 } // namespace interface1
193 using interface1::BatchContainer;
194 using interface1::Batch;
195 
196 } // namespace precomputed
197 } // namespace optimization_solver
198 } // namespace algorithms
199 } // namespace daal
200 #endif
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch()
Definition: precomputed_batch.h:110
daal
Definition: algorithm_base_common.h:31
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:57
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:65
daal::algorithms::optimization_solver::precomputed::interface1::Batch::input
InputType input
Definition: precomputed_batch.h:103
daal_defines.h
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:78
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:80
daal::algorithms::optimization_solver::objective_function::valueIdx
Definition: objective_function_types.h:79
daal::algorithms::optimization_solver::precomputed::interface1::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:94
daal::algorithms::optimization_solver::precomputed::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:155
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:123
daal::algorithms::optimization_solver::precomputed::interface1::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:105
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:72
daal::algorithms::optimization_solver::precomputed::interface1::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:165
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:148

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