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

 Program:   Visualization Toolkit
 Module:    vtkExtentRCBPartitioner.cxx

 Copyright (c) <NAME>, <NAME>, <NAME>
 All rights reserved.
 See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

 =========================================================================*/

#include "vtkExtentRCBPartitioner.h"
#include "vtkObjectFactory.h"
#include "vtkMath.h"

#include <cmath>
#include <cassert>
#include <algorithm>
#include <vtkstd/queue>

vtkStandardNewMacro( vtkExtentRCBPartitioner );

//------------------------------------------------------------------------------
vtkExtentRCBPartitioner::vtkExtentRCBPartitioner()
{
  this->NumExtents           = 0;
  this->NumberOfSubdivisions = 0;
  for( int i=0; i < 3; ++i )
    {
      this->GlobalExtent[ i ]   = 0;
      this->GlobalExtent[ i+3 ] = 1;
    }
}

//------------------------------------------------------------------------------
vtkExtentRCBPartitioner::~vtkExtentRCBPartitioner()
{
  this->pextents.clear();
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::PrintSelf( std::ostream &oss, vtkIndent indent )
{
  this->Superclass::PrintSelf( oss, indent );
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::Partition()
{
  this->pextents.clear();
  this->pextents.resize( this->GetNumberOfTotalExtents()*6 );

  this->AddExtent( 0, this->GlobalExtent );
  assert( "pre: Unexpected number of extents:" && (this->NumExtents==1) );

  int ex[6]; // temporary buffer to store the current extent
  int s1[6]; // temporary buffer to store the sub-extent s1
  int s2[6]; // temporary buffer to store the sub-extent s2

  for( int i=0; i < this->GetNumberOfSubdivisions(); ++i )
    {
      int N = this->NumExtents;
      for( int e=0; e < N; ++e )
        {
          this->GetExtent( e, ex );
          int ldim = this->GetLongestDimension( ex );

          this->SplitExtent( ex, s1, s2, ldim );
          this->ReplaceExtent( e, s1 );
          this->AddExtent( this->NumExtents, s2 );
        } // END for all extents
    } // END for all subdivisions

}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::GetExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    ext[ i ] = this->pextents[ idx*6+i ];
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::AddExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    this->pextents[ idx*6+i ] = ext[ i ];
  ++this->NumExtents;
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::ReplaceExtent(const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    this->pextents[ idx*6+i ] = ext[ i ];
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::GetPartitionExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    ext[i] = this->pextents[idx*6+i];
}

//------------------------------------------------------------------------------
int vtkExtentRCBPartitioner::GetNumberOfTotalExtents()
{
  int N = std::pow( 2,this->NumberOfSubdivisions );
  assert( "pre: N >= 1" && (N >= 1) );
  return N;
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::SplitExtent(
    int parent[6], int s1[6], int s2[6], int dimension )
{
  int numNodes = 0;
  int mid      = -1;
  int minIdx   = -1;
  int maxIdx   = -1;

  for( int i=0; i < 6; ++i )
    s1[ i ] = s2[ i ] = parent[ i ];<commit_msg>COMP: Explicitely cast params to double in pow()<commit_after>/*=========================================================================

 Program:   Visualization Toolkit
 Module:    vtkExtentRCBPartitioner.cxx

 Copyright (c) <NAME>, <NAME>, <NAME>
 All rights reserved.
 See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

 =========================================================================*/

#include "vtkExtentRCBPartitioner.h"
#include "vtkObjectFactory.h"
#include "vtkMath.h"

#include <cmath>
#include <cassert>
#include <algorithm>
#include <vtkstd/queue>

vtkStandardNewMacro( vtkExtentRCBPartitioner );

//------------------------------------------------------------------------------
vtkExtentRCBPartitioner::vtkExtentRCBPartitioner()
{
  this->NumExtents           = 0;
  this->NumberOfSubdivisions = 0;
  for( int i=0; i < 3; ++i )
    {
      this->GlobalExtent[ i ]   = 0;
      this->GlobalExtent[ i+3 ] = 1;
    }
}

//------------------------------------------------------------------------------
vtkExtentRCBPartitioner::~vtkExtentRCBPartitioner()
{
  this->pextents.clear();
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::PrintSelf( std::ostream &oss, vtkIndent indent )
{
  this->Superclass::PrintSelf( oss, indent );
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::Partition()
{
  this->pextents.clear();
  this->pextents.resize( this->GetNumberOfTotalExtents()*6 );

  this->AddExtent( 0, this->GlobalExtent );
  assert( "pre: Unexpected number of extents:" && (this->NumExtents==1) );

  int ex[6]; // temporary buffer to store the current extent
  int s1[6]; // temporary buffer to store the sub-extent s1
  int s2[6]; // temporary buffer to store the sub-extent s2

  for( int i=0; i < this->GetNumberOfSubdivisions(); ++i )
    {
      int N = this->NumExtents;
      for( int e=0; e < N; ++e )
        {
          this->GetExtent( e, ex );
          int ldim = this->GetLongestDimension( ex );

          this->SplitExtent( ex, s1, s2, ldim );
          this->ReplaceExtent( e, s1 );
          this->AddExtent( this->NumExtents, s2 );
        } // END for all extents
    } // END for all subdivisions

}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::GetExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    ext[ i ] = this->pextents[ idx*6+i ];
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::AddExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    this->pextents[ idx*6+i ] = ext[ i ];
  ++this->NumExtents;
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::ReplaceExtent(const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    this->pextents[ idx*6+i ] = ext[ i ];
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::GetPartitionExtent( const int idx, int ext[6] )
{
  int N = this->GetNumberOfTotalExtents();
  assert( "pre: invalide pextents size" && ( (this->pextents.size()/6)==N) );
  assert( "pre: idx is out-of-bounds" && ( (idx >= 0) && (idx < N) ) );

  for( int i=0; i < 6; ++i )
    ext[i] = this->pextents[idx*6+i];
}

//------------------------------------------------------------------------------
int vtkExtentRCBPartitioner::GetNumberOfTotalExtents()
{
  int N = std::pow( 
      static_cast<double>(2),
      static_cast<double>(this->NumberOfSubdivisions) );
  assert( "pre: N >= 1" && (N >= 1) );
  return N;
}

//------------------------------------------------------------------------------
void vtkExtentRCBPartitioner::SplitExtent(
    int parent[6], int s1[6], int s2[6], int dimension )
{
  int numNodes = 0;
  int mid      = -1;
  int minIdx   = -1;
  int maxIdx   = -1;

  for( int i=0; i < 6; ++i )
    s1[ i ] = s2[ i ] = parent[ i ];
{'fraction_non_alphanumeric': 0.3301345572128925, 'fraction_numerical': 0.013142797538333159, 'mean_word_length': 1.858676207513417, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4991446', 'n_tokens_mistral': 3029, 'n_tokens_neox': 2968, 'n_words': 730}