<commit_before>/*
 * lui_2d_integration.h
 *
 *  Copyright (C) 2013 Diamond Light Source
 *
 *  Author: <NAME>
 *
 *  This code is distributed under the BSD license, a copy of which is
 *  included in the root directory of this package.
 */
#ifndef DIALS_ALGORITHMS_LUI_INTEGRATION_2D_H
#define DIALS_ALGORITHMS_LUI_INTEGRATION_2D_H
#include <stdio.h>
#include <iostream>
#include <scitbx/vec2.h>
#include <scitbx/array_family/flex_types.h>
#include <cmath>
#include <cstdlib>
#include <scitbx/array_family/versa_matrix.h>
#include <dials/array_family/scitbx_shared_and_versa.h>
#include <dials/model/data/shoebox.h>
#include <scitbx/array_family/versa_matrix.h>
#include <scitbx/array_family/accessors/mat_grid.h>

namespace dials { namespace algorithms {

  using scitbx::vec2;
  // using dials::model::Valid;
  
  using scitbx::af::flex_int;
  using scitbx::af::flex_double;
  using scitbx::af::flex_grid;
  using dials::model::Foreground;
  using dials::model::Background;

  vec2<double> raw_2d_cut(
    const af::const_ref< double, af::c_grid<2> > &data2d,
    const af::const_ref< int, af::c_grid<2> > &mask2d,
    const af::const_ref< double, af::c_grid<2> > &background2d) {
      double i_s = 0, i_bg = 0, rho_j = 0;
      double n = 0, m = 0;
      int cont = 0;
      double var_i;
      std::size_t ncol=data2d.accessor()[1];
      std::size_t nrow=data2d.accessor()[0];
      vec2<double> integr_data(0,1);


      for (int row = 0; row<nrow;row++) {
        for (int col = 0; col<ncol;col++) {
          if ( mask2d(row,col) & Foreground ) {
            i_s  += data2d(row,col) - background2d(row,col);
            i_bg += background2d(row,col);
            m++;
          } else if(mask2d(row,col) & Background) {
            rho_j += background2d(row,col);
            n++;
          }
          cont++;
        }
      }
      if( i_bg>0 && cont>0 && m>0 && n>0 ){
        var_i = i_s + i_bg + (m / n) * ( m / n) * rho_j;
      } else {
        var_i = i_s;
      }

      integr_data[0]=i_s;            // intensity sumation
      integr_data[1]=var_i;          // intensity variance
      return integr_data;

    }

