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

precomputed_batch.h
1 /* file: precomputed_batch.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 of the objective function with precomputed characteristics.
21 //--
22 */
23 
24 #ifndef __PRECOMPUTED_BATCH_H__
25 #define __PRECOMPUTED_BATCH_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "services/daal_defines.h"
29 #include "objective_function_batch.h"
30 #include "sum_of_functions_batch.h"
31 #include "precomputed_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace optimization_solver
38 {
39 namespace precomputed
40 {
41 namespace interface1
42 {
58 template<typename algorithmFPType, Method method>
59 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
60 {
61 public:
67  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv) {}
68  DAAL_DEPRECATED_VIRTUAL virtual ~BatchContainer() {}
74  DAAL_DEPRECATED_VIRTUAL virtual services::Status compute()
75  {
76  /* empty compute */
77  return services::Status();
78  }
79 };
80 
95 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
96 class DAAL_EXPORT Batch : public sum_of_functions::interface1::Batch
97 {
98 public:
99  typedef sum_of_functions::interface1::Batch super;
100 
101  typedef typename super::InputType InputType;
102  typedef typename super::ParameterType ParameterType;
103  typedef typename super::ResultType ResultType;
104 
105  InputType input;
107  ParameterType parameter;
112  DAAL_DEPRECATED Batch() : parameter(1), super(1, &input, &parameter)
113  {
114  initialize();
115  }
116 
117  DAAL_DEPRECATED_VIRTUAL virtual ~Batch() {}
118 
125  DAAL_DEPRECATED Batch(const Batch<algorithmFPType, method> &other) :
126  parameter(other.parameter), super(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
127  {
128  initialize();
129  const ResultType *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
130  if (otherResult)
131  {
132  bool isResultInitialized = false;
133  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
134  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
135  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
136  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
137  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
138  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
139  if (isResultInitialized)
140  {
141  _res = _result.get();
142  }
143  }
144  }
145 
150  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
151 
157  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
158  {
159  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
160  }
161 
167  DAAL_DEPRECATED services::Status allocate()
168  {
169  return allocateResult();
170  }
171 
172 protected:
173  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
174  {
175  return new Batch<algorithmFPType, method>(*this);
176  }
177 
178  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
179  {
180  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
181  _res = _result.get();
182  return s;
183  }
184 
185  void initialize()
186  {
187  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
188  _in = &input;
189  _par = &parameter;
190  _result = objective_function::ResultPtr(new ResultType());
191  }
192 };
194 } // namespace interface1
195 
196 
197 namespace interface2
198 {
214 template<typename algorithmFPType, Method method>
215 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
216 {
217 public:
223  BatchContainer(daal::services::Environment::env *daalEnv) {}
224  virtual ~BatchContainer() {}
230  virtual services::Status compute()
231  {
232  /* empty compute */
233  return services::Status();
234  }
235 };
236 
251 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
252 class DAAL_EXPORT Batch : public sum_of_functions::Batch
253 {
254 public:
255  typedef sum_of_functions::Batch super;
256 
257  typedef typename super::InputType InputType;
258  typedef typename super::ParameterType ParameterType;
259  typedef typename super::ResultType ResultType;
260 
261  InputType input;
263  ParameterType parameter;
268  Batch() : parameter(1), super(1, &input, &parameter)
269  {
270  initialize();
271  }
272 
273  virtual ~Batch() {}
274 
281  Batch(const Batch<algorithmFPType, method> &other) :
282  parameter(other.parameter), super(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
283  {
284  initialize();
285  const ResultType *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
286  if (otherResult)
287  {
288  bool isResultInitialized = false;
289  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
290  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
291  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
292  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
293  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
294  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
295  if (isResultInitialized)
296  {
297  _res = _result.get();
298  }
299  }
300  }
301 
306  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
307 
313  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
314  {
315  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
316  }
317 
323  services::Status allocate()
324  {
325  return allocateResult();
326  }
327 
328 protected:
329  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
330  {
331  return new Batch<algorithmFPType, method>(*this);
332  }
333 
334  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
335  {
336  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
337  _res = _result.get();
338  return s;
339  }
340 
341  void initialize()
342  {
343  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
344  _in = &input;
345  _par = &parameter;
346  _result = objective_function::ResultPtr(new ResultType());
347  }
348 };
350 } // namespace interface2
351 using interface2::BatchContainer;
352 using interface2::Batch;
353 
354 } // namespace precomputed
355 } // namespace optimization_solver
356 } // namespace algorithms
357 } // namespace daal
358 #endif
daal::algorithms::optimization_solver::precomputed::interface2::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:263
daal::algorithms::optimization_solver::precomputed::interface1::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:107
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:281
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:125
daal::algorithms::optimization_solver::precomputed::interface1::Batch::input
InputType input
Definition: precomputed_batch.h:105
daal::algorithms::optimization_solver::sum_of_functions::interface1::Input
Input objects for the Sum of functions
Definition: sum_of_functions_types.h:113
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:215
daal::algorithms::optimization_solver::precomputed::interface2::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:323
daal::algorithms::optimization_solver::precomputed::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:306
daal::algorithms::optimization_solver::precomputed::interface2::Batch::input
InputType input
Definition: precomputed_batch.h:261
daal::algorithms::optimization_solver::precomputed::interface2::Batch::Batch
Batch()
Definition: precomputed_batch.h:268
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:59
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:63
daal::algorithms::optimization_solver::sum_of_functions::interface1::Parameter
Parameter for the Sum of functions
Definition: sum_of_functions_types.h:71
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:230
daal::algorithms::optimization_solver::precomputed::interface1::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:96
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::compute
virtual DAAL_DEPRECATED_VIRTUAL services::Status compute()
Definition: precomputed_batch.h:74
daal_defines.h
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:86
daal::algorithms::optimization_solver::precomputed::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:223
daal::algorithms::optimization_solver::objective_function::valueIdx
Definition: objective_function_types.h:87
daal::algorithms::optimization_solver::precomputed::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:313
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:150
daal::algorithms::optimization_solver::precomputed::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:157
daal::algorithms::optimization_solver::precomputed::interface1::Batch::allocate
DAAL_DEPRECATED services::Status allocate()
Definition: precomputed_batch.h:167
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:88
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:67
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
DAAL_DEPRECATED Batch()
Definition: precomputed_batch.h:112
daal::algorithms::optimization_solver::precomputed::interface2::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:252

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