Avoid C preprocessor macros (#3138)

This commit is contained in:
Eisuke Kawashima
2020-05-05 15:08:20 +09:00
committed by GitHub
parent a9d5170239
commit 535d8a2f35
11 changed files with 34 additions and 29 deletions

View File

@@ -871,14 +871,14 @@ template RDKIT_DATASTRUCTS_EXPORT void UpdateBitVectFromBinaryText(ExplicitBitVe
#include <intrin.h>
#ifdef _WIN64
#define BUILTIN_POPCOUNT_INSTR __popcnt64
#define BUILTIN_POPCOUNT_TYPE boost::uint64_t
using BUILTIN_POPCOUNT_TYPE = boost::uint64_t;
#else
#define BUILTIN_POPCOUNT_INSTR __popcnt
#define BUILTIN_POPCOUNT_TYPE std::uint32_t
using BUILTIN_POPCOUNT_TYPE = std::uint32_t;
#endif
#else
#define BUILTIN_POPCOUNT_INSTR __builtin_popcountll
#define BUILTIN_POPCOUNT_TYPE boost::uint64_t
using BUILTIN_POPCOUNT_TYPE = boost::uint64_t;
#endif
// the Bitmap Tanimoto and Dice similarity code is adapted

View File

@@ -7,7 +7,6 @@
#include <Geometry/Transform3D.h>
#include <GraphMol/MolTransforms/MolTransforms.h>
#include <GraphMol/FileParsers/FileParsers.h>
#define FEQ(_a_, _b_) (fabs((_a_) - (_b_)) < 1e-4)
namespace TemplateEnum {
using namespace RDKit;

View File

@@ -16,8 +16,9 @@
#include <fstream>
#include <cstdint>
#define OFFSET_TOL 1.e-8
#define SPACING_TOL 1.e-8
constexpr double OFFSET_TOL = 1.e-8;
constexpr double SPACING_TOL = 1.e-8;
using namespace RDKit;
namespace RDGeom {

View File

@@ -32,8 +32,7 @@ namespace RDKit {
namespace {
// This is a macro to allow its use for C++ constants
#define BCNAM(A, B, C) (((A) << 16) | ((B) << 8) | (C))
constexpr int BCNAM(char A, char B, char C) { return (A << 16) | (B << 8) | C; }
Atom *PDBAtomFromSymbol(const char *symb) {
PRECONDITION(symb, "bad char ptr");

View File

@@ -160,11 +160,11 @@ for (int j=0; j<count; j++) {
}
*/
#define HASHSIZE 1024
#define HASHMASK 1023
#define HASHX 571
#define HASHY 127
#define HASHZ 3
constexpr int HASHSIZE = 1024;
constexpr int HASHMASK = 1023;
constexpr int HASHX = 571;
constexpr int HASHY = 127;
constexpr int HASHZ = 3;
static void ConnectTheDots_Large(RWMol *mol, unsigned int flags) {
int HashTable[HASHSIZE];
@@ -263,8 +263,10 @@ void ConnectTheDots(RWMol *mol, unsigned int flags) {
}
// These are macros to allow their use in C++ constants
#define BCNAM(A, B, C) (((A) << 16) | ((B) << 8) | (C))
#define BCATM(A, B, C, D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
constexpr int BCNAM(char A, char B, char C) { return (A << 16) | (B << 8) | C; }
constexpr int BCATM(char A, char B, char C, char D) {
return (A << 24) | (B << 16) | (C << 8) | D;
}
static bool StandardPDBDoubleBond(unsigned int rescode, unsigned int atm1,
unsigned int atm2) {

View File

@@ -26,7 +26,7 @@
#include <future>
#endif
#define square(x) ((x) * (x))
double square(double x) { return x * x; }
namespace RDKit {
namespace MolAlign {
@@ -663,7 +663,7 @@ void LAP::computeCostMatrix(const ROMol &prbMol, const MolHistogram &prbHist,
if ((!rhyk) && (!phxk)) {
continue;
}
hSum += (double)square(rhyk - phxk) / (double)(rhyk + phxk);
hSum += square(rhyk - phxk) / (rhyk + phxk);
}
d_cost[y][x] = (*costFunc)(j, i, hSum, data);
}

View File

@@ -18,7 +18,7 @@
#include <boost/dynamic_bitset.hpp>
#include <RDGeneral/Exceptions.h>
#define EIGEN_TOLERANCE 5.0e-2
constexpr double EIGEN_TOLERANCE = 5.0e-2;
namespace MolTransforms {
using namespace RDKit;

View File

@@ -14,7 +14,7 @@
#include <Geometry/Transform3D.h>
#include <Numerics/Vector.h>
#define TOLERANCE 1.e-6
constexpr double TOLERANCE = 1.e-6;
namespace RDNumeric {

View File

@@ -43,9 +43,6 @@ inline void Contour(const double *d, size_t ilb, size_t iub, size_t jlb,
PRECONDITION(iub > ilb, "bad bounds");
PRECONDITION(jub > jlb, "bad bounds");
#define xsect(p1, p2) (h[p2] * xh[p1] - h[p1] * xh[p2]) / (h[p2] - h[p1])
#define ysect(p1, p2) (h[p2] * yh[p1] - h[p1] * yh[p2]) / (h[p2] - h[p1])
int m1, m2, m3, case_value;
double dmin, dmax, x1 = 0, x2 = 0, y1 = 0, y2 = 0;
int i, j, m;
@@ -60,6 +57,13 @@ inline void Contour(const double *d, size_t ilb, size_t iub, size_t jlb,
double temp1, temp2;
size_t ny = jub - jlb + 1;
auto xsect = [&](int p1, int p2) {
return (h[p2] * xh[p1] - h[p1] * xh[p2]) / (h[p2] - h[p1]);
};
auto ysect = [&](int p1, int p2) {
return (h[p2] * yh[p1] - h[p1] * yh[p2]) / (h[p2] - h[p1]);
};
for (j = (jub - 1); j >= (int)jlb; j--) {
for (i = ilb; i <= (int)iub - 1; i++) {
temp1 = std::min(d[i * ny + j], d[i * ny + j + 1]);

View File

@@ -15,16 +15,16 @@
#include <RDGeneral/Invariant.h>
#include <ctime>
#define MAX_ITERATIONS 1000
#define TOLERANCE 0.001
#define HUGE_EIGVAL 1.0e10
#define TINY_EIGVAL 1.0e-10
namespace RDNumeric {
namespace EigenSolvers {
bool powerEigenSolver(unsigned int numEig, DoubleSymmMatrix &mat,
DoubleVector &eigenValues, DoubleMatrix *eigenVectors,
int seed) {
const unsigned int MAX_ITERATIONS = 1000;
const double TOLERANCE = 0.001;
const double HUGE_EIGVAL = 1.0e10;
const double TINY_EIGVAL = 1.0e-10;
// first check all the sizes
unsigned int N = mat.numRows();
CHECK_INVARIANT(eigenValues.size() >= numEig, "");

View File

@@ -3,9 +3,9 @@
#define RDKIT_ITERATOR_NEXT_INCLUDED
#if PY_MAJOR_VERSION >= 3
#define NEXT_METHOD "__next__"
const char* const NEXT_METHOD = "__next__";
#else
#define NEXT_METHOD "next"
const char* const NEXT_METHOD = "next";
#endif
#endif