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

Routines used to convert LAPACK-style char to enum #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hfp
Copy link

@hfp hfp commented Jan 7, 2025

  • Routines were deprecated (to be removed 2025-05).
  • Introduced overloaded from_string (takes char).

include/blas/util.hh Outdated Show resolved Hide resolved
- Routines were deprecated (to be removed 2025-05).
- Introduced overloaded from_string (takes char).
@hfp hfp changed the title Removed routines used to convert LAPACK-style char to enum Routines used to convert LAPACK-style char to enum Jan 7, 2025
@mgates3
Copy link
Collaborator

mgates3 commented Jan 7, 2025

Is this just for efficiency sake, by avoiding converting const char* to std::string? Because the existing code already works for const char*. See test_util.cc:

    from_string( "c", &op );  require( op == blas::Op::ConjTrans );
    from_string( "notrans",   &op );  require( op == blas::Op::NoTrans   );

It seems this just duplicates existing logic, more-or-less.

@hfp
Copy link
Author

hfp commented Jan 8, 2025

Yes, it duplicates logic and it was mainly for efficiency (like a side task along other things I am experimenting with). Removing the deprecated functions can make up for the duplication. It seems ugly taking a single character, allocating memory, transforming string's case, and comparing against a string literal once more. Also, the call-side is cluttered by producing that std::string. For robustness, I am thought unnecessary memory allocation shall be avoided. Though, the full-blown string-interface supports things like passing "Upper" somewhere instead if 'U`. Feel free to reject the PR; no worries.

@mgates3
Copy link
Collaborator

mgates3 commented Jan 11, 2025

There's likely no malloc happening, due to small string optimization. See https://cppdepend.com/blog/understanding-small-string-optimization-sso-in-stdstring/.

I agree that dealing with individual chars clutters the call side a bit, e.g., in slate/scalapack_api/*.cc:

    from_string( std::string( 1, uplo_str[0] ), &uplo );

This could be written passing the string directly:

    from_string( uplo_str, &uplo );

but that's dangerous since the uplo_str string is coming from a Fortran API, there's no guarantee that it is null-terminated. It could be nice if passing a char worked, e.g., one of these:

    from_string( uplo_str[0], &uplo );
    // or
    from_char( uplo_str[0], &uplo );

There are currently another 19 from_string functions in LAPACK++ and 12 from_string functions in SLATE, so it ends up being a lot of duplication. The from_string functions were made to reduce previous duplication and have better error handling for more robustness. E.g., char2uplo( 'x' ) previously would work but give an invalid enum value; now from_string( "x", &uplo ) will throw an error.

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

Successfully merging this pull request may close these issues.

2 participants