-
Notifications
You must be signed in to change notification settings - Fork 91
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
#1 Allow more heterogenous types in numeric operations #36
Conversation
I think we'll need to figure out how to make things like |
Yes I understand but that would be less nice. I’d like to avoid this kind of code duplication. implicit class NumericOpsCls[A : Numeric : Manifest](lhs: A) {
def + [B, C](rhs: Rep[B])(implicit op: (A ~ B := C), mC: Manifest[C], sc: SourceContext) = numeric_plus(op.lhs(unit(lhs)), op.rhs(rhs))(op.Numeric, mC, sc)
} Note that the implicit conversion operates on a |
I agree the explicit version would be less nice. I'm not 100% sure where this one goes wrong (you can try running scalac with Since the |
It didn’t work either. I could only get it working by making the implicit class NumericOpsCls[A : Numeric : Manifest](lhs: A) {
def + (rhs: Rep[A])(implicit op: (A ~ A := A), sc: SourceContext) = numeric_plus(op.lhs(unit(lhs)), op.rhs(rhs))(op.Numeric, manifest[A], sc)
} But I still doesn’t understand why the polymorphic way works well when the left hand side is a |
Hi, thanks @kjbrown for cleaning things up, but why has this issue been closed? I think we really need to find a solution. |
I agree... it must have closed automatically when I deleted delite-develop-M7. There is another instance of this issue still open though. |
@julienrf Could the problem you were facing be an instance of scala/scala#2822? |
Reminds me more of https://issues.scala-lang.org/browse/SI-5107 and another issue I can't find in JIRA. There are multiple things which come together here which prevent this code from working. |
Hi,
Here is another attempt to resolve this issue. I’m using a pattern like
CanBuildFrom
to express what the return type of a numeric operation should be. That allows to express type promotion (e.g.Int
toFloat
) in a clean way.Unfortunately I’m unable to make things like
1 + unit(1)
working… TheanyToNumericOps
implicit conversion does not seem to be applied automatically.