<commit_before>#include <algorithm>
#include <iostream>
#include <string>
#include <cstdio>
#include "../include/ecuda/array.hpp"
#include "../include/ecuda/vector.hpp"

template<typename T> __global__
void kernel_checkVectorProperties(
	const ecuda::vector<T> constVector,
	ecuda::vector<T> vector,
	ecuda::vector<T> empties,
	ecuda::vector<typename ecuda::vector<T>::size_type> sizes,
	ecuda::vector<typename ecuda::vector<T>::pointer> pointers//,
//	ecuda::vector<typename ecuda::vector<T>::const_pointer> constPointers
)
{
	const int threadNumber = threadIdx.x;
	empties[threadNumber] = constVector.empty() ? 1 : 0;
	sizes[threadNumber] = constVector.size();
	pointers[threadNumber] = vector.data();
	//constPointers[threadNumber] = constVector.data();
}

template<typename T> __global__
void kernel_checkVectorAccessors(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> srcVectorNonConst,
	ecuda::vector<T> destVector,
	ecuda::vector<T> srcFronts,
	ecuda::vector<T> srcBacks,
	ecuda::vector<T> srcFrontsNonConst,
	ecuda::vector<T> srcBacksNonConst
)
{
	const int threadNumber = threadIdx.x;
	destVector[threadNumber] = srcVector[threadNumber];
	srcFronts[threadNumber] = srcVector.front();
	srcBacks[threadNumber] = srcVector.back();
	srcFrontsNonConst[threadNumber] = srcVectorNonConst.front();
	srcBacksNonConst[threadNumber] = srcVectorNonConst.back();
}

template<typename T> __global__
void kernel_checkDeviceIterators(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> destVector
)
{
	typename ecuda::vector<T>::const_iterator srcIterator = srcVector.begin();
	typename ecuda::vector<T>::iterator destIterator = destVector.begin();
	for( ; srcIterator != srcVector.end() and destIterator != destVector.end(); ++srcIterator, ++destIterator )
		*destIterator = *srcIterator;
}

template<typename T> __global__
void kernel_checkHostIterators(
	typename ecuda::vector<T>::const_iterator srcBegin,
	typename ecuda::vector<T>::const_iterator srcEnd,
	typename ecuda::vector<T>::iterator destBegin,
	typename ecuda::vector<T>::iterator destEnd
)
{
	for( ; srcBegin != srcEnd and destBegin != destEnd; ++srcBegin, ++destBegin )
		*destBegin = *srcBegin;
}

template<typename T> __global__
void kernel_checkDeviceReverseIterators(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> destVector
)
{
	typename ecuda::vector<T>::const_reverse_iterator srcIterator = srcVector.rbegin();
	typename ecuda::vector<T>::reverse_iterator destIterator = destVector.rbegin();
	for( ; srcIterator != srcVector.rend() and destIterator != destVector.rend(); ++srcIterator, ++destIterator )
		*destIterator = *srcIterator;
}

template<typename T> __global__
void kernel_checkHostReverseIterators(
	typename ecuda::vector<T>::const_reverse_iterator srcBegin,
	typename ecuda::vector<T>::const_reverse_iterator srcEnd,
	typename ecuda::vector<T>::reverse_iterator destBegin,
	typename ecuda::vector<T>::reverse_iterator destEnd
)
{
	for( ; srcBegin != srcEnd and destBegin != destEnd; ++srcBegin, ++destBegin ) *destBegin = *srcBegin;
}

template<typename T> __global__
void kernel_testSwapAndClear(
	ecuda::vector<T> vector1,
	ecuda::vector<T> vector2,
	ecuda::vector<T> dummyVector,
	ecuda::array<int,2> array
)
{
	dummyVector.clear();
	if( dummyVector.empty() ) array[0] = 1;
	T oldStart1 = vector1.front();
	T oldStart2 = vector2.front();
	vector1.swap( vector2 );
	if( vector2.front() == oldStart1 and vector1.front() == oldStart2 ) array[1] = 1;
}

