Skip to content
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

linalg: export numeric constants #910

Open
perazz opened this issue Dec 24, 2024 · 0 comments
Open

linalg: export numeric constants #910

perazz opened this issue Dec 24, 2024 · 0 comments
Labels
idea Proposition of an idea and opening an issue to discuss it

Comments

@perazz
Copy link
Contributor

perazz commented Dec 24, 2024

Motivation

As pointed out in #902, it is often tedious to read through templated numeric constants through the code.

Prior Art

#800

Additional Information

  • For the user API, maybe all needed is a consistent way to export them? One way this is present in stdlib (codata module) is to use a mold parameter and function.
  • For development (linear algebra routines will be easier to read), maybe the best approach would be to template them directly in fypp? this works well:
#! Return the unitary numeric constant for a given type and kind
#!
#! Args:
#!   type (string): an intrinsic type (complex, real, integer)
#!
#! Returns:
#!   Parameter value string
#!
#! E.g.,
#!   one('complex(dp)')  -> (1.0_dp, 0.0_dp)
#!   one('real(sp)') -> 1.0_sp
#!   one('integer') -> 1
#!
#:def one(type)
  #:assert 'integer' in type or 'real' in type or 'complex' in type
  #:if '(' in type and ')' in type
    #:set kind="_" + type.split('(')[1].split(')')[0]
  #:else
    #:set kind=""
  #:endif
  #:if 'integer' in type
    ${"1"+kind}$
  #:elif 'real' in type
    ${"1.0"+kind}$
  #:elif 'complex' in type
    ${"(1.0"+kind+",0.0"+kind+')'}$
  #:endif
#:enddef
@perazz perazz added the idea Proposition of an idea and opening an issue to discuss it label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it
Projects
None yet
Development

No branches or pull requests

1 participant