<commit_before>#pragma once

#if defined( USE_EIGEN )

#define GET_COLUMN( VARIABLE, COLUMN_NR )  VARIABLE.col(COLUMN_NR)
#define GET_POINTER( VARIABLE )            VARIABLE.data()
#define GET_NORM( VARIABLE )               VARIABLE.norm()
#define DOT_PRODUCT( VECTOR1, VECTOR2 )    VECTOR1.transpose() * VECTOR2
#define NORM( VECTOR )                     VECTOR.norm()
#include <Eigen/Dense>

template<class Scalar> using HostMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
template<class Scalar> using DeviceMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
template<class Scalar> using HostVector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
template<class Scalar> using DeviceVector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;

#elif defined( USE_MINLIN )

#if defined(DEBUG)
#define MINLIN_DEBUG 1
#endif

#define GET_COLUMN( VARIABLE, COLUMN_NR )  VARIABLE(all,COLUMN_NR)
#define GET_POINTER( VARIABLE )            VARIABLE.pointer()
#define GET_NORM( VARIABLE )               norm( VARIABLE )
#define DOT_PRODUCT( VECTOR1, VECTOR2 )    dot( VECTOR1, VECTOR2 )
#define NORM( VECTOR )                     norm(VECTOR)

#include <minlin/minlin.h>
#include <minlin/modules/threx/threx.h>
using namespace minlin::threx; // just dump the namespace for this example

#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_OMP
MINLIN_INIT
#include <cublas_v2.h>
#endif


#if defined(USE_GPU)
cublasStatus_t cublasTger(cublasHandle_t handle, int m, int n,
    const double *alpha, const double *x, int incx, const double *y, int incy,
    double *A, int lda) {
  cublasStatus_t status = cublasDger(handle, m, n, alpha, x, incx, y, incy,
      A, lda);
  return status;
}
cublasStatus_t cublasTger(cublasHandle_t handle, int m, int n,
    const float *alpha, const float *x, int incx, const float *y, int incy,
    float *A, int lda) {
  cublasStatus_t status = cublasSger(handle, m, n, alpha, x, incx, y, incy,
      A, lda);
  return status;
}
#else
void tger(const int *m, const int *n, double *alpha, const double *x, const
    int *incx, const double *y, const int *incy, double *A, const int *lda) {
  dger(m, n, alpha, x, incx, y, incy, A, lda);
}
void tger(const int *m, const int *n, float *alpha, const float *x, const
    int *incx, const float *y, const int *incy, float *A, const int *lda) {
  sger(m, n, alpha, x, incx, y, incy, A, lda);
}
#endif

// geru (rank-1 update)
// A <- A - alpha*x*y'
template<typename Scalar>
bool geru_wrapper( DeviceMatrix<Scalar> &A, const Scalar* x, const Scalar* y,
    Scalar alpha)
{
  const int inc = 1;
#ifdef USE_GPU
  cublasHandle_t handle = CublasState::instance()->handle();
  cublasStatus_t status = cublasTger(handle, A.rows(), A.cols(), &alpha,
      x, inc, y, inc, A.pointer(), A.rows());
  return (status==CUBLAS_STATUS_SUCCESS);
#else
  const int m = A.rows();
  const int n = A.cols();
  const int lda = m;
  tger(&m, &n, &alpha, const_cast<Scalar*>(x), &inc,
      const_cast<Scalar*>(y), &inc,  A.pointer(), &lda);
  return true;
#endif
}

#else
ERROR!   MUST USE A LIBRARY, E.G. USE_EIGEN OR USE_MINLIN
#endif<commit_msg>real preprocessor error when neither minlin nor eigen is used<commit_after>#pragma once

#if defined( USE_EIGEN )

#define GET_COLUMN( VARIABLE, COLUMN_NR )  VARIABLE.col(COLUMN_NR)
#define GET_POINTER( VARIABLE )            VARIABLE.data()
#define GET_NORM( VARIABLE )               VARIABLE.norm()
#define DOT_PRODUCT( VECTOR1, VECTOR2 )    VECTOR1.transpose() * VECTOR2
#define NORM( VECTOR )                     VECTOR.norm()
#include <Eigen/Dense>

template<class Scalar> using HostMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
template<class Scalar> using DeviceMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
template<class Scalar> using HostVector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
template<class Scalar> using DeviceVector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;

#elif defined( USE_MINLIN )

#if defined(DEBUG)
#define MINLIN_DEBUG 1
#endif

#define GET_COLUMN( VARIABLE, COLUMN_NR )  VARIABLE(all,COLUMN_NR)
#define GET_POINTER( VARIABLE )            VARIABLE.pointer()
#define GET_NORM( VARIABLE )               norm( VARIABLE )
#define DOT_PRODUCT( VECTOR1, VECTOR2 )    dot( VECTOR1, VECTOR2 )
#define NORM( VECTOR )                     norm(VECTOR)

#include <minlin/minlin.h>
#include <minlin/modules/threx/threx.h>
using namespace minlin::threx; // just dump the namespace for this example

#if THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_OMP
MINLIN_INIT
#include <cublas_v2.h>
#endif


#if defined(USE_GPU)
cublasStatus_t cublasTger(cublasHandle_t handle, int m, int n,
    const double *alpha, const double *x, int incx, const double *y, int incy,
    double *A, int lda) {
  cublasStatus_t status = cublasDger(handle, m, n, alpha, x, incx, y, incy,
      A, lda);
  return status;
}
cublasStatus_t cublasTger(cublasHandle_t handle, int m, int n,
    const float *alpha, const float *x, int incx, const float *y, int incy,
    float *A, int lda) {
  cublasStatus_t status = cublasSger(handle, m, n, alpha, x, incx, y, incy,
      A, lda);
  return status;
}
#else
void tger(const int *m, const int *n, double *alpha, const double *x, const
    int *incx, const double *y, const int *incy, double *A, const int *lda) {
  dger(m, n, alpha, x, incx, y, incy, A, lda);
}
void tger(const int *m, const int *n, float *alpha, const float *x, const
    int *incx, const float *y, const int *incy, float *A, const int *lda) {
  sger(m, n, alpha, x, incx, y, incy, A, lda);
}
#endif

// geru (rank-1 update)
// A <- A - alpha*x*y'
template<typename Scalar>
bool geru_wrapper( DeviceMatrix<Scalar> &A, const Scalar* x, const Scalar* y,
    Scalar alpha)
{
  const int inc = 1;
#ifdef USE_GPU
  cublasHandle_t handle = CublasState::instance()->handle();
  cublasStatus_t status = cublasTger(handle, A.rows(), A.cols(), &alpha,
      x, inc, y, inc, A.pointer(), A.rows());
  return (status==CUBLAS_STATUS_SUCCESS);
#else
  const int m = A.rows();
  const int n = A.cols();
  const int lda = m;
  tger(&m, &n, &alpha, const_cast<Scalar*>(x), &inc,
      const_cast<Scalar*>(y), &inc,  A.pointer(), &lda);
  return true;
#endif
}

#else
#error "ERROR! MUST USE A LIBRARY, E.G. USE_EIGEN OR USE_MINLIN"
#endif
{'fraction_non_alphanumeric': 0.13239703329651253, 'fraction_numerical': 0.004418494555783494, 'mean_word_length': 4.123686337914309, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7411186', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2365, 'n_words': 697}