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

precomputed_batch.h
1 /* file: precomputed_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 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::interface1::Batch
95 {
96 public:
97  typedef sum_of_functions::interface1::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 
194 
195 namespace interface2
196 {
212 template<typename algorithmFPType, Method method>
213 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
214 {
215 public:
221  BatchContainer(daal::services::Environment::env *daalEnv) {}
222  virtual ~BatchContainer() {}
228  virtual services::Status compute()
229  {
230  /* empty compute */
231  return services::Status();
232  }
233 };
234 
249 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
250 class DAAL_EXPORT Batch : public sum_of_functions::Batch
251 {
252 public:
253  typedef sum_of_functions::Batch super;
254 
255  typedef typename super::InputType InputType;
256  typedef typename super::ParameterType ParameterType;
257  typedef typename super::ResultType ResultType;
258 
259  InputType input;
261  ParameterType parameter;
266  Batch() : parameter(1), super(1, &input, &parameter)
267  {
268  initialize();
269  }
270 
271  virtual ~Batch() {}
272 
279  Batch(const Batch<algorithmFPType, method> &other) :
280  parameter(other.parameter), super(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
281  {
282  initialize();
283  const ResultType *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
284  if (otherResult)
285  {
286  bool isResultInitialized = false;
287  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
288  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
289  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
290  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
291  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
292  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
293  if (isResultInitialized)
294  {
295  _res = _result.get();
296  }
297  }
298  }
299 
304  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
305 
311  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
312  {
313  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
314  }
315 
321  services::Status allocate()
322  {
323  return allocateResult();
324  }
325 
326 protected:
327  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
328  {
329  return new Batch<algorithmFPType, method>(*this);
330  }
331 
332  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
333  {
334  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
335  _res = _result.get();
336  return s;
337  }
338 
339  void initialize()
340  {
341  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
342  _in = &input;
343  _par = &parameter;
344  _result = objective_function::ResultPtr(new ResultType());
345  }
346 };
348 } // namespace interface2
349 using interface2::BatchContainer;
350 using interface2::Batch;
351 
352 } // namespace precomputed
353 } // namespace optimization_solver
354 } // namespace algorithms
355 } // namespace daal
356 #endif
daal::algorithms::optimization_solver::sum_of_functions::interface1::Input
Input objects for the Sum of functions
Definition: sum_of_functions_types.h:111
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::interface2::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:321
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::interface2::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:228
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::algorithms::optimization_solver::precomputed::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:304
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch()
Definition: precomputed_batch.h:266
daal_defines.h
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:84
daal::algorithms::optimization_solver::sum_of_functions::interface1::Batch
Interface for computing the Sum of functions in the batch processing mode.
Definition: sum_of_functions_batch.h:61
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:86
daal::algorithms::optimization_solver::sum_of_functions::interface1::Parameter
Parameter for the Sum of functions
Definition: sum_of_functions_types.h:69
daal::algorithms::optimization_solver::objective_function::valueIdx
Definition: objective_function_types.h:85
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::interface2::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:250
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::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:311
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:213
daal::algorithms::optimization_solver::precomputed::interface2::Batch::input
InputType input
Definition: precomputed_batch.h:259
daal::algorithms::optimization_solver::precomputed::interface2::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:261
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:148
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:221
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:279

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