MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReduceWindow3DAdd

Method ReduceWindow3DAdd

tensorflow/compiler/xla/reference_util.cc:187–229  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

185}
186
187/* static */ std::unique_ptr<Array3D<float>> ReferenceUtil::ReduceWindow3DAdd(
188 const Array3D<float>& operand, float init, absl::Span<const int64> window,
189 absl::Span<const int64> stride, Padding padding) {
190 std::vector<int64> dim_lengths{operand.n1(), operand.n2(), operand.n3()};
191 auto padding_both = xla::MakePadding(dim_lengths, window, stride, padding);
192
193 std::vector<int64> window_counts(window.size(), 0);
194 std::vector<int64> pad_low(window.size(), 0);
195 for (int64 i = 0; i < window.size(); ++i) {
196 window_counts[i] =
197 WindowCount(dim_lengths[i], window[i], stride[i], padding);
198 pad_low[i] = padding_both[i].first;
199 }
200 auto result = absl::make_unique<Array3D<float>>(
201 window_counts[0], window_counts[1], window_counts[2]);
202
203 for (int64 i0 = 0; i0 < window_counts[0]; ++i0) {
204 for (int64 i1 = 0; i1 < window_counts[1]; ++i1) {
205 for (int64 i2 = 0; i2 < window_counts[2]; ++i2) {
206 int64 i0_base = i0 * stride[0] - pad_low[0];
207 int64 i1_base = i1 * stride[1] - pad_low[1];
208 int64 i2_base = i2 * stride[2] - pad_low[2];
209
210 float val = init;
211 for (int64 i0_win = 0; i0_win < window[0]; ++i0_win) {
212 for (int64 i1_win = 0; i1_win < window[1]; ++i1_win) {
213 for (int64 i2_win = 0; i2_win < window[2]; ++i2_win) {
214 if (i0_base + i0_win >= 0 && i1_base + i1_win >= 0 &&
215 i2_base + i2_win >= 0 && i0_base + i0_win < operand.n1() &&
216 i1_base + i1_win < operand.n2() &&
217 i2_base + i2_win < operand.n3()) {
218 val += operand(i0_base + i0_win, i1_base + i1_win,
219 i2_base + i2_win);
220 }
221 }
222 }
223 }
224 (*result)(i0, i1, i2) = val;
225 }
226 }
227 }
228 return result;
229}
230
231/* static */ std::unique_ptr<Array4D<float>>
232ReferenceUtil::ReduceWindow4DGeneric(

Callers

nothing calls this directly

Calls 5

MakePaddingFunction · 0.85
n1Method · 0.45
n2Method · 0.45
n3Method · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected