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

softmax_cross_layer_backward.h
1 /* file: softmax_cross_layer_backward.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 interface for the backward softmax cross-entropy layer in the batch processing mode
21 //--
22 */
23 
24 #ifndef __NEURAL_NENTWORK_LOSS_SOFTMAX_CROSS_LAYER_BACKWARD_H__
25 #define __NEURAL_NENTWORK_LOSS_SOFTMAX_CROSS_LAYER_BACKWARD_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/tensor.h"
29 #include "services/daal_defines.h"
30 #include "algorithms/neural_networks/layers/layer.h"
31 #include "algorithms/neural_networks/layers/loss/loss_layer_backward.h"
32 #include "algorithms/neural_networks/layers/loss/softmax_cross_layer_types.h"
33 #include "algorithms/neural_networks/layers/loss/softmax_cross_layer_backward_types.h"
34 
35 namespace daal
36 {
37 namespace algorithms
38 {
39 namespace neural_networks
40 {
41 namespace layers
42 {
43 namespace loss
44 {
45 namespace softmax_cross
46 {
47 namespace backward
48 {
49 namespace interface1
50 {
68 template<typename algorithmFPType, Method method, CpuType cpu>
69 class BatchContainer : public AnalysisContainerIface<batch>
70 {
71 public:
78  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
83  DAAL_DEPRECATED ~BatchContainer();
90  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
91 };
92 
113 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
114 class Batch : public loss::backward::Batch
115 {
116 public:
117  typedef loss::backward::Batch super;
118 
119  typedef algorithms::neural_networks::layers::loss::softmax_cross::backward::Input InputType;
120  typedef algorithms::neural_networks::layers::loss::softmax_cross::Parameter ParameterType;
121  typedef algorithms::neural_networks::layers::loss::softmax_cross::backward::Result ResultType;
122 
123  ParameterType &parameter;
124  InputType input;
130  DAAL_DEPRECATED Batch() : parameter(_defaultParameter)
131  {
132  initialize();
133  };
134 
141  Batch(ParameterType& parameter) : parameter(parameter), _defaultParameter(parameter)
142  {
143  initialize();
144  }
145 
146 
154  Batch(const Batch<algorithmFPType, method> &other) : super(other),
155  _defaultParameter(other.parameter), parameter(_defaultParameter), input(other.input)
156  {
157  initialize();
158  }
159 
165  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
166 
172  DAAL_DEPRECATED_VIRTUAL virtual InputType *getLayerInput() DAAL_C11_OVERRIDE { return &input; }
173 
179  DAAL_DEPRECATED_VIRTUAL virtual ParameterType *getLayerParameter() DAAL_C11_OVERRIDE { return &parameter; };
180 
186  DAAL_DEPRECATED layers::backward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
187  {
188  return _result;
189  }
190 
196  DAAL_DEPRECATED ResultPtr getResult()
197  {
198  return _result;
199  }
200 
208  DAAL_DEPRECATED services::Status setResult(const ResultPtr& result)
209  {
210  DAAL_CHECK(result, services::ErrorNullResult)
211  _result = result;
212  _res = _result.get();
213  return services::Status();
214  }
215 
223  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
224  {
225  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
226  }
227 
234  DAAL_DEPRECATED_VIRTUAL virtual services::Status allocateResult() DAAL_C11_OVERRIDE
235  {
236  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
237  this->_res = this->_result.get();
238  return s;
239  }
240 
241 protected:
242  /*
243  * \DAAL_DEPRECATED
244  */
245  DAAL_DEPRECATED_VIRTUAL virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
246  {
247  return new Batch<algorithmFPType, method>(*this);
248  }
249 
250  /*
251  * \DAAL_DEPRECATED
252  */
253  void initialize()
254  {
255  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
256  _in = &input;
257  _par = &parameter;
258  _result.reset(new ResultType());
259  }
260 
261 private:
262  ResultPtr _result;
263  ParameterType _defaultParameter;
264 };
266 } // namespace interface1
267 using interface1::BatchContainer;
268 using interface1::Batch;
269 } // namespace backward
270 } // namespace softmax_cross
271 } // namespace loss
272 } // namespace layers
273 } // namespace neural_networks
274 } // namespace algorithms
275 } // namespace daal
276 #endif
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::Batch
DAAL_DEPRECATED Batch()
Definition: softmax_cross_layer_backward.h:130
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::input
InputType input
Definition: softmax_cross_layer_backward.h:124
daal::batch
Definition: daal_defines.h:112
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::Batch
Batch(ParameterType &parameter)
Definition: softmax_cross_layer_backward.h:141
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch
Provides methods for the backward softmax cross-entropy layer in the batch processing mode...
Definition: softmax_cross_layer_backward.h:114
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: softmax_cross_layer_backward.h:223
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::allocateResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: softmax_cross_layer_backward.h:234
daal_defines.h
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::getLayerParameter
virtual DAAL_DEPRECATED_VIRTUAL ParameterType * getLayerParameter() DAAL_C11_OVERRIDE
Definition: softmax_cross_layer_backward.h:179
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::parameter
ParameterType & parameter
Definition: softmax_cross_layer_backward.h:123
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: softmax_cross_layer_backward.h:165
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::getLayerInput
virtual DAAL_DEPRECATED_VIRTUAL InputType * getLayerInput() DAAL_C11_OVERRIDE
Definition: softmax_cross_layer_backward.h:172
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::BatchContainer
Provides methods to run implementations of the of the backward softmax cross-entropy layer This class...
Definition: softmax_cross_layer_backward.h:69
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::getResult
DAAL_DEPRECATED ResultPtr getResult()
Definition: softmax_cross_layer_backward.h:196
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::setResult
DAAL_DEPRECATED services::Status setResult(const ResultPtr &result)
Definition: softmax_cross_layer_backward.h:208
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::getLayerResult
DAAL_DEPRECATED layers::backward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: softmax_cross_layer_backward.h:186
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: softmax_cross_layer_backward.h:154
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::neural_networks::layers::loss::softmax_cross::backward::interface1::BatchContainer::compute
DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE

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