jamesorr / CO2SYS-MATLAB

CO2SYS software for MATLAB (or octave) to compute variables of ocean CO2 system
MIT License
29 stars 11 forks source link

Separate the Julia version? #2

Closed briochemc closed 2 years ago

briochemc commented 2 years ago

I could not submit an issue on @mvdh7's CO2System.jl repository likely because it is a fork of this repository. Would it make sense to split the Julia version completely and cut the umbilical cord tying it to this MATLAB version?

FWIW, for the Julia version, 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.)

Don't hesitate to close if these are stupid ideas! 😅

mvdh7 commented 2 years ago

Good suggestions @briochemc, thanks! Have separated the repo now here: https://github.com/mvdh7/CO2System.jl The modification to the main function sounds like a good idea, but Julia is not my focus right now, and it will be quite some time before I can look at this - would be happy to incorporate it if someone else has time! Perhaps you could add it as an issue to the new repo.