use cubecl::prelude::*;
use crate::Axis;
use super::{Reads, Recipe, RecipeCoords, RecipeExpand};
#[derive(CubeType, Clone)]
pub struct AffineCoordinate<T: Numeric> {
pub offset: T,
pub coefficient: T,
#[cube(comptime)]
pub axis: Axis,
}
#[cube]
pub fn affine_along<T: Numeric>(
#[comptime] axis: Axis,
offset: T,
coefficient: T,
) -> AffineCoordinate<T> {
AffineCoordinate::<T> {
offset,
coefficient,
axis,
}
}
#[cube]
impl<T: Numeric> Recipe<T> for AffineCoordinate<T> {
fn evaluate(&self, coordinates: &RecipeCoords) -> T {
self.offset + self.coefficient * T::cast_from(coordinates.along(self.axis))
}
}
impl<T: Numeric> Reads for AffineCoordinateExpand<T> {
fn reads(&self, _scope: &Scope, axis: Axis) -> bool {
self.axis == axis
}
}