15
#include "cumulativesum.h"
19
CumulativeSum::CumulativeSum()
22
support_inplace = true;
25
int CumulativeSum::load_param(const ParamDict& pd)
32
int CumulativeSum::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
34
int dims = bottom_top_blob.dims;
35
int positive_axis = axis < 0 ? dims + axis : axis;
39
int w = bottom_top_blob.w;
41
float* ptr = bottom_top_blob;
43
for (int i = 1; i < w; ++i)
45
ptr[i] = ptr[i] + ptr[i - 1];
51
if (dims == 2 && positive_axis == 0)
54
int w = bottom_top_blob.w;
55
int h = bottom_top_blob.h;
57
for (int i = 1; i < h; ++i)
59
const float* prev_row = bottom_top_blob.row(i - 1);
60
float* this_row = bottom_top_blob.row(i);
62
for (int k = 0; k < w; ++k)
64
this_row[k] = this_row[k] + prev_row[k];
71
if (dims == 2 && positive_axis == 1)
74
int w = bottom_top_blob.w;
75
int h = bottom_top_blob.h;
77
#pragma omp parallel for num_threads(opt.num_threads)
78
for (int i = 0; i < h; ++i)
80
float* ptr = bottom_top_blob.row(i);
82
for (int k = 1; k < w; ++k)
84
ptr[k] = ptr[k] + ptr[k - 1];
91
if (dims == 3 && positive_axis == 0)
94
int w = bottom_top_blob.w;
95
int h = bottom_top_blob.h;
96
int c = bottom_top_blob.c;
100
for (int i = 1; i < c; ++i)
102
const float* prev = bottom_top_blob.channel(i - 1);
103
float* cur = bottom_top_blob.channel(i);
105
for (int k = 0; k < size; ++k)
107
cur[k] = cur[k] + prev[k];
114
if (dims == 3 && positive_axis == 1)
118
int w = bottom_top_blob.w;
119
int h = bottom_top_blob.h;
120
int c = bottom_top_blob.c;
122
#pragma omp parallel for num_threads(opt.num_threads)
123
for (int q = 0; q < c; ++q)
125
Mat this_channel = bottom_top_blob.channel(q);
127
for (int i = 1; i < h; ++i)
129
const float* prev_row = this_channel.row(i - 1);
130
float* this_row = this_channel.row(i);
132
for (int k = 0; k < w; ++k)
134
this_row[k] = this_row[k] + prev_row[k];
142
if (dims == 3 && positive_axis == 2)
146
int w = bottom_top_blob.w;
147
int h = bottom_top_blob.h;
148
int c = bottom_top_blob.c;
150
#pragma omp parallel for num_threads(opt.num_threads)
151
for (int q = 0; q < c; ++q)
153
Mat this_channel = bottom_top_blob.channel(q);
155
for (int i = 0; i < h; ++i)
157
float* ptr = this_channel.row(i);
158
for (int k = 1; k < w; ++k)
160
ptr[k] = ptr[k] + ptr[k - 1];