template<typename T> __global__
void kernel_testComparisonOperators(
	const ecuda::vector<T> vector1,
	const ecuda::vector<T> vector2,
	ecuda::vector<int> results
)
{
	results[0] = vector1 == vector2 ? 0 : 1;
	results[1] = vector1 != vector2 ? 1 : 0;
	results[2] = vector1 < vector2 ? 1 : 0;
	results[3] = vector1 > vector2 ? 0 : 1;
	results[4] = vector1 <= vector2 ? 1 : 0;
	results[5] = vector1 >= vector2 ? 0 : 1;
	results[6] = vector2 < vector1 ? 0 : 1;
	results[7] = vector2 > vector1 ? 1 : 0;
	results[8] = vector2 <= vector1 ? 0 : 1;
	results[9] = vector2 >= vector1 ? 1 : 0;
}

int main( int argc, char* argv[] ) {

	std::cout << "Testing ecuda::vector..." << std::endl;

	std::vector<int> testResults;

	//
	// Test 1: default constructor, copy to host, and general info
	//
	std::cerr << "Test 1" << std::endl;
	{
		bool passed = true;
		{
			ecuda::vector<int> deviceVector;
			if( deviceVector.size() ) passed = false;
			if( !deviceVector.empty() ) passed = false;
		}
		{
			const ecuda::vector<int> deviceVector( 100 );
			if( deviceVector.size() != 100 ) passed = false;
			if( deviceVector.empty() ) passed = false;
			if( !deviceVector.data() ) passed = false;
			std::vector<int> hostVector;
			deviceVector >> hostVector;
			if( hostVector.size() != 100 ) passed = false;
			for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) if( hostVector[i] ) passed = false;
		}
		ecuda::vector<int> deviceVector( 100, 3 );
		if( deviceVector.size() != 100 ) passed = false;
		if( deviceVector.empty() ) passed = false;
		if( !deviceVector.data() ) passed = false;
		std::vector<int> hostVector;
		deviceVector >> hostVector;
		if( hostVector.size() != 100 ) passed = false;
		for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) if( hostVector[i] != 3 ) passed = false;
		testResults.push_back( passed ? 1 : 0 );
	}

	//
	// Test 2: information is correct on device
	//
	std::cerr << "Test 2" << std::endl;
	{
		std::vector<int> hostVector( 100 );
		for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) hostVector[i] = i;
		ecuda::vector<int> deviceVector( hostVector.begin(), hostVector.end() );
		ecuda::vector<int> deviceEmpties( 100, -1 );
		ecuda::vector<ecuda::vector<int>::size_type> deviceSizes( 100 );
		ecuda::vector<ecuda::vector<int>::pointer> devicePointers( 100 );
		//ecuda::vector<ecuda::vector<int>::const_pointer> deviceConstPointers( 100 );
		kernel_checkVectorProperties<<<1,100>>>( deviceVector, deviceVector, deviceEmpties, deviceSizes, devicePointers ); //, deviceConstPointers );
		CUDA_CHECK_ERRORS();
		CUDA_CALL( cudaDeviceSynchronize() );
		std::vector<int> hostEmpties( 100, -1 );
		std::vector<ecuda::vector<int>::size_type> hostSizes( 100 );
		std::vector<ecuda::vector<int>::pointer> hostPointers( 100 );
		//std::vector<ecuda::vector<int>::const_pointer> hostConstPointers( 100 );
		deviceEmpties >> hostEmpties;
		deviceSizes >> hostSizes;
		devicePointers >> hostPointers;
		//deviceConstPointers >> hostConstPointers;
		bool passed = true;<commit_msg>tweaking vector<commit_after>#include <algorithm>
#include <iostream>
#include <string>
#include <cstdio>
#include "../include/ecuda/array.hpp"
#include "../include/ecuda/vector.hpp"

