how to cast Numeric to Index #2722
-
#[cube(launch)]
pub fn grid_sample_kernel<F: Float, I: Int>(
input: &Tensor<F>,
grid: &Tensor<F>,
output: &mut Tensor<F>,
out_grid: &mut Tensor<F>,
) {
let batch = output.shape(0);
let channel = input.shape(1);
let row = output.shape(2);
let col = output.shape(3);
if ABSOLUTE_POS_X >= row || ABSOLUTE_POS_Y >= col {
return;
}
let out_index = ABSOLUTE_POS_X + ABSOLUTE_POS_Y * col + ABSOLUTE_POS_Z * row * col;
let n = ABSOLUTE_POS_Z / channel;
let h = ABSOLUTE_POS_Y;
let w = ABSOLUTE_POS_X;
let x: F = grid[2 * row * col * n + 2 * row * h + 2 * w];
let y: F = grid[2 * row * col * n + 2 * row * h + 2 * w + 1];
let x = (x + F::new(1.0)) * (F::cast_from(w) + F::new(1.0)) / F::new(2.0);
let y = (y + F::new(1.0)) * (F::cast_from(h) + F::new(1.0)) / F::new(2.0);
out_grid[ABSOLUTE_POS_Z] = F::cast_from(n);
// cast F to Index
// out_grid[index]
} |
Beta Was this translation helpful? Give feedback.
Answered by
nathanielsimard
Jan 21, 2025
Replies: 1 comment
-
Casting to u32 should do the job: let index = u32::cast_from(numeric); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dfsfdfse
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Casting to u32 should do the job: