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

precomputed_batch.h
1 /* file: precomputed_batch.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 of the objective function with precomputed characteristics.
45 //--
46 */
47 
48 #ifndef __PRECOMPUTED_BATCH_H__
49 #define __PRECOMPUTED_BATCH_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "services/daal_defines.h"
53 #include "objective_function_batch.h"
54 #include "sum_of_functions_batch.h"
55 #include "precomputed_types.h"
56 
57 namespace daal
58 {
59 namespace algorithms
60 {
61 namespace optimization_solver
62 {
63 namespace precomputed
64 {
65 namespace interface1
66 {
82 template<typename algorithmFPType, Method method>
83 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
84 {
85 public:
91  BatchContainer(daal::services::Environment::env *daalEnv) {}
92  virtual ~BatchContainer() {}
98  virtual services::Status compute()
99  {
100  /* empty compute */
101  return services::Status();
102  }
103 };
104 
119 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
120 class DAAL_EXPORT Batch : public sum_of_functions::Batch
121 {
122 public:
123  typedef sum_of_functions::Batch super;
124 
125  typedef typename super::InputType InputType;
126  typedef typename super::ParameterType ParameterType;
127  typedef typename super::ResultType ResultType;
128 
129  InputType input;
131  ParameterType parameter;
136  Batch() : parameter(1), super(1, &input, &parameter)
137  {
138  initialize();
139  }
140 
141  virtual ~Batch() {}
142 
149  Batch(const Batch<algorithmFPType, method> &other) :
150  parameter(other.parameter), super(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
151  {
152  initialize();
153  const ResultType *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
154  if (otherResult)
155  {
156  bool isResultInitialized = false;
157  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
158  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
159  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
160  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
161  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
162  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
163  if (isResultInitialized)
164  {
165  _res = _result.get();
166  }
167  }
168  }
169 
174  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
175 
181  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
182  {
183  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
184  }
185 
191  services::Status allocate()
192  {
193  return allocateResult();
194  }
195 
196 protected:
197  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
198  {
199  return new Batch<algorithmFPType, method>(*this);
200  }
201 
202  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
203  {
204  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
205  _res = _result.get();
206  return s;
207  }
208 
209  void initialize()
210  {
211  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
212  _in = &input;
213  _par = &parameter;
214  _result = objective_function::ResultPtr(new ResultType());
215  }
216 };
218 } // namespace interface1
219 using interface1::BatchContainer;
220 using interface1::Batch;
221 
222 } // namespace precomputed
223 } // namespace optimization_solver
224 } // namespace algorithms
225 } // namespace daal
226 #endif
daal::algorithms::optimization_solver::sum_of_functions::interface1::Input
Input objects for the Sum of functions
Definition: sum_of_functions_types.h:137
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch()
Definition: precomputed_batch.h:136
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::optimization_solver::objective_function::interface1::Result
Provides methods to access final results obtained with the compute() method of the Objective function...
Definition: objective_function_types.h:186
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer
Provides methods to run implementations of the objective function with precomputed characteristics...
Definition: precomputed_batch.h:83
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
Definition: precomputed_batch.h:91
daal::algorithms::optimization_solver::precomputed::interface1::Batch::input
InputType input
Definition: precomputed_batch.h:129
daal_defines.h
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:104
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:87
daal::algorithms::optimization_solver::objective_function::interface1::Input
Input objects for the Objective function
Definition: objective_function_types.h:146
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:106
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::optimization_solver::sum_of_functions::interface1::Parameter
Parameter for the Sum of functions
Definition: sum_of_functions_types.h:95
daal::algorithms::optimization_solver::objective_function::valueIdx
Definition: objective_function_types.h:105
daal::algorithms::optimization_solver::precomputed::interface1::Batch
Computes the objective function with precomputed characteristics in the batch processing mode...
Definition: precomputed_batch.h:120
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:149
daal::algorithms::optimization_solver::precomputed::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:181
daal::algorithms::optimization_solver::precomputed::interface1::Batch::~Batch
virtual ~Batch()
Definition: precomputed_batch.h:141
daal::algorithms::optimization_solver::precomputed::interface1::Batch::parameter
ParameterType parameter
Definition: precomputed_batch.h:131
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
daal::algorithms::optimization_solver::precomputed::interface1::BatchContainer::compute
virtual services::Status compute()
Definition: precomputed_batch.h:98
daal::algorithms::optimization_solver::precomputed::interface1::Batch::allocate
services::Status allocate()
Definition: precomputed_batch.h:191
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:174
daal::algorithms::optimization_solver::objective_function::interface1::Parameter
Parameter for the Objective function
Definition: objective_function_types.h:122
daal::algorithms::optimization_solver::objective_function::interface1::Result::get
data_management::NumericTablePtr get(ResultId id) const

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