template<typename T> __global__
void kernel_checkVectorProperties(
	const ecuda::vector<T> constVector,
	ecuda::vector<T> vector,
	ecuda::vector<T> empties,
	ecuda::vector<typename ecuda::vector<T>::size_type> sizes,
	ecuda::vector<typename ecuda::vector<T>::pointer> pointers//,
//	ecuda::vector<typename ecuda::vector<T>::const_pointer> constPointers
)
{
	const int threadNumber = threadIdx.x;
	empties[threadNumber] = constVector.empty() ? 1 : 0;
	sizes[threadNumber] = constVector.size();
	pointers[threadNumber] = vector.data();
	//constPointers[threadNumber] = constVector.data();
}

template<typename T> __global__
void kernel_checkVectorAccessors(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> srcVectorNonConst,
	ecuda::vector<T> destVector,
	ecuda::vector<T> srcFronts,
	ecuda::vector<T> srcBacks,
	ecuda::vector<T> srcFrontsNonConst,
	ecuda::vector<T> srcBacksNonConst
)
{
	const int threadNumber = threadIdx.x;
	destVector[threadNumber] = srcVector[threadNumber];
	srcFronts[threadNumber] = srcVector.front();
	srcBacks[threadNumber] = srcVector.back();
	srcFrontsNonConst[threadNumber] = srcVectorNonConst.front();
	srcBacksNonConst[threadNumber] = srcVectorNonConst.back();
}

template<typename T> __global__
void kernel_checkDeviceIterators(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> destVector
)
{
	typename ecuda::vector<T>::const_iterator srcIterator = srcVector.begin();
	typename ecuda::vector<T>::iterator destIterator = destVector.begin();
	for( ; srcIterator != srcVector.end() and destIterator != destVector.end(); ++srcIterator, ++destIterator )
		*destIterator = *srcIterator;
}

template<typename T> __global__
void kernel_checkHostIterators(
	typename ecuda::vector<T>::const_iterator srcBegin,
	typename ecuda::vector<T>::const_iterator srcEnd,
	typename ecuda::vector<T>::iterator destBegin,
	typename ecuda::vector<T>::iterator destEnd
)
{
	for( ; srcBegin != srcEnd and destBegin != destEnd; ++srcBegin, ++destBegin )
		*destBegin = *srcBegin;
}

template<typename T> __global__
void kernel_checkDeviceReverseIterators(
	const ecuda::vector<T> srcVector,
	ecuda::vector<T> destVector
)
{
	typename ecuda::vector<T>::const_reverse_iterator srcIterator = srcVector.rbegin();
	typename ecuda::vector<T>::reverse_iterator destIterator = destVector.rbegin();
	for( ; srcIterator != srcVector.rend() and destIterator != destVector.rend(); ++srcIterator, ++destIterator )
		*destIterator = *srcIterator;
}

template<typename T> __global__
void kernel_checkHostReverseIterators(
	typename ecuda::vector<T>::const_reverse_iterator srcBegin,
	typename ecuda::vector<T>::const_reverse_iterator srcEnd,
	typename ecuda::vector<T>::reverse_iterator destBegin,
	typename ecuda::vector<T>::reverse_iterator destEnd
)
{
	for( ; srcBegin != srcEnd and destBegin != destEnd; ++srcBegin, ++destBegin ) *destBegin = *srcBegin;
}

template<typename T> __global__
void kernel_testSwapAndClear(
	ecuda::vector<T> vector1,
	ecuda::vector<T> vector2,
	ecuda::vector<T> dummyVector,
	ecuda::array<int,2> array
)
{
	dummyVector.clear();
	if( dummyVector.empty() ) array[0] = 1;
	T oldStart1 = vector1.front();
	T oldStart2 = vector2.front();
	vector1.swap( vector2 );
	if( vector2.front() == oldStart1 and vector1.front() == oldStart2 ) array[1] = 1;
}

