Skip to content

Commit

Permalink
Merge pull request #335 from evaleev/evaleev/fix/unify-am2symbol
Browse files Browse the repository at this point in the history
l->symbol maps condensed to 1 definition for non-Python code
  • Loading branch information
evaleev authored Mar 5, 2024
2 parents fd1c6a9 + 054bfb6 commit b5e8c88
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 37 deletions.
3 changes: 3 additions & 0 deletions include/libint2/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@
#define LIBINT_MAYBE_UNUSED
#endif

/* maps angular momentum to the corresponding symbol: 0 -> s, 1 -> p, etc. */
#define LIBINT_AM2SYMBOL "spdfghiklmnoqrtuvwxyz"

#endif /* header guard */
33 changes: 18 additions & 15 deletions include/libint2/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif

#include <libint2.h>
#include <libint2/config.h>
#include <libint2/util/small_vector.h>

#include <array>
Expand Down Expand Up @@ -809,10 +810,10 @@ struct Shell {
/// @param l angular momentum quantum number
/// @return (lower-case) letter symbol corresponding to @p l ; e.g., `s` for
/// `l=0`, `p` for `l=1`, etc.
/// @throw std::invalid_argument if \c l is greater than 19
/// @throw std::invalid_argument if \c l is greater than 20
static char am_symbol(size_t l) {
static char lsymb[] = "spdfghiklmnoqrtuvwxyz";
assert(l <= 19);
assert(l <= sizeof(LIBINT_AM2SYMBOL) - 1);
static char lsymb[] = LIBINT_AM2SYMBOL;
return lsymb[l];
}

Expand Down Expand Up @@ -842,30 +843,32 @@ struct Shell {
return 6;
case 'K':
return 7;
case 'M':
case 'L':
return 8;
case 'N':
case 'M':
return 9;
case 'O':
case 'N':
return 10;
case 'Q':
case 'O':
return 11;
case 'R':
case 'Q':
return 12;
case 'T':
case 'R':
return 13;
case 'U':
case 'T':
return 14;
case 'V':
case 'U':
return 15;
case 'W':
case 'V':
return 16;
case 'X':
case 'W':
return 17;
case 'Y':
case 'X':
return 18;
case 'Z':
case 'Y':
return 19;
case 'Z':
return 20;
default:
throw std::invalid_argument{"invalid angular momentum label"};
}
Expand Down
4 changes: 0 additions & 4 deletions src/bin/libint/default_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ TaskParameters::TaskParameters()

//////////

const char
libint2::StaticDefinitions::am_letters[StaticDefinitions::num_am_letters +
1] = "spdfghiklm";

std::string libint2::label_to_funcname(const std::string& label) {
// Do not prepend compute as it messes up the API prefix functionality.
#if 0
Expand Down
10 changes: 0 additions & 10 deletions src/bin/libint/default_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,6 @@ class TaskParameters {
}
};

/// Static parameters
struct StaticDefinitions {
/// basis functions with angular momenta 0 .. 9 are represented by these
/// letters higher angular momenta are expressed by replacing digits in their
/// base-10 representation with the corresponding letters
static const unsigned int num_am_letters = 10;
/// am -> char conversion
static const char am_letters[num_am_letters + 1];
};

/// Converts a label, e.g. name of the target node, to the name of the function
/// to compute it
std::string label_to_funcname(const std::string& label);
Expand Down
7 changes: 4 additions & 3 deletions src/bin/libint/gauss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ std::array<LIBINT2_UINT_LEAST64, OriginDerivative<3u>::max_deriv + 1>
namespace {
std::string am_to_symbol(unsigned int l, bool contracted) {
std::string result;
const size_t lmax_plus_1 = sizeof(LIBINT_AM2SYMBOL) - 1;
do {
const unsigned int digit = l % 10u;
char letter = StaticDefinitions::am_letters[digit];
const unsigned int digit = l % lmax_plus_1;
char letter = LIBINT_AM2SYMBOL[digit];
if (contracted) letter = toupper(letter);
result.insert(result.begin(), letter);
l /= 10;
l /= lmax_plus_1;
} while (l != 0);

return result;
Expand Down
12 changes: 12 additions & 0 deletions src/bin/libint/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ void RunTest(Callback test, const std::string& descr, std::ostream& os) {
}

void test0() {
// test CGShell labels
if (CGShell(0).label() != "s")
throw ProgrammingError("CGShell::label() failed for l=0");
if (CGShell(20).label() != "z")
throw ProgrammingError("CGShell::label() failed for l=20");
if (CGShell(21).label() != "ps")
throw ProgrammingError("CGShell::label() failed for l=21");
if (CGShell(22).label() != "pp")
throw ProgrammingError("CGShell::label() failed for l=22");
if (CGShell(42).label() != "ds")
throw ProgrammingError("CGShell::label() failed for l=42");

std::shared_ptr<TwoPRep_11_11_sq> pppp_quartet =
TwoPRep_11_11_sq::Instance(sh_p, sh_p, sh_p, sh_p, 0u);
std::shared_ptr<DGVertex> pppp_ptr =
Expand Down
3 changes: 2 additions & 1 deletion src/bin/test_eri/time_eri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ std::string usage() {
}

std::string am2label(unsigned int l) {
static char labels[] = "spdfghiklmnoqrtuvwxyz";
assert(l <= sizeof(LIBINT_AM2SYMBOL) - 1);
static char labels[] = LIBINT_AM2SYMBOL;
std::ostringstream oss;
oss << labels[l];
return oss.str();
Expand Down
8 changes: 4 additions & 4 deletions tests/eri/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ libint2::FmEval_Taylor<double, 6> fmeval_taylor(std::max(LIBINT_MAX_AM, 4) * 4 +
1e-15);

namespace {
const char am_letters[] = "spdfghiklm";

std::string am_to_symbol(unsigned int l, bool contracted = false) {
std::string result;
const size_t lmax_plus_1 = sizeof(LIBINT_AM2SYMBOL) - 1;
do {
const unsigned int digit = l % 10u;
char letter = am_letters[digit];
const unsigned int digit = l % lmax_plus_1;
char letter = LIBINT_AM2SYMBOL[digit];
if (contracted) letter = toupper(letter);
result.insert(result.begin(), letter);
l /= 10;
l /= lmax_plus_1;
} while (l != 0);

return result;
Expand Down

0 comments on commit b5e8c88

Please sign in to comment.