<commit_before>#ifndef CNN_GPU_FUNCTORS_H
#define CNN_GPU_FUNCTORS_H

#if HAVE_CUDA
#  define CNN_DEVICE_FUNC __device__
#else
#  define CNN_DEVICE_FUNC
#endif

// these functions are used both in CPU and in GPU computation
// this file may be compiled with NVCC or a standard C++ tool.
// if you need a new elementwise (nullary, unary, binary...)
// functor, this is the place for it

#define cast_uint32_t static_cast<uint32_t>

static inline float fastpow2 (float p) {
  float offset = (p < 0) ? 1.0f : 0.0f;
  float clipp = (p < -126) ? -126.0f : p;
  int w = clipp;
  float z = clipp - w + offset;
  union { uint32_t i; float f; } v = { cast_uint32_t ( (1 << 23) * (clipp + 121.2740575f + 27.7280233f / (4.84252568f - z) - 1.49012907f * z) ) };

  return v.f;
}

static inline float fastexp (float p) {
  return fastpow2 (1.442695040f * p);
}

#define CNN_EXPF fastexp

namespace cnn {

struct FHuberForward {
  FHuberForward(float c) : c(c) {}
  CNN_DEVICE_FUNC inline float operator()(float x) const {
    const float a = fabs(x);
    return (a < c) ? x*x : c*(2*a - c);
  }
  const float c;
};

template <typename T> int sgn(T val) {
  return (T(0) < val) - (val < T(0));
}

struct FHuberBackward {
  FHuberBackward(float c) : c(c) {}
  CNN_DEVICE_FUNC inline float operator()(float x, float d) const {
    const float a = fabs(x);
    return (2 * d) * ((a < c) ? x : c * sgn(x));
  }
  const float c;
};

struct FProduct {
  CNN_DEVICE_FUNC inline float operator()(float a, float b) const {<commit_msg>Fixed functors to work with CUDA<commit_after>#ifndef CNN_GPU_FUNCTORS_H
#define CNN_GPU_FUNCTORS_H

#include <cstdint>

#if HAVE_CUDA
#  define CNN_DEVICE_FUNC __device__
#else
#  define CNN_DEVICE_FUNC
#endif

// these functions are used both in CPU and in GPU computation
// this file may be compiled with NVCC or a standard C++ tool.
// if you need a new elementwise (nullary, unary, binary...)
// functor, this is the place for it

#define cast_uint32_t static_cast<uint32_t>

static inline float fastpow2 (float p) {
  float offset = (p < 0) ? 1.0f : 0.0f;
  float clipp = (p < -126) ? -126.0f : p;
  int w = clipp;
  float z = clipp - w + offset;
  union { uint32_t i; float f; } v = { cast_uint32_t ( (1 << 23) * (clipp + 121.2740575f + 27.7280233f / (4.84252568f - z) - 1.49012907f * z) ) };

  return v.f;
}

static inline float fastexp (float p) {
  return fastpow2 (1.442695040f * p);
}

#if HAVE_CUDA
#  define CNN_EXPF exp
#else
#  define CNN_EXPF fastexp
#endif

namespace cnn {

struct FHuberForward {
  FHuberForward(float c) : c(c) {}
  CNN_DEVICE_FUNC inline float operator()(float x) const {
    const float a = fabs(x);
    return (a < c) ? x*x : c*(2*a - c);
  }
  const float c;
};

template <typename T> int sgn(T val) {
  return (T(0) < val) - (val < T(0));
}

struct FHuberBackward {
  FHuberBackward(float c) : c(c) {}
  CNN_DEVICE_FUNC inline float operator()(float x, float d) const {
    const float a = fabs(x);
    return (2 * d) * ((a < c) ? x : c * sgn(x));
  }
  const float c;
};

struct FProduct {
  CNN_DEVICE_FUNC inline float operator()(float a, float b) const {
{'fraction_non_alphanumeric': 0.1294571153228397, 'fraction_numerical': 0.048827497590748475, 'mean_word_length': 3.3370473537604455, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 8, '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': '7098604', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1213, 'n_words': 388}