template<typename T> __global__
void kernel_testComparisonOperators(
	const ecuda::vector<T> vector1,
	const ecuda::vector<T> vector2,
	ecuda::vector<int> results
)
{
	results[0] = vector1 == vector2 ? 0 : 1;
	results[1] = vector1 != vector2 ? 1 : 0;
	results[2] = vector1 < vector2 ? 1 : 0;
	results[3] = vector1 > vector2 ? 0 : 1;
	results[4] = vector1 <= vector2 ? 1 : 0;
	results[5] = vector1 >= vector2 ? 0 : 1;
	results[6] = vector2 < vector1 ? 0 : 1;
	results[7] = vector2 > vector1 ? 1 : 0;
	results[8] = vector2 <= vector1 ? 0 : 1;
	results[9] = vector2 >= vector1 ? 1 : 0;
}

int main( int argc, char* argv[] ) {

	std::cout << "Testing ecuda::vector..." << std::endl;

	std::vector<int> testResults;

	//
	// Test 1: default constructor, copy to host, and general info
	//
	std::cerr << "Test 1" << std::endl;
	{
		bool passed = true;
		{
			ecuda::vector<int> deviceVector;
			if( deviceVector.size() ) passed = false;
			if( !deviceVector.empty() ) passed = false;
		}
		{
			const ecuda::vector<int> deviceVector( 100 );
			if( deviceVector.size() != 100 ) passed = false;
			if( deviceVector.empty() ) passed = false;
			if( !deviceVector.data() ) passed = false;
			std::vector<int> hostVector( deviceVector.size() );
			deviceVector >> hostVector;
			if( hostVector.size() != 100 ) passed = false;
			for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) if( hostVector[i] ) passed = false;
		}
		ecuda::vector<int> deviceVector( 100, 3 );
		if( deviceVector.size() != 100 ) passed = false;
		if( deviceVector.empty() ) passed = false;
		if( !deviceVector.data() ) passed = false;
		std::vector<int> hostVector( deviceVector.size() );
		deviceVector >> hostVector;
		if( hostVector.size() != 100 ) passed = false;
		for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) if( hostVector[i] != 3 ) passed = false;
		testResults.push_back( passed ? 1 : 0 );
	}

	//
	// Test 2: information is correct on device
	//
	std::cerr << "Test 2" << std::endl;
	{
		std::vector<int> hostVector( 100 );
		for( std::vector<int>::size_type i = 0; i < hostVector.size(); ++i ) hostVector[i] = i;
		ecuda::vector<int> deviceVector( hostVector.begin(), hostVector.end() );
		ecuda::vector<int> deviceEmpties( 100, -1 );
		ecuda::vector<ecuda::vector<int>::size_type> deviceSizes( 100 );
		ecuda::vector<ecuda::vector<int>::pointer> devicePointers( 100 );
		//ecuda::vector<ecuda::vector<int>::const_pointer> deviceConstPointers( 100 );
		kernel_checkVectorProperties<<<1,100>>>( deviceVector, deviceVector, deviceEmpties, deviceSizes, devicePointers ); //, deviceConstPointers );
		CUDA_CHECK_ERRORS();
		CUDA_CALL( cudaDeviceSynchronize() );
		std::vector<int> hostEmpties( 100, -1 );
		std::vector<ecuda::vector<int>::size_type> hostSizes( 100 );
		std::vector<ecuda::vector<int>::pointer> hostPointers( 100 );
		//std::vector<ecuda::vector<int>::const_pointer> hostConstPointers( 100 );
		deviceEmpties >> hostEmpties;
		deviceSizes >> hostSizes;
		devicePointers >> hostPointers;
		//deviceConstPointers >> hostConstPointers;
		bool passed = true;
{'fraction_non_alphanumeric': 0.15699815837937384, 'fraction_numerical': 0.020411295273173726, 'mean_word_length': 5.773908523908524, 'pattern_counts': {'":': 0, '<': 199, '<?xml version=': 0, '>': 193, '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': '7179021', 'n_tokens_mistral': 4750, 'n_tokens_neox': 4438, 'n_words': 962}