<commit_before>#include <newton/newton.hpp>
#include <thrust/device_vector.h>

static const float inv_sqrt2 = sqrt(2.);

template<typename T>
inline __host__ __device__
  auto cnd(const T &x)
    -> decltype(0.5f * (1.f + erf(inv_sqrt2 * x)))
{
  return 0.5f * (1.f + erf(inv_sqrt2 * x));
}

void black_scholes(const thrust::device_vector<float> &stock_price,
                   const thrust::device_vector<float> &option_strike,
                   const thrust::device_vector<float> &option_years,
                   const thrust::device_vector<float> &riskless_rate,
                   const thrust::device_vector<float> &volatility,
                   newton::numeric_vector<float> &call_result,
                   newton::numeric_vector<float> &put_result)
{
  // to apply math functions on device_vector, 
  // we can use a using namespace newton directive
  using namespace newton;

  auto sqrt_option_years = sqrt(option_years);
  auto d1 = (log(stock_price / option_strike) + (riskless_rate + 0.5f * volatility * volatility) * option_years) / (volatility * sqrt_option_years);
  auto d2 = d1 - volatility * sqrt_option_years;

  auto expRT = exp(-riskless_rate * option_years);

  // we receive results as numeric_vector so that we can assign the result of numeric expressions to them
  call_result = stock_price * cnd(d1) - option_strike * expRT * cnd(d2);
  put_result  = option_strike * expRT * (1.0f - cnd(d2)) - stock_price * (1.0f - cnd(d1));
}<commit_msg>Correct typo in black_scholes example<commit_after>#include <newton/newton.hpp>
#include <thrust/device_vector.h>

static const float inv_sqrt2 = 1.f / sqrt(2.);

template<typename T>
inline __host__ __device__
  auto cnd(const T &x)
    -> decltype(0.5f * (1.f + erf(inv_sqrt2 * x)))
{
  return 0.5f * (1.f + erf(inv_sqrt2 * x));
}

void black_scholes(const thrust::device_vector<float> &stock_price,
                   const thrust::device_vector<float> &option_strike,
                   const thrust::device_vector<float> &option_years,
                   const thrust::device_vector<float> &riskless_rate,
                   const thrust::device_vector<float> &volatility,
                   newton::numeric_vector<float> &call_result,
                   newton::numeric_vector<float> &put_result)
{
  // to apply math functions on device_vector, 
  // we can use a using namespace newton directive
  using namespace newton;

  auto sqrt_option_years = sqrt(option_years);
  auto d1 = (log(stock_price / option_strike) + (riskless_rate + 0.5f * volatility * volatility) * option_years) / (volatility * sqrt_option_years);
  auto d2 = d1 - volatility * sqrt_option_years;

  auto expRT = exp(-riskless_rate * option_years);

  // we receive results as numeric_vector so that we can assign the result of numeric expressions to them
  call_result = stock_price * cnd(d1) - option_strike * expRT * cnd(d2);
  put_result  = option_strike * expRT * (1.0f - cnd(d2)) - stock_price * (1.0f - cnd(d1));
}
{'fraction_non_alphanumeric': 0.10976430976430976, 'fraction_numerical': 0.015824915824915825, 'mean_word_length': 3.3627019089574155, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '4594970', 'n_tokens_mistral': 1043, 'n_tokens_neox': 961, 'n_words': 241}