Findmax on ranges


#1

This had me surprised:

julia> @btime findmax($(2:10^9))
  1.191 s (0 allocations: 0 bytes)
(1000000000, 999999999)

julia> @btime maximum($(2:10^9))
  4.441 ns (0 allocations: 0 bytes)
1000000000

Apparently, findmax / argmax actually iterate over each element of the range. This is the case on both 0.6 and 0.7, so I’m wondering if it’s deliberate.


#2

Definitely not deliberate, just a case of a missing optimization method. A pull request to fix this should be relatively simple and would be greatly appreciated!


#3

I have taken a look at CONTRIBUTING.md. Unfotunately, forking and building is too high a hurdle now (implementing the code itself is not a problem.)

But I seem to remember that someone said you can create pull requests directly via the web interface with no fork/build process before that, and that this was far easier. I cannot find anything about that in CONTRIBUTING.


#4

Yes, you can definitely test it locally and then copy it into the GitHub editor. We should add directions about that to CONTRIBUTING. It definitely works best for documentation improvements; for code changes it can be more cumbersome as those almost always require editing two or more files (one for the functionality, one for the tests), but it’s still doable if you’re tenacious:

  • Navigate to the code you want to modify or find similar code to what you want to add on GitHub. Using a Julia notebook here can be convenient since @which will give you links directly to GitHub. In this case, somewhere around maximum seems like a good home.

  • Click the little :pencil2: icon on the top of the page to bring up the GitHub editor. Scroll back down to where you were.

  • Add your new functionality or make your edits.

  • Scroll down to the bottom and commit your changes to a new branch. Give it a good title and description. Hit commit! Now you’ve created a branch that contains your changes.

  • Here’s where it gets tricky: GitHub thinks you’re done, so it goes directly to a “Create New PR” page. But we still need to add tests to a different file. GitHub does not make this easy. I think the best way is to just create the PR with the new feature, and then add a note that you’re still in the process of adding tests.

  • Now go your your Julia fork (e.g., github.com/DNF/julia, or whatever your GitHub username is), and on the branch dropdown menu find your new branch that you just created. By switching to this branch now you can add additional commits directly to it.

  • Navigate to the test file you want to modify within that branch on your fork (test/ranges.jl), find a reasonable place to put your tests, copy them in, and then commit them. This time, instead of creating another branch, you want to commit them directly to the branch you’re currently on. By doing so, they’ll show up in the PR over at JuliaLang/julia.

So, yeah, it’s a bit of a pain when there’s more than one file involved.