MCPcopy Create free account
hub / github.com/apache/tvm / _bicubic_sample

Function _bicubic_sample

python/tvm/topi/testing/grid_sample_python.py:139–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

137 )
138
139 def _bicubic_sample():
140 A = -0.75
141
142 def cubic_weight_1(x_fraction):
143 return ((A + 2) * x_fraction - (A + 3)) * x_fraction * x_fraction + 1
144
145 def cubic_weight_2(x_fraction):
146 return ((A * x_fraction - 5 * A) * x_fraction + 8 * A) * x_fraction - 4 * A
147
148 def cubic_interp_1d(pixel_0, pixel_1, pixel_2, pixel_3, x_fraction):
149 weights = [0] * 4
150 weights[0] = cubic_weight_2(x_fraction + 1)
151 weights[1] = cubic_weight_1(x_fraction)
152 weights[2] = cubic_weight_1(1 - x_fraction)
153 weights[3] = cubic_weight_2(2 - x_fraction)
154
155 return (
156 pixel_0 * weights[0]
157 + pixel_1 * weights[1]
158 + pixel_2 * weights[2]
159 + pixel_3 * weights[3]
160 )
161
162 def coefficients_along_x(x_floor, y_floor, x_fraction):
163 coefficients = [0] * 4
164
165 for i in range(4):
166 y_ = y_floor - 1 + i
167 x_0 = x_floor - 1
168 x_1 = x_floor + 0
169 x_2 = x_floor + 1
170 x_3 = x_floor + 2
171
172 if padding_mode == "border":
173 y_ = _clip_coordinates(y_, in_height)
174 x_0 = _clip_coordinates(x_0, in_width)
175 x_1 = _clip_coordinates(x_1, in_width)
176 x_2 = _clip_coordinates(x_2, in_width)
177 x_3 = _clip_coordinates(x_3, in_width)
178
179 elif padding_mode == "reflection":
180 y_ = _reflect_coordinates(y_, in_height)
181 x_0 = _reflect_coordinates(x_0, in_width)
182 x_1 = _reflect_coordinates(x_1, in_width)
183 x_2 = _reflect_coordinates(x_2, in_width)
184 x_3 = _reflect_coordinates(x_3, in_width)
185
186 y_ = int(_clip_coordinates(y_, in_height))
187 x_0 = int(_clip_coordinates(x_0, in_width))
188 x_1 = int(_clip_coordinates(x_1, in_width))
189 x_2 = int(_clip_coordinates(x_2, in_width))
190 x_3 = int(_clip_coordinates(x_3, in_width))
191
192 coefficients[i] = cubic_interp_1d(
193 _get_pixel(_b, _c, y_, x_0),
194 _get_pixel(_b, _c, y_, x_1),
195 _get_pixel(_b, _c, y_, x_2),
196 _get_pixel(_b, _c, y_, x_3),

Callers 1

grid_sample_2dFunction · 0.70

Calls 3

coefficients_along_xFunction · 0.85
_unnormalizeFunction · 0.70
cubic_interp_1dFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…