SparseToDense.h 1.26 KB
Newer Older
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
1
2
3
4
5
6
7
8
9
10
11
12
// Copyright 2016-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.

#ifndef CPU_SPARSETODENSE_H
#define CPU_SPARSETODENSE_H
#include "../SparseConvNet.h"

template <typename T>
void SparseToDense_ForwardPass(T *input_features, T *output_features,
13
14
15
16
17
18
19
20
                               uInt nPlanes, uInt spatialVolume, uInt *rules,
                               int nHot) {
  for (uInt outSite = 0; outSite < nHot; outSite++) {
    T *i = input_features + rules[2 * outSite] * nPlanes;
    T *o = output_features + rules[2 * outSite + 1];
    for (uInt plane = 0; plane < nPlanes; plane++)
      o[plane * spatialVolume] = i[plane];
  }
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
21
22
23
24
}

template <typename T>
void SparseToDense_BackwardPass(T *d_input_features, T *d_output_features,
25
26
                                uInt nPlanes, uInt spatialVolume, uInt *rules,
                                int nHot) {
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
27

28
29
  for (uInt outSite = 0; outSite < nHot; outSite++) {
    T *d_i = d_input_features + rules[2 * outSite] * nPlanes;
Benjamin Thomas Graham's avatar
tidy  
Benjamin Thomas Graham committed
30
    T *d_o = d_output_features + rules[2 * outSite + 1];
31
32
33
34
    for (uInt plane = 0; plane < nPlanes; plane++)
      d_i[plane] = d_o[plane * spatialVolume];
  }
}
Benjamin Thomas Graham's avatar
Benjamin Thomas Graham committed
35
#endif /* CPU_SPARSETODENSE_H */