<commit_before>#ifndef __avm_cxx
#define __avm_cxx

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVector.h"
#include "itkImage.h"
#include "itkImageRegionConstIterator.h"
#include "itkGradientToMagnitudeImageFilter.h"
#include "itkExceptionObject.h"

#include <map>
#include <iostream>
#include <string>


template <
  unsigned int NImageDimension,
  unsigned int NSpaceDimension,
  class ValueType >
ValueType run_avm(const char * inputFileName, const char * outputFileName = 0)
{
  /** Typedefs */

  const unsigned int ImageDimension = NImageDimension;
  const unsigned int SpaceDimension = NSpaceDimension;

  typedef ValueType     InputValueType;
  typedef itk::Vector<InputValueType, SpaceDimension> InputPixelType;
  typedef InputValueType    OutputPixelType;

  typedef itk::Image<InputPixelType, ImageDimension>  InputImageType;
  typedef itk::Image<OutputPixelType, ImageDimension>   OutputImageType;
  typedef typename OutputImageType::Pointer OutputImagePointer;
  typedef itk::ImageRegionConstIterator<OutputImageType>  IteratorType;

  typedef itk::ImageFileReader<InputImageType>  ReaderType;
  typedef itk::ImageFileWriter<OutputImageType>   WriterType;
  typedef typename ReaderType::Pointer ReaderPointer;
  typedef typename WriterType::Pointer WriterPointer;

  typedef itk::GradientToMagnitudeImageFilter<
    InputImageType, OutputImageType>  FilterType;
  typedef typename FilterType::Pointer    FilterPointer;

  /** Create variables */

  ReaderPointer reader = ReaderType::New();
  WriterPointer writer = 0;
  FilterPointer filter = FilterType::New();
  OutputImagePointer magnitudeImage = 0;

  /** Setup the pipeline */
  reader->SetFileName(inputFileName);
  filter->SetInput( reader->GetOutput() );
  magnitudeImage = filter->GetOutput();

  /** Only write to disk if an outputFileName is given */
  if (outputFileName)
  {
    if (std::string(outputFileName) != "")
    {
      writer = WriterType::New();
      writer->SetFileName(outputFileName);
      writer->SetInput( magnitudeImage );
    }
  }

  try
  {
    if (writer)
    {
      writer->Update();
    }
    else
    {
      magnitudeImage->Update();
    }
  }
  catch (itk::ExceptionObject & err)
  {
    std::cerr << err << std::endl;
    throw err;
  }

  /** Sum over the resulting image and divide by the number of pixels */
  IteratorType iterator(magnitudeImage, magnitudeImage->GetLargestPossibleRegion() );
  double sum = 0.0;
  unsigned long nrOfPixels = 0;

  for (iterator = iterator.Begin(); !iterator.IsAtEnd(); ++iterator)
  {
    sum += iterator.Value();
    ++nrOfPixels;
  }
  ValueType averageVectorMagnitude = static_cast<ValueType>( sum / nrOfPixels );

  return averageVectorMagnitude;

} // end function run_avm

void PrintUsageString(void)
{
  std::cerr
    << "Calculate the average magnitude of the vectors in a vector image.\n\n"
    << "Usage:\n"
    << "AverageVectorMagnitude\n"
    << "\t-in InputVectorImageFileName\n"
    << "\t[-out OutputImageFileName]\n"
    << "\t-id ImageDimension\n"
    << "\t-sd SpaceDimension (the dimension of the vectors)\n"
    << std::endl;
}


