I found this blog post interesting, even though I do not fully agree with the authors’ conclusion. I don’t think it is the agility of Python as a programming language itself, but the developed infrastructure of libraries, online documentation and learning resources, which enabled Bob to quickly find the Python kdtree in the first place. There is in fact a kdtree library available for Fortran. According to some resources it even delivers performance similar to mature C and C++ libraries. However, it lacks the nice webpage, proper unit testing, documentation, and user examples, which are needed so it could stand out.
Flipping the coin of the debate, we could also say it is the lack of Fortran developer resources (and developers themselves), particularly for “classic” computer science algorithms like searching, sorting, heaps, stacks and queues, tree construction, etc., which obstructs adoption of Fortran in some domains of computational science.
The previous weekend I followed a Python quadtree tutorial and was quickly able to adapt it to Fortran (code is available here). Usage of the tree is not any more complicated than in Python:
integer, parameter :: n = 140
real(wp) :: points(n,2)
type(qtree) :: tree
integer, allocatable :: idxs(:)
! Square quadtree box with center at (0.5,0.5) and width 1
call tree%init(0.5_wp,0.5_wp,1.0_wp,1.0_wp)
! Populate with random points
call random_number(points)
call tree%populate(points)
! Query indexes in rectangle centered at (0.75,0.75) and width 0.6
idxs = tree%query(boundaries(0.75_wp,0.75_wp,0.6_wp,0.6_wp))
! Query indexes in circle with radius 0.3 centered at (0.75,0.75)
idxs = tree%query_radius([0.75_wp,0.75_wp],0.3_wp)
Sample output:
A few months ago I also followed a gist by Jake Vanderplas and created a Fortran Balltree. Some errors remains in the query function ), but at the time the build process worked nicely:
I was planning to polish these some more and make them available in the future as an fpm
package. It would be nice to find some collaborators!