31 const std::vector<int>& filter_dims,
34 const TReal* out_positions,
36 const TReal* inp_positions,
37 const TFeat* inp_features,
38 const TFeat* inp_importance,
39 size_t neighbors_index_size,
40 const TIndex* neighbors_index,
41 const TFeat* neighbors_importance,
42 const int64_t* neighbors_row_splits,
46 const bool NEIGHBORS_IMPORTANCE = neighbors_importance !=
nullptr;
48 typedef Eigen::Array<TReal, VECSIZE, 1> Vec_t;
50 InterpolationVec_t interpolation;
52 const int in_channels = filter_dims[filter_dims.size() - 2];
53 const int out_channels = filter_dims[filter_dims.size() - 1];
55 int spatial_filter_size = 1;
56 for (
int i = 0; i < 3; ++i) spatial_filter_size *= filter_dims[i];
57 Eigen::Array<int, 3, 1> filter_size_xyz(filter_dims[2], filter_dims[1],
60 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
62 typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
63 typedef Eigen::Array<TReal, VECSIZE, 3> Matrix3C;
66 tbb::blocked_range<size_t>(0, num_out, 32),
67 [&](
const tbb::blocked_range<size_t>& r) {
68 int range_length = r.end() - r.begin();
70 Eigen::Matrix<TOut, Eigen::Dynamic, 1> normalizers(range_length,
72 normalizers.setZero();
74 Eigen::Matrix<TFeat, Eigen::Dynamic, Eigen::Dynamic>
B(
75 in_channels * spatial_filter_size, range_length);
78 Matrix infeat(
VECSIZE, in_channels);
80 Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
84 if (INDIVIDUAL_EXTENT ==
false) {
85 if (ISOTROPIC_EXTENT) {
86 inv_extents = 1 / extents[0];
88 inv_extents.col(0) = 1 / extents[0];
89 inv_extents.col(1) = 1 / extents[1];
90 inv_extents.col(2) = 1 / extents[2];
94 for (
size_t out_idx = r.begin(); out_idx != r.end();
96 const int out_col = out_idx - r.begin();
97 const size_t neighbor_start = neighbors_row_splits[out_idx];
98 const size_t neighbor_end =
99 neighbors_row_splits[out_idx + 1];
101 if (INDIVIDUAL_EXTENT) {
102 if (ISOTROPIC_EXTENT) {
103 inv_extents = 1 / extents[out_idx];
105 inv_extents.col(0) = 1 / extents[3 * out_idx + 0];
106 inv_extents.col(1) = 1 / extents[3 * out_idx + 1];
107 inv_extents.col(2) = 1 / extents[3 * out_idx + 2];
111 typename InterpolationVec_t::Weight_t interp_weights;
112 typename InterpolationVec_t::Idx_t interp_indices;
114 int vec_valid_count = 0;
122 for (
size_t n = neighbor_start; n < neighbor_end; ++n) {
123 const size_t inp_idx = neighbors_index[n];
124 const int i = vec_valid_count;
125 x(i) = inp_positions[inp_idx * 3 + 0] -
126 out_positions[out_idx * 3 + 0];
127 y(i) = inp_positions[inp_idx * 3 + 1] -
128 out_positions[out_idx * 3 + 1];
129 z(i) = inp_positions[inp_idx * 3 + 2] -
130 out_positions[out_idx * 3 + 2];
132 const TFeat n_importance =
133 (NEIGHBORS_IMPORTANCE ? neighbors_importance[n]
135 normalizers(out_col) += TOut(n_importance);
137 for (
int ic = 0; ic < in_channels; ++ic)
139 inp_features[inp_idx * in_channels + ic];
141 TFeat importance(1.0);
142 if (POINT_IMPORTANCE)
143 importance = inp_importance[inp_idx];
144 if (NEIGHBORS_IMPORTANCE) importance *= n_importance;
146 if (POINT_IMPORTANCE || NEIGHBORS_IMPORTANCE) {
147 for (
int ic = 0; ic < in_channels; ++ic)
148 infeat(i, ic) *= importance;
152 if (vec_valid_count ==
VECSIZE) {
153 ComputeFilterCoordinates<ALIGN_CORNERS, MAPPING>(
154 x, y, z, filter_size_xyz, inv_extents,
156 interpolation.Interpolate(
157 interp_weights, interp_indices, x, y, z,
158 filter_size_xyz, in_channels);
159 for (
int k = 0; k <
VECSIZE; ++k)
160 for (
int j = 0; j < InterpolationVec_t::Size();
162 for (
int ic = 0; ic < in_channels; ++ic)
163 B(interp_indices(j, k) + ic, out_col) +=
164 TFeat(interp_weights(j, k)) *
170 if (vec_valid_count) {
171 ComputeFilterCoordinates<ALIGN_CORNERS, MAPPING>(
172 x, y, z, filter_size_xyz, inv_extents,
174 interpolation.Interpolate(interp_weights,
175 interp_indices, x, y, z,
176 filter_size_xyz, in_channels);
177 for (
int k = 0; k < vec_valid_count; ++k)
178 for (
int j = 0; j < InterpolationVec_t::Size();
180 for (
int ic = 0; ic < in_channels; ++ic)
181 B(interp_indices(j, k) + ic, out_col) +=
182 TFeat(interp_weights(j, k)) *
189 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
191 A(filter, out_channels,
192 spatial_filter_size * in_channels);
193 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
194 C(out_features + (r.begin() * out_channels),
195 out_channels, range_length);
197 C = (A *
B).
template cast<TOut>();
199 for (
int i = 0; i < range_length; ++i) {
200 if (normalizers(i) != TOut(0))
201 C.col(i) /= normalizers(i);