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
Fmean, mean overload functions implemented #877
Conversation
Currently this test is not enabled in
Can you isolate all bugs from this that LPython still does not support and report them? Let's get them fixed. I would recommend to only implement things that actually fully compile with LPython. Otherwise we'll end up with a huge library that does not work. |
src/runtime/statistics.py
Outdated
for i in range(k): | ||
for j in range(i+1,k): | ||
if x[i]>x[j]: | ||
x[i],x[j]=x[j],x[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is repeated many times. How about creating a new function, say _sort
and reuse it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the following function
def _sort(x: list[i32]):
k: i32 = len(x)
i: i32
j: i32
for i in range(k):
for j in range(i+1,k):
if x[i]>x[j]:
x[i],x[j]=x[j],x[i]
and passed the list by reference in the following manner:
_sort({x})
However, when I try to overload the sort function for f64, it throws an error. Any suggestions for alternative workarounds? @Smit-create
Lists are supported now in LLVM. So please enable LLVM for your test. |
I'm getting the following error when enabling LLVM for this:
I tried to understand why the symbol table it throwing an error but couldn't figure it out. Suggestions please? @czgdp1807 |
The error is not related lists. It is due to incorrect symbol being used in the |
Yeah, will look into it. |
909f616
to
065e271
Compare
I have removed the median functions because the diff was getting larger and had some issues to fix. Rest all is working fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's excellent that such list usage already works.
Thanks!
065e271
to
a3af2ab
Compare
Great. Thanks @Smit-create for working on this and completing this. |
@Smit-create could you please explain what you mean by this? That way I'll be careful of the issue in question as I implement further functions |
How could I improve on the median function? I also have another PR open with Variance and stdev functions. |
|
||
for i in range(k): | ||
sum += x[i] | ||
return sum/k |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, these are great candidates to try using the new templates. The templates are still experimental, and we still need to implement restrictions, so things will change, but the current state should be able to compile such functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. @ansharlubis @Oshanath May be, you can try templates on these functions and reduce the implementation size? What do you folks say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be a little bit early, since it will slow @ansharlubis down if we have to do any refactoring, which we will. We can however do it on a branch / Draft PR that is not merged. That would be great, just to see if it works, and to iron out any bugs, but I would not merge into master yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It kind of work in an example I added in PR #921, it still uses the hard-coded restrictions though and don't do much type checks.
No description provided.