<commit_before>/*
 * File: cint2e.c
 * Author: <NAME> <<EMAIL>>
 *
 * basic cGTO integrals
 */

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "cint_bas.h"
#include "g2e.h"
#include "optimizer.h"
#include "cint2e.h"
#include "misc.h"
#include "cart2sph.h"
#include "c2f.h"

#define SQUARE(r)       (r)[0]*(r)[0] + (r)[1]*(r)[1] + (r)[2]*(r)[2]

#define PRIM2CTR0(ctrsymb, gp, ngp) \
        if (ctrsymb##_ctr > 1) {\
                if (*ctrsymb##empty) { \
                        CINTprim_to_ctr_0(gctr##ctrsymb, ngp, gp, \
                                          envs->ctrsymb##_prim, \
                                          ctrsymb##_ctr, c##ctrsymb+ctrsymb##p); \
                } else { \
                        CINTprim_to_ctr_1(gctr##ctrsymb, ngp, gp, \
                                          envs->ctrsymb##_prim, \
                                          ctrsymb##_ctr, c##ctrsymb+ctrsymb##p); \
                } \
        } \
        *ctrsymb##empty = 0

void CINTprim_to_ctr_0(double *gc, const int nf, const double *gp,
                       const int nprim, const int nctr, const double *coeff)
{
        int n, i;
        double *p0, *p1, *p2;
        double non0coeff[32];
        int non0idx[32];
        int non0ctr = 0;

        for (i = 0; i < nctr; i++) {
                if (coeff[nprim*i] != 0) {
                        non0coeff[non0ctr] = coeff[nprim*i];
                        non0idx[non0ctr] = i;
                        non0ctr++;
                } else { // need to initialize the memory, since += is used later
                        memset(gc+nf*i, 0, sizeof(double)*nf);
                }
        }

        switch (non0ctr) {
                case 1:
                        p0 = gc + nf*non0idx[0];
                        for (n = 0; n < nf; n++) {
                                p0[n] = non0coeff[0] * gp[n];
                        }
                        break;
                case 2:
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        for (n = 0; n < nf; n++) {
                                p0[n] = non0coeff[0] * gp[n];
                                p1[n] = non0coeff[1] * gp[n];
                        }
                        break;
                case 3:
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        p2 = gc + nf*non0idx[2];
                        for (n = 0; n < nf; n++) {
                                p0[n] = non0coeff[0] * gp[n];
                                p1[n] = non0coeff[1] * gp[n];
                                p2[n] = non0coeff[2] * gp[n];
                        }
                        break;
                default:
                        for (i = 0; i < non0ctr-1; i+=2) {
                                p0 = gc + nf*non0idx[i  ];
                                p1 = gc + nf*non0idx[i+1];
                                for (n = 0; n < nf; n++) {
                                        p0[n] = non0coeff[i  ] * gp[n];
                                        p1[n] = non0coeff[i+1] * gp[n];
                                }
                        }
                        if (i < non0ctr) {
                                p0 = gc + nf*non0idx[i];
                                for (n = 0; n < nf; n++) {
                                        p0[n] = non0coeff[i] * gp[n];
                                }
                        }
        }
}

static void prim_to_ctr_opt(double *gc, const int nf, const double *gp,
                            double *non0coeff, int *non0idx, int non0ctr)
{
        int n, i;
        double *p0, *p1, *p2;

        switch (non0ctr) {
                case 1:
                        p0 = gc + nf*non0idx[0];
                        for (n = 0; n < nf; n++) {
                                p0[n] += non0coeff[0] * gp[n];
                        }
                        break;
                case 2:
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        for (n = 0; n < nf; n++) {
                                p0[n] += non0coeff[0] * gp[n];
                                p1[n] += non0coeff[1] * gp[n];
                        }
                        break;
                case 3:
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        p2 = gc + nf*non0idx[2];
                        for (n = 0; n < nf; n++) {
                                p0[n] += non0coeff[0] * gp[n];
                                p1[n] += non0coeff[1] * gp[n];
                                p2[n] += non0coeff[2] * gp[n];
                        }
                        break;
                default:
                        for (i = 0; i < non0ctr-1; i+=2) {
                                p0 = gc + nf*non0idx[i  ];
                                p1 = gc + nf*non0idx[i+1];
                                for (n = 0; n < nf; n++) {
                                        p0[n] += non0coeff[i  ] * gp[n];
                                        p1[n] += non0coeff[i+1] * gp[n];
                                }
                        }
                        if (i < non0ctr) {
                                p0 = gc + nf*non0idx[i];
                                for (n = 0; n < nf; n++) {
                                        p0[n] += non0coeff[i] * gp[n];
                                }
                        }
        }
}

void CINTprim_to_ctr_1(double *gc, const int nf, const double *gp,
                       const int nprim, const int nctr, const double *coeff)<commit_msg>restore previous optimized code<commit_after>/*
 * File: cint2e.c
 * Author: <NAME> <<EMAIL>>
 *
 * basic cGTO integrals
 */

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "cint_bas.h"
#include "g2e.h"
#include "optimizer.h"
#include "cint2e.h"
#include "misc.h"
#include "cart2sph.h"
#include "c2f.h"

#define SQUARE(r)       (r)[0]*(r)[0] + (r)[1]*(r)[1] + (r)[2]*(r)[2]

#define PRIM2CTR0(ctrsymb, gp, ngp) \
        if (ctrsymb##_ctr > 1) {\
                if (*ctrsymb##empty) { \
                        CINTprim_to_ctr_0(gctr##ctrsymb, ngp, gp, \
                                          envs->ctrsymb##_prim, \
                                          ctrsymb##_ctr, c##ctrsymb+ctrsymb##p); \
                } else { \
                        CINTprim_to_ctr_1(gctr##ctrsymb, ngp, gp, \
                                          envs->ctrsymb##_prim, \
                                          ctrsymb##_ctr, c##ctrsymb+ctrsymb##p); \
                } \
        } \
        *ctrsymb##empty = 0

void CINTprim_to_ctr_0(double *gc, const int nf, const double *gp,
                       const int nprim, const int nctr, const double *coeff)
{
        int n, i;
        double c0, c1, c2;
        double *p0, *p1, *p2;
        double non0coeff[32];
        double *non0pgc[32];
        int ncoeff = 0;

        for (i = 0; i < nctr; i++) {
                if (coeff[nprim*i] != 0) {
                        non0coeff[ncoeff] = coeff[nprim*i];
                        non0pgc[ncoeff] = gc + nf * i;
                        ncoeff++;
                } else { // need to initialize the memory, since += is used later
                        memset(gc+nf*i, 0, sizeof(double)*nf);
                }
        }

        switch (ncoeff) {
                case 1:
                        c0 = non0coeff[0];
                        p0 = non0pgc[0];
                        for (n = 0; n < nf; n++) {
                                p0[n] = c0 * gp[n];
                        }
                        break;
                case 2:
                        c0 = non0coeff[0];
                        c1 = non0coeff[1];
                        p0 = non0pgc[0];
                        p1 = non0pgc[1];
                        for (n = 0; n < nf; n++) {
                                p0[n] = c0 * gp[n];
                                p1[n] = c1 * gp[n];
                        }
                        break;
                case 3:
                        c0 = non0coeff[0];
                        c1 = non0coeff[1];
                        c2 = non0coeff[2];
                        p0 = non0pgc[0];
                        p1 = non0pgc[1];
                        p2 = non0pgc[2];
                        for (n = 0; n < nf; n++) {
                                p0[n] = c0 * gp[n];
                                p1[n] = c1 * gp[n];
                                p2[n] = c2 * gp[n];
                        }
                        break;
                default:
                        for (i = 0; i < ncoeff-1; i+=2) {
                                c0 = non0coeff[i  ];
                                c1 = non0coeff[i+1];
                                p0 = non0pgc[i  ];
                                p1 = non0pgc[i+1];
                                for (n = 0; n < nf; n++) {
                                        p0[n] = c0 * gp[n];
                                        p1[n] = c1 * gp[n];
                                }
                        }
                        if (i < ncoeff) {
                                c0 = non0coeff[i];
                                p0 = non0pgc[i];
                                for (n = 0; n < nf; n++) {
                                        p0[n] = c0 * gp[n];
                                }
                        }
        }
}

static void prim_to_ctr_opt(double *gc, const int nf, const double *gp,
                            double *non0coeff, int *non0idx, int non0ctr)
{
        int n, i;
        double c0, c1, c2;
        double *p0, *p1, *p2;

        switch (non0ctr) {
                case 1:
                        c0 = non0coeff[0];
                        p0 = gc + nf*non0idx[0];
                        for (n = 0; n < nf; n++) {
                                p0[n] += c0 * gp[n];
                        }
                        break;
                case 2:
                        c0 = non0coeff[0];
                        c1 = non0coeff[1];
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        for (n = 0; n < nf; n++) {
                                p0[n] += c0 * gp[n];
                                p1[n] += c1 * gp[n];
                        }
                        break;
                case 3:
                        c0 = non0coeff[0];
                        c1 = non0coeff[1];
                        c2 = non0coeff[2];
                        p0 = gc + nf*non0idx[0];
                        p1 = gc + nf*non0idx[1];
                        p2 = gc + nf*non0idx[2];
                        for (n = 0; n < nf; n++) {
                                p0[n] += c0 * gp[n];
                                p1[n] += c1 * gp[n];
                                p2[n] += c2 * gp[n];
                        }
                        break;
                default:
                        for (i = 0; i < non0ctr-1; i+=2) {
                                c0 = non0coeff[i  ];
                                c1 = non0coeff[i+1];
                                p0 = gc + nf*non0idx[i  ];
                                p1 = gc + nf*non0idx[i+1];
                                for (n = 0; n < nf; n++) {
                                        p0[n] += c0 * gp[n];
                                        p1[n] += c1 * gp[n];
                                }
                        }
                        if (i < non0ctr) {
                                c0 = non0coeff[i];
                                p0 = gc + nf*non0idx[i];
                                for (n = 0; n < nf; n++) {
                                        p0[n] += c0 * gp[n];
                                }
                        }
        }
}

void CINTprim_to_ctr_1(double *gc, const int nf, const double *gp,
                       const int nprim, const int nctr, const double *coeff)
{'fraction_non_alphanumeric': 0.12037571063689545, 'fraction_numerical': 0.03122682705775727, 'mean_word_length': 0.6877085650723026, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 71, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4280814', 'n_tokens_mistral': 3939, 'n_tokens_neox': 3659, 'n_words': 775}