5 ms·
Article claims that "modern Fortran already has [...] generics" but AFAIK it's still not possible to write e.g. a type-generic sort function (unless you restric
by photon-torpedo 8y ago
Article claims that "modern Fortran already has [...] generics" but AFAIK it's still not possible to write e.g. a type-generic sort function (unless you restrict yourself to types all inheriting from a common class, a bit like very early Java). So there's no standard library of basic algorithms and data structures, and you can't even write one, without resorting to meta-programming (likely in a language other than Fortran). From what I have seen about Fortran2018, this will not improve any time soon.
- jabl 8y agoYou can use "class(*)" and the "select type" construct, and yes, polymorphism. So to compare to C++ or Java, it a bit like inheritance and RTTI. Not generating type-specialized functions at compile-time like with C++ templates, which is what's needed for high performance.
- thecleaner 8y agoIs there a use case of using polymorphism in scientific computing ? Just curious.
- jabl 8y agoScientific computing doesn't (only) mean small tight loops doing linear algebra. Scientific applications can be millions of LOC, with all the attendant problems of managing complexity at scale. Polymorphism can well be a useful tool to have in the toolbox. Just because it's not an appropriate tool when writing high-performance kernel code, doesn't mean it's not useful elsewhere.
- claudius 8y agoI quite like having functions which take generic "scalars" (double/float/std::complex<double>/boost multiprecision etc) without me having to worry about the specific type everywhere. Of course, sufficiently far down eventually one has to care about the scalar type, but on a high level, it’s nice to ignore it. The same goes when building abstractions based on this. Tensor<T> instead of Tensor_double, Tensor_float etc. And then you have all the typical usecases of polymorphism in the wrappers and callers and executables and whatnot which are also to some degree part of "scientific computing".
- milancurcic 8y agoOne example I often give is the nabla operator from vector calculus that is in one form or another used in any fluid dynamics code. If you define nabla as a function that operates on a Field type, and Scalar and Vector types extend the Field type, then nabla can be coded to return a gradient (Vector) if passed a Scalar, and divergence (Scalar) if passed a Vector. Polymorphism is an elegant way to implement this.