int main(int argc, char** argv)
{
  typedef std::map<std::string, std::string> ArgMapType;
  typedef float ValueType;

  ArgMapType argmap;
  std::string inputFileName("");
  std::string outputFileName("");
  std::string imageDimension("");
  std::string spaceDimension("");

  /** Fill the argument map */
  for (unsigned int i = 1; i<argc; i+=2)
  {
    if ( (i+1) < argc)
    {
      argmap[ argv[i] ] = argv[i+1];
    }
    else
    {
      argmap[ argv[i] ] = "";
    }
  }<commit_msg>ENH: fix unsigned int warnings<commit_after>#ifndef __avm_cxx
#define __avm_cxx

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVector.h"
#include "itkImage.h"
#include "itkImageRegionConstIterator.h"
#include "itkGradientToMagnitudeImageFilter.h"
#include "itkExceptionObject.h"

#include <map>
#include <iostream>
#include <string>


template <
  unsigned int NImageDimension,
  unsigned int NSpaceDimension,
  class ValueType >
ValueType run_avm(const char * inputFileName, const char * outputFileName = 0)
{
  /** Typedefs */

  const unsigned int ImageDimension = NImageDimension;
  const unsigned int SpaceDimension = NSpaceDimension;

  typedef ValueType     InputValueType;
  typedef itk::Vector<InputValueType, SpaceDimension> InputPixelType;
  typedef InputValueType    OutputPixelType;

  typedef itk::Image<InputPixelType, ImageDimension>  InputImageType;
  typedef itk::Image<OutputPixelType, ImageDimension>   OutputImageType;
  typedef typename OutputImageType::Pointer OutputImagePointer;
  typedef itk::ImageRegionConstIterator<OutputImageType>  IteratorType;

  typedef itk::ImageFileReader<InputImageType>  ReaderType;
  typedef itk::ImageFileWriter<OutputImageType>   WriterType;
  typedef typename ReaderType::Pointer ReaderPointer;
  typedef typename WriterType::Pointer WriterPointer;

  typedef itk::GradientToMagnitudeImageFilter<
    InputImageType, OutputImageType>  FilterType;
  typedef typename FilterType::Pointer    FilterPointer;

  /** Create variables */

  ReaderPointer reader = ReaderType::New();
  WriterPointer writer = 0;
  FilterPointer filter = FilterType::New();
  OutputImagePointer magnitudeImage = 0;

  /** Setup the pipeline */
  reader->SetFileName(inputFileName);
  filter->SetInput( reader->GetOutput() );
  magnitudeImage = filter->GetOutput();

  /** Only write to disk if an outputFileName is given */
  if (outputFileName)
  {
    if (std::string(outputFileName) != "")
    {
      writer = WriterType::New();
      writer->SetFileName(outputFileName);
      writer->SetInput( magnitudeImage );
    }
  }

  try
  {
    if (writer)
    {
      writer->Update();
    }
    else
    {
      magnitudeImage->Update();
    }
  }
  catch (itk::ExceptionObject & err)
  {
    std::cerr << err << std::endl;
    throw err;
  }

  /** Sum over the resulting image and divide by the number of pixels */
  IteratorType iterator(magnitudeImage, magnitudeImage->GetLargestPossibleRegion() );
  double sum = 0.0;
  unsigned long nrOfPixels = 0;

  for (iterator = iterator.Begin(); !iterator.IsAtEnd(); ++iterator)
  {
    sum += iterator.Value();
    ++nrOfPixels;
  }
  ValueType averageVectorMagnitude = static_cast<ValueType>( sum / nrOfPixels );

  return averageVectorMagnitude;

} // end function run_avm

void PrintUsageString(void)
{
  std::cerr
    << "Calculate the average magnitude of the vectors in a vector image.\n\n"
    << "Usage:\n"
    << "AverageVectorMagnitude\n"
    << "\t-in InputVectorImageFileName\n"
    << "\t[-out OutputImageFileName]\n"
    << "\t-id ImageDimension\n"
    << "\t-sd SpaceDimension (the dimension of the vectors)\n"
    << std::endl;
}


int main(int argc, char** argv)
{
  typedef std::map<std::string, std::string> ArgMapType;
  typedef float ValueType;

  ArgMapType argmap;
  std::string inputFileName("");
  std::string outputFileName("");
  std::string imageDimension("");
  std::string spaceDimension("");

  /** Fill the argument map */
  for (unsigned int i = 1; i < static_cast<unsigned int>(argc); i+=2)
  {
    if ( (i+1) < static_cast<unsigned int>(argc))
    {
      argmap[ argv[i] ] = argv[i+1];
    }
    else
    {
      argmap[ argv[i] ] = "";
    }
  }
{'fraction_non_alphanumeric': 0.12050335111475859, 'fraction_numerical': 0.002735603884557516, 'mean_word_length': 4.102581995812979, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 49, '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': '5212695', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2240, 'n_words': 539}