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

precomputed_batch.h
1 /* file: precomputed_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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  sum_of_functions::Input input;
125  sum_of_functions::Parameter parameter;
130  Batch() : parameter(1), sum_of_functions::Batch(1, &input, &parameter)
131  {
132  initialize();
133  }
134 
135  virtual ~Batch() {}
136 
143  Batch(const Batch<algorithmFPType, method> &other) :
144  parameter(other.parameter), sum_of_functions::Batch(other.parameter.numberOfTerms, &input, &parameter), input(other.input)
145  {
146  initialize();
147  const objective_function::Result *otherResult = const_cast<Batch<algorithmFPType, method> &>(other).getResult().get();
148  if (otherResult)
149  {
150  bool isResultInitialized = false;
151  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::gradientIdx));
152  _result->set(objective_function::gradientIdx, otherResult->get(objective_function::gradientIdx));
153  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::valueIdx));
154  _result->set(objective_function::valueIdx, otherResult->get(objective_function::valueIdx));
155  isResultInitialized = (isResultInitialized || otherResult->get(objective_function::hessianIdx));
156  _result->set(objective_function::hessianIdx, otherResult->get(objective_function::hessianIdx));
157  if (isResultInitialized)
158  {
159  _res = _result.get();
160  }
161  }
162  }
163 
168  virtual int getMethod() const DAAL_C11_OVERRIDE { return (int)method; }
169 
175  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
176  {
177  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
178  }
179 
185  services::Status allocate()
186  {
187  return allocateResult();
188  }
189 
190 protected:
191  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
192  {
193  return new Batch<algorithmFPType, method>(*this);
194  }
195 
196  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
197  {
198  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
199  _res = _result.get();
200  return s;
201  }
202 
203  void initialize()
204  {
205  Analysis<batch>::_ac = new BatchContainer<algorithmFPType, method>(&_env);
206  _in = &input;
207  _par = &parameter;
208  _result = objective_function::ResultPtr(new objective_function::Result());
209  }
210 };
212 } // namespace interface1
213 using interface1::BatchContainer;
214 using interface1::Batch;
215 
216 } // namespace precomputed
217 } // namespace optimization_solver
218 } // namespace algorithms
219 } // namespace daal
220 #endif
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch()
Definition: precomputed_batch.h:130
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::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
sum_of_functions::Input input
Definition: precomputed_batch.h:123
daal_defines.h
daal::algorithms::optimization_solver::objective_function::gradientIdx
Definition: objective_function_types.h:104
daal::algorithms::optimization_solver::objective_function::hessianIdx
Definition: objective_function_types.h:106
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::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: precomputed_batch.h:175
daal::algorithms::optimization_solver::precomputed::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: precomputed_batch.h:143
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:185
daal::algorithms::optimization_solver::precomputed::interface1::Batch::parameter
sum_of_functions::Parameter parameter
Definition: precomputed_batch.h:125
daal::algorithms::optimization_solver::precomputed::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: precomputed_batch.h:168

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