Skip to content

Return value polymorphic function #11

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

Closed
zoziha opened this issue Jun 8, 2021 · 0 comments
Closed

Return value polymorphic function #11

zoziha opened this issue Jun 8, 2021 · 0 comments

Comments

@zoziha
Copy link
Member

zoziha commented Jun 8, 2021

For example, x = zeros(dim1, dim2, ...) function.

flag

We add a flag to the function, this flag is consistent with the precision of the return value.

x = zeros(dim1, dim2, ..., flag)

ref from: https://fortran-lang.discourse.group/t/fortran-function-return-value-polymorphism/1350/5

But we found that this method is actually not good for the user experience. We want to find other ways.

function name

We can abandon the idea of a polymorphic function interface and set up the following functions:

szeros / dzeros / qzeros
default: zeros = szeros

real(integer, kind)

Maybe we can imitate the standard function of Fortran, the real function.
ref from:

  1. {"real", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}
  2. https://github.com/llvm/llvm-project/blob/d8805574c183484f055552855fa82d2e8932415e/flang/runtime/numeric.h#L22
  3. https://github.com/llvm/llvm-project/blob/d8805574c183484f055552855fa82d2e8932415e/flang/runtime/numeric.cpp
  4. https://github.com/llvm/llvm-project/blob/d480f968ad8b56d3ee4a6b6df5532d485b0ad01e/flang/runtime/type-code.cpp
real(integer, kind)

Final question

Should we implement the second method first. It will be more difficult to implement the third method? May need to use c/c++, so we need to ensure that fpm can build such code.
fortran-lang/fpm#353
https://github.com/fortran-lang/fpm/tree/master/example_packages/with_c

Or do we have a better way?

@zoziha zoziha closed this as completed Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant