-
Notifications
You must be signed in to change notification settings - Fork 187
Standard Algorithms: iota #638
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
Comments
I am happy to work on this, scan, and reduce if this idea is found acceptable by project maintainers. |
I find the name Note that we already have the function |
You can do the the following in fortran with array constructors, how different a function like program main
implicit none
integer, parameter :: N = 5
integer :: i
integer, allocatable :: a(:)
a = [(i,i=1,N,2)] ! i = start, end, steps
print*, a
end program |
As a side note, the implicit saved variable use std_algorithm, only : iota
implicit none
integer :: a(5), b(5), c(5)
call iota(a)
call iota(b, 1)
call iota(c)
print *, all(c == a) ! F
print *, all(c == b) ! T
end |
@awvwgk Ah, I handn't found @14NGiestas My example iota can work on array slices which may be more helpful than the array constructors. Are there existing versions of scan or reduce? If not, are these worth creating another issue for? I appreciate both of your responses either way. |
No, I don't think we have those yet. Feel free to open an issue and we can discuss the API. |
I also find the name In general I'm very supportive of "mining" the C++ standard template library for algorithms. Granted, the lack of generics makes this feasible only for the intrinsic types. Although with some preprocessing, you could perhaps extend this also to derived types. Arjen Markus posted an interesting template for reversing an array at Discourse. It gives a hint of what a generic Fortran template library might look like. If a compiler vendor would ever want to re-use their C++ STL implementation, they could do so easily by making an STL-compatible wrapper of the Fortran array descriptor (I've made a few steps in this direction in #325). |
Great. I'll open another issue for reduce and we can continue the conversation there. |
Motivation
General algorithms have become ubiquitous in GPU and parallel programming, leading many developers to write code in terms of a set of standard algorithms that are broadly present in programming languages today. For example, the C++ standard library provides the function
std::iota
to make a sequence out of an array, which might be called from Fortran like so:A draft of this algorithm may be found below.
Providing a set of standard algorithms should lower Fortran's barrier to entry for programmers already familiar with these concepts. In my opinion, the highest-priority algorithms after
iota
are scan and reduce.iota
was chosen because of its simplicity and ubiquity.Prior Art
std::iota
make_sequence
range
functionAdditional Information
No response
The text was updated successfully, but these errors were encountered: