ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ReduceMean.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __NNFW_CKER_TRAIN_OPERATION_REDUCEMEAN_H__
18#define __NNFW_CKER_TRAIN_OPERATION_REDUCEMEAN_H__
19
20#include "cker/Shape.h"
21#include "cker/eigen/Utils.h"
23
24namespace nnfw
25{
26namespace cker
27{
28namespace train
29{
30
31template <typename T>
32void MeanGrad(const Shape &incoming_shape, const T *incoming_data, const Shape &grad_shape,
33 T *grad_data)
34{
35 BroadcastTo(incoming_shape, const_cast<T *>(incoming_data), grad_shape, grad_data);
36 const auto incoming = MapAsMatrixWithLastDimAsRows(incoming_data, incoming_shape);
37 auto grad = MapAsMatrixWithLastDimAsRows(grad_data, grad_shape);
38 grad /= (grad.size() / incoming.size());
39}
40
41} // namespace train
42} // namespace cker
43} // namespace nnfw
44
45#endif // __NNFW_CKER_TRAIN_OPERATION_REDUCEMEAN_H__
void MeanGrad(const Shape &incoming_shape, const T *incoming_data, const Shape &grad_shape, T *grad_data)
Definition ReduceMean.h:32
void BroadcastTo(const Shape &input_shape, T *input_data, const Shape &output_shape, T *output_data)
MatrixMap< Scalar > MapAsMatrixWithLastDimAsRows(Scalar *data, const Shape &shape)
Definition Utils.h:60
Definition topk_v2.h:30