<commit_before>// This file is part of the cube - ica/cuda - software package
// Copyright © 2010-2013 <NAME> <<EMAIL>>
// License: MIT (see LICENSE.BSD-MIT)

#include <cube_math.h>
#ifdef __APPLE__
#include <Accelerate/Accelerate.h>
#else
#ifdef HAVE_MKL
#include <mkl_cblas.h>
#include <mkl_lapacke.h>
#elif HAVE_ACML
#include <acml.h>
#else
#include <cblas.h>
#endif
#endif

#ifdef HAVE_CULA
#include <cula_lapack_device.h>
#endif

#include "cube_private.h"

#include <stdlib.h>
#include <stdio.h>
#include <math.h>


#define min(a,b) ((a)>(b)?(b):(a))

void
cube_host_dgesvd (char jobu, char jobvt, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt, int *info)
{
#ifdef __APPLE__
  double  cwork;
  double *work;
  int     lwork;

  dgesvd_(&jobu, &jobvt,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  &cwork, &lwork, info);

  lwork = (int) cwork;

  work = malloc (lwork * sizeof (double));

  dgesvd_(&jobu, &jobvt,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  work, &lwork, info);

  free (work);
#elif defined (HAVE_MKL)
#if 0
  double superb[min(m,n)];
  *info = LAPACKE_dgesvd (LAPACK_COL_MAJOR, jobu, jobvt, m, n, A, lda,
			  s, U, ldu, Vt, ldvt, superb);
#else
  *info = LAPACKE_dgesdd(LAPACK_COL_MAJOR, 'S', m, n, A, lda, s,
			U, ldu, Vt, ldvt);
#endif

#else
  dgesvd (jobu, jobvt, m, n, A, lda, s, U, ldu, Vt, ldvt, info);
#endif
}

void
cube_host_dgesdd (char jobz, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt, int *info)
{
#ifdef __APPLE__
  double  cwork;
  double *work;
  int     lwork;
  int    *iwork;

  iwork = malloc (sizeof(int) * 8 * min(m, n));
  lwork = -1;

  dgesdd_(&jobz,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  &cwork, &lwork, iwork, info);

  if (*info != 0)
    {
      fprintf (stderr, "dgesdd_: error during workspace estimation %d\n", *info);
      return;
    }

  lwork = (int) cwork;
  work = malloc (lwork * sizeof(double));
  
  dgesdd_(&jobz,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  work, &lwork, iwork, info);

  free (work);
  free (iwork);
#elif defined (HAVE_MKL)
  *info = LAPACKE_dgesdd (LAPACK_COL_MAJOR, jobz, m, n, A, lda, s,
			  U, ldu, Vt, ldvt);
#else
  dgesdd (jobz, m, n, A, lda, s, U, ldu, Vt, ldvt, info);
#endif
}

void
cube_gpu_dgesdd (cube_t *ctx, char jobs, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt)<commit_msg>Cube-Math: Fix build on linux (dgesdd invocation)<commit_after>// This file is part of the cube - ica/cuda - software package
// Copyright © 2010-2013 <NAME> <<EMAIL>>
// License: MIT (see LICENSE.BSD-MIT)

#include <cube_math.h>
#ifdef __APPLE__
#include <Accelerate/Accelerate.h>
#else
#ifdef HAVE_MKL
#include <mkl_cblas.h>
#include <mkl_lapacke.h>
#elif HAVE_ACML
#include <acml.h>
#else
#include <cblas.h>
#include <lapacke.h>
#endif
#endif

#ifdef HAVE_CULA
#include <cula_lapack_device.h>
#endif

#include "cube_private.h"

#include <stdlib.h>
#include <stdio.h>
#include <math.h>


#define min(a,b) ((a)>(b)?(b):(a))

void
cube_host_dgesvd (char jobu, char jobvt, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt, int *info)
{
#ifdef __APPLE__
  double  cwork;
  double *work;
  int     lwork;

  dgesvd_(&jobu, &jobvt,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  &cwork, &lwork, info);

  lwork = (int) cwork;

  work = malloc (lwork * sizeof (double));

  dgesvd_(&jobu, &jobvt,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  work, &lwork, info);

  free (work);
#elif defined (HAVE_ACML)
  dgesvd (jobu, jobvt, m, n, A, lda, s, U, ldu, Vt, ldvt, info);
#else
  double superb[min(m,n)];
  *info = LAPACKE_dgesvd (LAPACK_COL_MAJOR, jobu, jobvt, m, n, A, lda,
			  s, U, ldu, Vt, ldvt, superb);
#endif
}

void
cube_host_dgesdd (char jobz, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt, int *info)
{
#ifdef __APPLE__
  double  cwork;
  double *work;
  int     lwork;
  int    *iwork;

  iwork = malloc (sizeof(int) * 8 * min(m, n));
  lwork = -1;

  dgesdd_(&jobz,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  &cwork, &lwork, iwork, info);

  if (*info != 0)
    {
      fprintf (stderr, "dgesdd_: error during workspace estimation %d\n", *info);
      return;
    }

  lwork = (int) cwork;
  work = malloc (lwork * sizeof(double));
  
  dgesdd_(&jobz,
	  &m, &n, A, &lda,
	  s,
	  U, &ldu,
	  Vt, &ldvt,
	  work, &lwork, iwork, info);

  free (work);
  free (iwork);
#elif defined (HAVE_ACML)
  dgesdd (jobz, m, n, A, lda, s, U, ldu, Vt, ldvt, info);
#else
  *info = LAPACKE_dgesdd (LAPACK_COL_MAJOR, jobz, m, n, A, lda, s,
			  U, ldu, Vt, ldvt);
#endif
}

void
cube_gpu_dgesdd (cube_t *ctx, char jobs, int m, int n, double *A, int lda, double *s, double *U, int ldu, double *Vt, int ldvt)
{'fraction_non_alphanumeric': 0.1700988467874794, 'fraction_numerical': 0.004736408566721581, 'mean_word_length': 3.3756756756756756, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, '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': '6489531', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2241, 'n_words': 649}