22 tensorflow::OpKernelConstruction* construction)
23 : OpKernel(construction) {
24 using namespace tensorflow;
26 OP_REQUIRES_OK(construction,
28 OP_REQUIRES_OK(construction,
29 construction->GetAttr(
"normalize", &
normalize));
31 std::string interpolation_str;
32 OP_REQUIRES_OK(construction, construction->GetAttr(
"interpolation",
35 if (interpolation_str ==
"linear")
37 else if (interpolation_str ==
"linear_border")
42 std::string mapping_str;
43 OP_REQUIRES_OK(construction, construction->GetAttr(
"coordinate_mapping",
46 if (mapping_str ==
"ball_to_cube_radial")
48 else if (mapping_str ==
"ball_to_cube_volume_preserving")
50 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
54 OP_REQUIRES_OK(construction, construction->GetAttr(
"max_temp_mem_MB",
59 using namespace tensorflow;
60 static_assert(
sizeof(int64_t) ==
sizeof(int64_t),
61 "int64_t type is not compatible");
62 const Tensor& filter =
context->input(0);
64 const Tensor& out_positions =
context->input(1);
66 out_positions.shape().dim_size(0) <=
67 std::numeric_limits<TIndex>::max(),
68 absl::InvalidArgumentError(
"Too many output points"));
70 const Tensor& extents =
context->input(2);
72 context, extents.shape().dims() == 2,
73 absl::InvalidArgumentError(
"extents must be a rank 2 tensor"));
76 extents.shape().dim_size(0) ==
77 out_positions.shape().dim_size(0) ||
78 extents.shape().dim_size(0) == 1,
79 absl::InvalidArgumentError(
"number of extents must match the "
80 "number of out_positions or must "
83 extents.shape().dim_size(1) == 3 ||
84 extents.shape().dim_size(1) == 1,
85 absl::InvalidArgumentError(
86 "number of components for extents must be 3 or 1"));
91 absl::InvalidArgumentError(
"offset must be a rank 1 tensor"));
93 absl::InvalidArgumentError(
"offset length must be 3"));
95 const Tensor& inp_positions =
context->input(4);
97 inp_positions.shape().dim_size(0) <=
98 std::numeric_limits<TIndex>::max(),
99 absl::InvalidArgumentError(
"Too many input points"));
101 const Tensor& inp_features =
context->input(5);
103 const Tensor& inp_importance =
context->input(6);
105 const Tensor& neighbors_index =
context->input(7);
107 const Tensor& neighbors_importance =
context->input(8);
109 const Tensor& neighbors_row_splits =
context->input(9);
112 inp_positions.shape().dim_size(0) ==
113 inp_features.shape().dim_size(0),
114 absl::InvalidArgumentError(
115 "first dim of inp_positions does not "
116 "match the first dim of inp_features"));
120 inp_positions.shape().dim_size(0) ==
121 inp_importance.shape().dim_size(0) ||
122 inp_importance.shape().dim_size(0) == 0,
123 absl::InvalidArgumentError(
"first dim of inp_positions does "
124 "not match the first dim of "
129 neighbors_importance.shape().dim_size(0) ==
130 neighbors_index.shape().dim_size(0) ||
131 neighbors_importance.shape().dim_size(0) == 0,
132 absl::InvalidArgumentError(
"first dim of neighbors_importance "
133 "does not match the first dim of "
138 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
139 absl::InvalidArgumentError(
"number of input channels in filter "
140 "and inp_features does not match"));
142 TensorShape out_features_shape({out_positions.shape().dim_size(0),
143 filter.shape().dim_size(4)});
144 Tensor* out_features =
nullptr;
145 OP_REQUIRES_OK(
context,
context->allocate_output(0, out_features_shape,
148 std::vector<int> filter_dims({
149 int(filter.shape().dim_size(0)),
150 int(filter.shape().dim_size(1)),
151 int(filter.shape().dim_size(2)),
152 int(filter.shape().dim_size(3)),
153 int(filter.shape().dim_size(4)),
156 bool individual_extents = extents.shape().dim_size(0) ==
157 out_positions.shape().dim_size(0) &&
158 extents.shape().dim_size(0) > 1;
160 bool isotropic_extents = extents.shape().dim_size(1) == 1;
162 bool point_importances = inp_importance.shape().dim_size(0) != 0;
164 bool has_neighbors_importances =
165 neighbors_importance.shape().dim_size(0) != 0;
168 inp_features, inp_importance, neighbors_index,
169 neighbors_importance, neighbors_row_splits, filter_dims,
170 individual_extents, isotropic_extents, point_importances,
171 has_neighbors_importances, *out_features);