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

Add built-in sum() #1547

Merged
merged 4 commits into from
Feb 24, 2023
Merged

Add built-in sum() #1547

merged 4 commits into from
Feb 24, 2023

Conversation

faze-geek
Copy link
Contributor

@faze-geek faze-geek commented Feb 23, 2023

sum() is a useful inbuilt function in python. Compared to fsum() from math class it is more commonly used for smaller inputs. It Is also faster as it can be used directly used and does not convert the summation value into float on each iteration unlike floating-point sum.

import math
def main0():
    print(sum([1,2,3,4,5]))
    print(math.fsum([1,2,3,4,5]))

main0()

(lp) faze-geek@DESKTOP-497JDCU:~/lpython/lpython$ python try.py
15
15.0
(lp) faze-geek@DESKTOP-497JDCU:~/lpython/lpython$ ./src/bin/lpython try.py
15
1.50000000000000000e+01

For now only the list iterable is compatible with this function

@faze-geek
Copy link
Contributor Author

@Thirumalai-Shaktivel Made this pr from my wsl since windows set up was still giving some trouble in updating references. Could you have a look at it? I wonder why the tests are not running ?

@Shaikh-Ubaid
Copy link
Collaborator

Shaikh-Ubaid commented Feb 23, 2023

I wonder why the tests are not running ?

I had experienced this previously. Probably some issue at GitHub's end. I think just pushing again (after resolving conflicts and rebasing on latest main) would run the CI tests.

@faze-geek
Copy link
Contributor Author

faze-geek commented Feb 23, 2023

I think just pushing again (maybe after rebasing) would run the CI tests.

Sure,
git rebase main gives Current branch sum is up to date. Should I make a minor tweak and push again ?

Or if you are aware of how to fetch a branch, I would like to restore it in my windows and then push from there. Thanks!

@Shaikh-Ubaid
Copy link
Collaborator

Shaikh-Ubaid commented Feb 23, 2023

Should I make a minor tweak and push again ?

Yes, try it.

Or if you are aware of how to fetch a branch, I would like to restore it in my windows and then push from there. Thanks!

I (usually) follow these steps to pull branches.

  1. add the particular remote: git remote add faze-geek git@github.com:faze-geek/lpython.git
  2. fetch remote info: git fetch faze-geek
  3. checkout the desired branch: git checkout sum (Unsure what happens if you already have a branch with that same name)
  4. now you can work on it just like a normal branch.

@faze-geek
Copy link
Contributor Author

I pushed a minor tweak ,still no luck. I'll try closing and reopening to make the tests again.

@faze-geek faze-geek closed this Feb 23, 2023
@faze-geek faze-geek reopened this Feb 23, 2023
@Shaikh-Ubaid
Copy link
Collaborator

Please also resolve the conflicts and then let's see if the CI runs.

@Shaikh-Ubaid
Copy link
Collaborator

Shaikh-Ubaid commented Feb 23, 2023

The CI tests now run.

@faze-geek I think your local main branch is not updated. The commits just before your commits were around 20 days old. As you shared git rebase main gives Current branch sum is up to date, maybe, you should first update your local main branch by:

git checkout main
git pull --rebase

// now checkout your branch and rebase over main
git checkout sum
git rebase main

I just did the above and the tests ran. (I also had removed any changes in the test folder).

@Thirumalai-Shaktivel
Copy link
Collaborator

Thirumalai-Shaktivel commented Feb 24, 2023

Yup. If there are conflicts with the main branch, the actions (CI) don't run by default.

Copy link
Collaborator

@czgdp1807 czgdp1807 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@certik certik merged commit cbdf2e5 into lcompilers:main Feb 24, 2023
@faze-geek
Copy link
Contributor Author

Thanks @Shaikh-Ubaid for the help and others for going through the pr.

The motivation for this pr was that I'm interested in the Implement Modules from Python standard library project for GSOC'23. I am having conversations with @Madhav2310 through mail for ideas. I intend on going through his work and refactoring/improving it wherever possible in the near future. Thanks again !

@faze-geek faze-geek deleted the sum branch February 25, 2023 03:17
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

Successfully merging this pull request may close these issues.

None yet

5 participants