19 tensorflow::OpKernelConstruction* construction)
20 : OpKernel(construction) {
21 using namespace tensorflow;
23 OP_REQUIRES_OK(construction,
25 OP_REQUIRES_OK(construction,
26 construction->GetAttr(
"normalize", &
normalize));
28 std::string interpolation_str;
29 OP_REQUIRES_OK(construction, construction->GetAttr(
"interpolation",
32 if (interpolation_str ==
"linear")
34 else if (interpolation_str ==
"linear_border")
39 std::string mapping_str;
40 OP_REQUIRES_OK(construction, construction->GetAttr(
"coordinate_mapping",
43 if (mapping_str ==
"ball_to_cube_radial")
45 else if (mapping_str ==
"ball_to_cube_volume_preserving")
47 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
51 OP_REQUIRES_OK(construction, construction->GetAttr(
"max_temp_mem_MB",
56 using namespace tensorflow;
57 static_assert(
sizeof(int64) ==
sizeof(int64_t),
58 "int64 type is not compatible");
59 const Tensor& filter =
context->input(0);
61 const Tensor& out_positions =
context->input(1);
63 out_positions.shape().dim_size(0) <=
64 std::numeric_limits<TIndex>::max(),
65 errors::InvalidArgument(
"Too many output points"));
67 const Tensor& extents =
context->input(2);
68 OP_REQUIRES(
context, extents.shape().dims() == 2,
69 errors::InvalidArgument(
"extents must be a rank 2 tensor"));
71 extents.shape().dim_size(0) ==
72 out_positions.shape().dim_size(0) ||
73 extents.shape().dim_size(0) == 1,
74 errors::InvalidArgument(
"number of extents must match the "
75 "number of out_positions or must "
78 extents.shape().dim_size(1) == 3 ||
79 extents.shape().dim_size(1) == 1,
80 errors::InvalidArgument(
81 "number of components for extents must be 3 or 1"));
85 errors::InvalidArgument(
"offset must be a rank 1 tensor"));
87 errors::InvalidArgument(
"offset length must be 3"));
89 const Tensor& inp_positions =
context->input(4);
91 inp_positions.shape().dim_size(0) <=
92 std::numeric_limits<TIndex>::max(),
93 errors::InvalidArgument(
"Too many input points"));
95 const Tensor& inp_features =
context->input(5);
97 const Tensor& inp_importance =
context->input(6);
99 const Tensor& neighbors_index =
context->input(7);
101 const Tensor& neighbors_importance =
context->input(8);
103 const Tensor& neighbors_row_splits =
context->input(9);
107 inp_positions.shape().dim_size(0) ==
108 inp_features.shape().dim_size(0),
109 errors::InvalidArgument(
"first dim of inp_positions does not "
110 "match the first dim of inp_features"));
113 inp_positions.shape().dim_size(0) ==
114 inp_importance.shape().dim_size(0) ||
115 inp_importance.shape().dim_size(0) == 0,
116 errors::InvalidArgument(
"first dim of inp_positions does "
117 "not match the first dim of "
121 neighbors_importance.shape().dim_size(0) ==
122 neighbors_index.shape().dim_size(0) ||
123 neighbors_importance.shape().dim_size(0) == 0,
124 errors::InvalidArgument(
"first dim of neighbors_importance "
125 "does not match the first dim of "
130 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
131 errors::InvalidArgument(
"number of input channels in filter "
132 "and inp_features does not match"));
134 TensorShape out_features_shape({out_positions.shape().dim_size(0),
135 filter.shape().dim_size(4)});
136 Tensor* out_features =
nullptr;
137 OP_REQUIRES_OK(
context,
context->allocate_output(0, out_features_shape,
140 std::vector<int> filter_dims({
141 int(filter.shape().dim_size(0)),
142 int(filter.shape().dim_size(1)),
143 int(filter.shape().dim_size(2)),
144 int(filter.shape().dim_size(3)),
145 int(filter.shape().dim_size(4)),
148 bool individual_extents = extents.shape().dim_size(0) ==
149 out_positions.shape().dim_size(0) &&
150 extents.shape().dim_size(0) > 1;
152 bool isotropic_extents = extents.shape().dim_size(1) == 1;
154 bool point_importances = inp_importance.shape().dim_size(0) != 0;
156 bool has_neighbors_importances =
157 neighbors_importance.shape().dim_size(0) != 0;
160 inp_features, inp_importance, neighbors_index,
161 neighbors_importance, neighbors_row_splits, filter_dims,
162 individual_extents, isotropic_extents, point_importances,
163 has_neighbors_importances, *out_features);