Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operating overloading on custom type is broken #19

Open
shiinamiyuki opened this issue Sep 23, 2023 · 0 comments
Open

Operating overloading on custom type is broken #19

shiinamiyuki opened this issue Sep 23, 2023 · 0 comments

Comments

@shiinamiyuki
Copy link
Collaborator

The best working attemp is

#[derive(Clone, Copy, Debug, Value, PartialEq)]
#[repr(C)]
#[value_new(pub)]
pub struct CustomAdd {
    i: f32,
}
impl AddExpr<CustomAddExpr> for CustomAddExpr {
    type Output = Expr<CustomAdd>;
    #[tracked]
    fn add(self, rhs: CustomAddExpr) -> Expr<CustomAdd> {
        let rhs = rhs.as_expr_from_proxy();
        let self_ = self.self_.var();
        *self_.i += rhs.i;
        **self_
    }
}
impl AddMaybeExpr<CustomAddExpr, luisa_compute::lang::types::ExprType> for Expr<CustomAdd> {
    type Output = Expr<CustomAdd>;
    fn __add(self, rhs: CustomAddExpr) -> Self::Output {
        self.add(rhs)
    }
}
fn custom_add(a: Expr<CustomAdd>, b: Expr<CustomAdd>) -> Expr<CustomAdd> {
    track!(a + *b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant