<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

  =========================================================================*/
#ifndef __SharkUtils_h
#define __SharkUtils_h

//#include <shark/Algorithms/Trainers/RFTrainer.h>
#include <shark/Data/Dataset.h>
namespace otb
{
namespace Shark
{
template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<shark::RealVector> & output)
{
  assert(listSample != NULL);
  // Sample index
  unsigned int sampleIdx = 0;
    
  //Check for valid listSample
  if(listSample->Size()>0)
    {
    // Retrieve samples count
    output.clear();
    // Build an iterator
    typename T::ConstIterator sampleIt = listSample->Begin();

    // Retrieve samples size alike
    const unsigned int sampleSize = listSample->GetMeasurementVectorSize();

    // Fill the output vector
    for(;sampleIt != listSample->End();++sampleIt,++sampleIdx)
      {
      // Retrieve sample
      typename T::MeasurementVectorType sample = sampleIt.GetMeasurementVector();
	   
      // Define a shark::RealVector
      shark::RealVector rv(sampleSize);
      // Loop on sample size
      for(unsigned int i = 0; i < sampleSize; ++i)
        {
        rv[i] = sample[i];
        }
      output.push_back(rv);
      }
    }
}

template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<unsigned int> & output)
{
  assert(listSample != NULL);
  // Sample index<commit_msg>ENH: ITK_NULLPTR instead if NULL<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

  =========================================================================*/
#ifndef __SharkUtils_h
#define __SharkUtils_h

//#include <shark/Algorithms/Trainers/RFTrainer.h>
#include <shark/Data/Dataset.h>
namespace otb
{
namespace Shark
{
template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<shark::RealVector> & output)
{
  assert(listSample != ITK_NULLPTR);
  // Sample index
  unsigned int sampleIdx = 0;
    
  //Check for valid listSample
  if(listSample->Size()>0)
    {
    // Retrieve samples count
    output.clear();
    // Build an iterator
    typename T::ConstIterator sampleIt = listSample->Begin();

    // Retrieve samples size alike
    const unsigned int sampleSize = listSample->GetMeasurementVectorSize();

    // Fill the output vector
    for(;sampleIt != listSample->End();++sampleIt,++sampleIdx)
      {
      // Retrieve sample
      typename T::MeasurementVectorType sample = sampleIt.GetMeasurementVector();
	   
      // Define a shark::RealVector
      shark::RealVector rv(sampleSize);
      // Loop on sample size
      for(unsigned int i = 0; i < sampleSize; ++i)
        {
        rv[i] = sample[i];
        }
      output.push_back(rv);
      }
    }
}

template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<unsigned int> & output)
{
  assert(listSample != ITK_NULLPTR);
  // Sample index
{'fraction_non_alphanumeric': 0.17410832232496698, 'fraction_numerical': 0.001585204755614267, 'mean_word_length': 3.577992744860943, 'pattern_counts': {'":': 0, '<': 17, '<?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': '3134786', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1046, 'n_words': 303}