9 #include <tbb/parallel_for.h>
19 template <
class TFeat,
23 bool POINT_IMPORTANCE>
25 const std::vector<int>& filter_dims,
29 const TFeat* inp_features,
30 const TFeat* inp_importance,
31 size_t neighbors_index_size,
32 const TIndex* neighbors_index,
33 const TKernelIndex* neighbors_kernel_index,
34 const TFeat* neighbors_importance,
35 const int64_t* neighbors_row_splits,
37 const bool NEIGHBOR_IMPORTANCE = neighbors_importance !=
nullptr;
39 const int in_channels = filter_dims[filter_dims.size() - 2];
40 const int out_channels = filter_dims[filter_dims.size() - 1];
42 int num_kernel_elements = 1;
43 for (
int i = 0; i < filter_dims.size() - 2; ++i)
44 num_kernel_elements *= filter_dims[i];
46 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
49 tbb::blocked_range<size_t>(0, num_out, 32),
50 [&](
const tbb::blocked_range<size_t>& r) {
51 int range_length = r.end() - r.begin();
53 Eigen::Matrix<TOut, Eigen::Dynamic, 1> normalizers(range_length,
55 normalizers.setZero();
57 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
58 C(out_features + (r.begin() * out_channels),
59 out_channels, range_length);
61 for (
size_t out_idx = r.begin(); out_idx != r.end();
63 const int out_col = out_idx - r.begin();
64 const size_t neighbor_start = neighbors_row_splits[out_idx];
65 const size_t neighbor_end =
66 neighbors_row_splits[out_idx + 1];
68 for (
size_t n = neighbor_start; n < neighbor_end; ++n) {
69 const size_t inp_idx = neighbors_index[n];
70 const int kernel_idx = neighbors_kernel_index[n];
72 const TFeat n_importance =
73 (NEIGHBOR_IMPORTANCE ? neighbors_importance[n]
75 normalizers(out_col) += TOut(n_importance);
77 TFeat importance(1.0);
79 importance = inp_importance[inp_idx];
80 if (NEIGHBOR_IMPORTANCE) importance *= n_importance;
82 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
84 A(filter + kernel_idx * out_channels *
86 out_channels, in_channels);
88 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
90 B(inp_features + inp_idx * in_channels,
94 (A * (importance *
B)).template cast<TOut>();
100 for (
int i = 0; i < range_length; ++i) {
101 if (normalizers(i) != TOut(0))
102 C.col(i) /= normalizers(i);
153 template <
class TFeat,
class TOut,
class TIndex,
class TKernelIndex>
155 const std::vector<int>& filter_dims,
159 const TFeat* inp_features,
160 const TFeat* inp_importance,
161 size_t neighbors_index_size,
162 const TIndex* neighbors_index,
163 const TKernelIndex* neighbors_kernel_index,
164 const TFeat* neighbors_importance,
165 const int64_t* neighbors_row_splits,
168 bool has_importance = inp_importance;
170 #define FN_PARAMETERS \
171 out_features, filter_dims, filter, num_out, num_inp, inp_features, \
172 inp_importance, neighbors_index_size, neighbors_index, \
173 neighbors_kernel_index, neighbors_importance, \
174 neighbors_row_splits, normalize
176 #define CALL_TEMPLATE(HAS_IMPORTANCE) \
177 if (HAS_IMPORTANCE == has_importance) \
178 _SparseConvComputeFeaturesCPU<TFeat, TOut, TIndex, TKernelIndex, \
179 HAS_IMPORTANCE>(FN_PARAMETERS);
181 #define CALL_TEMPLATE2 \
182 CALL_TEMPLATE(true) \
188 #undef CALL_TEMPLATE2
Eigen::Matrix3d B
Definition: PointCloudPlanarPatchDetection.cpp:512
void _SparseConvComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, size_t num_inp, const TFeat *inp_features, const TFeat *inp_importance, size_t neighbors_index_size, const TIndex *neighbors_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, bool normalize)
Definition: SparseConv.h:24
void SparseConvComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, size_t num_inp, const TFeat *inp_features, const TFeat *inp_importance, size_t neighbors_index_size, const TIndex *neighbors_index, const TKernelIndex *neighbors_kernel_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, bool normalize)
Definition: SparseConv.h:154
Definition: PinholeCameraIntrinsic.cpp:16