Following jamesorr/CO2SYS-MATLAB#2, here is copy-pasted suggestion:
I wanted to suggest converting the main function, which takes scalars or arrays as input, into a function that takes only scalars as inputs. I think a scalar function, called e.g., co2sys(args...)
, would have many advantages over the current version (in Julia). Note that a scalar function would be easy to broadcast to arrays with Julia's dot syntax, e.g., for a simple example:
julia> f(x,y) = x + y # define the function on scalars
f (generic function with 1 method)
julia> f.([1, 2, 3], 4) # easily broadcast to those inputs that are arrays
3-element Vector{Int64}:
5
6
7
Another potential gain is that the code would be simpler (e.g., less lines of code because no need for all the array treatment, the allocations, and so on). Furthermore, it might be computationally more efficient because, e.g., no need to reallocate the boolean indices array F
dozens of times. (Although efficiency would need to be benchmarked against the current vectorized version I guess.)