   flex_double add_2d(flex_double descriptor, flex_double data2d, flex_double tmp_total) {
    flex_double total(tmp_total);
    int ncol_in = data2d.accessor().all()[1];
    int nrow_in = data2d.accessor().all()[0];
    int ncol_tot = tmp_total.accessor().all()[1];
    int nrow_tot = tmp_total.accessor().all()[0];

    double centr_col = descriptor(0,0);
    double centr_row = descriptor(0,1);
    double scale = descriptor(0,2);

    double tot_row, tot_col;
    double x_contrib, y_contrib, x_pix_pos, y_pix_pos;
    int xpos_ex, ypos_ex;

    int tot_row_centr=int(nrow_tot / 2);
    int tot_col_centr=int(ncol_tot / 2);

    for (int row = 0; row < nrow_in; row++) {
      for (int col = 0; col < ncol_in; col++) {
        tot_row = row + tot_row_centr - centr_row + 1;
        tot_col = col + tot_col_centr - centr_col + 1;
        if (tot_row >= 0 and tot_col >= 0 and tot_row < nrow_tot and tot_col < ncol_tot) {

          x_pix_pos=tot_col - int(tot_col);
          if (x_pix_pos < 0.5) {
            x_contrib = 0.5 + x_pix_pos;<commit_msg>testing adding<commit_after>/*
 * lui_2d_integration.h
 *
 *  Copyright (C) 2013 Diamond Light Source
 *
 *  Author: <NAME>
 *
 *  This code is distributed under the BSD license, a copy of which is
 *  included in the root directory of this package.
 */
#ifndef DIALS_ALGORITHMS_LUI_INTEGRATION_2D_H
#define DIALS_ALGORITHMS_LUI_INTEGRATION_2D_H
#include <stdio.h>
#include <iostream>
#include <scitbx/vec2.h>
#include <scitbx/array_family/flex_types.h>
#include <cmath>
#include <cstdlib>
#include <scitbx/array_family/versa_matrix.h>
#include <dials/array_family/scitbx_shared_and_versa.h>
#include <dials/model/data/shoebox.h>
#include <scitbx/array_family/versa_matrix.h>
#include <scitbx/array_family/accessors/mat_grid.h>

namespace dials { namespace algorithms {

  using scitbx::vec2;
  // using dials::model::Valid;
  
  using scitbx::af::flex_int;
  using scitbx::af::flex_double;
  using scitbx::af::flex_grid;
  using dials::model::Foreground;
  using dials::model::Background;

  vec2<double> raw_2d_cut(
    const af::const_ref< double, af::c_grid<2> > &data2d,
    const af::const_ref< int, af::c_grid<2> > &mask2d,
    const af::const_ref< double, af::c_grid<2> > &background2d) {
      double i_s = 0, i_bg = 0, rho_j = 0;
      double n = 0, m = 0;
      int cont = 0;
      double var_i;
      std::size_t ncol=data2d.accessor()[1];
      std::size_t nrow=data2d.accessor()[0];
      vec2<double> integr_data(0,1);


      for (int row = 0; row<nrow;row++) {
        for (int col = 0; col<ncol;col++) {
          if ( mask2d(row,col) & Foreground ) {
            i_s  += data2d(row,col) - background2d(row,col);
            i_bg += background2d(row,col);
            m++;
          } else if(mask2d(row,col) & Background) {
            rho_j += background2d(row,col);
            n++;
          }
          cont++;
        }
      }
      if( i_bg>0 && cont>0 && m>0 && n>0 ){
        var_i = i_s + i_bg + (m / n) * ( m / n) * rho_j;
      } else {
        var_i = i_s;
      }

      integr_data[0]=i_s;            // intensity sumation
      integr_data[1]=var_i;          // intensity variance
      return integr_data;

    }

    
   flex_double add_2d(flex_double descriptor, flex_double data2d, flex_double tmp_total) {
    flex_double total(tmp_total);
    int ncol_in = data2d.accessor().all()[1];
    int nrow_in = data2d.accessor().all()[0];
    int ncol_tot = tmp_total.accessor().all()[1];
    int nrow_tot = tmp_total.accessor().all()[0];

    double centr_col = descriptor(0,0);
    double centr_row = descriptor(0,1);
    double scale = descriptor(0,2);

    double tot_row, tot_col;
    double x_contrib, y_contrib, x_pix_pos, y_pix_pos;
    int xpos_ex, ypos_ex;

    int tot_row_centr=int(nrow_tot / 2);
    int tot_col_centr=int(ncol_tot / 2);

    for (int row = 0; row < nrow_in; row++) {
      for (int col = 0; col < ncol_in; col++) {
        tot_row = row + tot_row_centr - centr_row + 1;
        tot_col = col + tot_col_centr - centr_col + 1;
        if (tot_row >= 0 and tot_col >= 0 and tot_row < nrow_tot and tot_col < ncol_tot) {

          x_pix_pos=tot_col - int(tot_col);
          if (x_pix_pos < 0.5) {
            x_contrib = 0.5 + x_pix_pos;
{'fraction_non_alphanumeric': 0.13619286161552913, 'fraction_numerical': 0.021916092673763307, 'mean_word_length': 2.8511151295961423, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 55, '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': '4544019', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2456, 'n_words': 512}