diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5cafa245f62def8f5c70372d06fcbe771af24f6a..c47898bd369acb9aac3aede2d57cab2b7d6856fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,10 @@ default: image: "archlinux/devel-tnl:latest" tags: - docker + retry: + max: 2 + when: + - runner_system_failure stages: - build diff --git a/src/TNL/Algorithms/MultiDeviceMemoryOperations.h b/src/TNL/Algorithms/MultiDeviceMemoryOperations.h index ef76a72eb005289ff7b495613131fec5f461fa54..4338be51f773c8f950bfea3ae7fb9dbbd9de327a 100644 --- a/src/TNL/Algorithms/MultiDeviceMemoryOperations.h +++ b/src/TNL/Algorithms/MultiDeviceMemoryOperations.h @@ -7,6 +7,7 @@ #pragma once #include <TNL/Algorithms/MemoryOperations.h> +#include <TNL/Cuda/LaunchHelpers.h> // getTransferBufferSize namespace TNL { namespace Algorithms { diff --git a/src/TNL/Exceptions/CudaRuntimeError.h b/src/TNL/Exceptions/CudaRuntimeError.h index b1c9eaf8678bc40e6f37e5d7e1dc61b96dca6ffd..797d1874f01ae96b1ecf93bab79163f9db194aa6 100644 --- a/src/TNL/Exceptions/CudaRuntimeError.h +++ b/src/TNL/Exceptions/CudaRuntimeError.h @@ -38,7 +38,7 @@ public: CudaRuntimeError( CudaStatusType error_code, const char* file_name, int line ) : std::runtime_error( "CUDA ERROR " + std::to_string( (int) error_code ) + " (" + name( error_code ) + "): " + description( error_code ) + ".\nSource: line " + std::to_string( line ) - + " in " + file_name + ": " + description( error_code ) ), + + " in " + file_name ), code_(error_code) {} diff --git a/src/TNL/Images/DicomHeader.h b/src/TNL/Images/DicomHeader.h index 009d29919594c03505a23447b2ef18b7455731cb..44905b1dff574fb9c0bdb3a12d54fe2ea33ed6df 100644 --- a/src/TNL/Images/DicomHeader.h +++ b/src/TNL/Images/DicomHeader.h @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT -#pragma once +#pragma once #ifdef HAVE_DCMTK_H #define HAVE_CONFIG_H @@ -27,40 +27,39 @@ class DicomImageInfo; class DicomHeader { public: - + inline DicomHeader(); - + inline virtual ~DicomHeader(); #ifdef HAVE_DCMTK_H inline DcmFileFormat &getFileFormat(); #endif - + inline DicomImageInfo &getImageInfo(); - + inline DicomPatientInfo &getPatientInfo(); - + inline DicomSeriesInfo &getSeriesInfo(); inline bool loadFromFile( const String& fileName ); protected: - + DicomImageInfo *imageInfoObj; - + DicomPatientInfo *patientInfoObj; - + DicomSeriesInfo *seriesInfoObj; #ifdef HAVE_DCMTK_H DcmFileFormat *fileFormat; #endif - + bool isLoaded; }; } // namespace Images } // namespace TNL -#include <TNL/Images//DicomHeader_impl.h> - +#include <TNL/Images/DicomHeader_impl.h> diff --git a/src/TNL/Images/DicomHeader_impl.h b/src/TNL/Images/DicomHeader_impl.h index 59e30aa24aa8109dbea56f3dfbbe55b03a61e4c3..13257439c8b1188358c0d37887c7dbfab7547bb5 100644 --- a/src/TNL/Images/DicomHeader_impl.h +++ b/src/TNL/Images/DicomHeader_impl.h @@ -6,10 +6,10 @@ #pragma once -#include <TNL/Images//DicomHeader.h> -#include <TNL/Images//DicomSeriesInfo.h> -#include <TNL/Images//DicomPatientInfo.h> -#include <TNL/Images//DicomImageInfo.h> +#include <TNL/Images/DicomHeader.h> +#include <TNL/Images/DicomImageInfo.h> +#include <TNL/Images/DicomPatientInfo.h> +#include <TNL/Images/DicomSeriesInfo.h> namespace TNL { namespace Images { diff --git a/src/TNL/Images/DicomImageInfo.h b/src/TNL/Images/DicomImageInfo.h index c8820503279edceee23758d3fbb4bd76a528da2c..0b6362830fa7c097280f53b8e469de016e937486 100644 --- a/src/TNL/Images/DicomImageInfo.h +++ b/src/TNL/Images/DicomImageInfo.h @@ -13,7 +13,7 @@ #endif namespace TNL { -namespace Images { +namespace Images { class DicomHeader; @@ -44,48 +44,47 @@ struct PixelSpacing class DicomImageInfo { public: - + inline DicomImageInfo( DicomHeader &DicomHeader); - + inline virtual ~DicomImageInfo(); inline ImagePositionToPatient getImagePositionToPatient(); - + inline ImageOrientationToPatient getImageOrientationToPatient(); - + inline double getSliceThickness(); - + inline double getSliceLocation(); - + inline PixelSpacing getPixelSpacing(); - + inline int getNumberOfSlices(); private: - + DicomHeader &dicomHeader; - + bool retrieveInfo(); - + bool isObjectRetrieved; double sliceLocation; - + double sliceThickness; - + ImagePositionToPatient imagePositionToPatient; - + ImageOrientationToPatient imageOrientationToPatient; - + PixelSpacing pixelSpacing; - + int numberOfSlices; - + int width, height, depth; }; } // namespace Images } // namespace TNL -#include <TNL/Images//DicomImageInfo_impl.h> - +#include <TNL/Images/DicomImageInfo_impl.h> diff --git a/src/TNL/Images/DicomImageInfo_impl.h b/src/TNL/Images/DicomImageInfo_impl.h index 67ce1c7e7559a238511746c5085b3d1251ac19b3..6c709c16618fb4e4ca1d1842ff91acd0217ed4d5 100644 --- a/src/TNL/Images/DicomImageInfo_impl.h +++ b/src/TNL/Images/DicomImageInfo_impl.h @@ -6,11 +6,11 @@ #pragma once -#include <TNL/Images//DicomImageInfo.h> -#include <TNL/Images//DicomHeader.h> +#include <TNL/Images/DicomHeader.h> +#include <TNL/Images/DicomImageInfo.h> namespace TNL { -namespace Images { +namespace Images { inline DicomImageInfo::DicomImageInfo( DicomHeader& dicomHeader ) : dicomHeader( dicomHeader ) diff --git a/src/TNL/Images/DicomPatientInfo.h b/src/TNL/Images/DicomPatientInfo.h index 3c83da47e6980442f110b71c4f9894d77f57463b..73894bbc08c7cb4976e1d6898cf65ac6137c48ec 100644 --- a/src/TNL/Images/DicomPatientInfo.h +++ b/src/TNL/Images/DicomPatientInfo.h @@ -17,7 +17,7 @@ #endif namespace TNL { -namespace Images { +namespace Images { class DicomHeader; @@ -28,21 +28,21 @@ class DicomHeader; class DicomPatientInfo { public: - + inline DicomPatientInfo(DicomHeader &aDicomHeader); - + inline virtual ~DicomPatientInfo(); inline const String& getName(); - + inline const String& getSex(); - + inline const String& getID(); - + inline const String& getWeight(); - + inline const String& getPosition(); - + inline const String& getOrientation(); private: @@ -67,5 +67,4 @@ class DicomPatientInfo } // namespace Images } // namespace TNL -#include <TNL/Images//DicomPatientInfo_impl.h> - +#include <TNL/Images/DicomPatientInfo_impl.h> diff --git a/src/TNL/Images/DicomSeries.h b/src/TNL/Images/DicomSeries.h index f02930a5334a37fe4f2662582932d10c36fc2247..f6005751ac31a8466fa45a929452db1edbdff9f1 100644 --- a/src/TNL/Images/DicomSeries.h +++ b/src/TNL/Images/DicomSeries.h @@ -11,11 +11,12 @@ #include <TNL/Containers/Array.h> #include <TNL/String.h> #include <TNL/TypeInfo.h> -#include <TNL/Images//Image.h> -#include <TNL/Images//DicomHeader.h> -#include <TNL/Images//RegionOfInterest.h> #include <TNL/Meshes/Grid.h> +#include <TNL/Images/DicomHeader.h> +#include <TNL/Images/Image.h> +#include <TNL/Images/RegionOfInterest.h> + #ifdef HAVE_DCMTK_H #define USING_STD_NAMESPACE #include <dcmtk/config/osconfig.h> @@ -49,15 +50,15 @@ struct ImagesInfo class DicomSeries : public Image< int > { public: - + typedef int IndexType; - + inline DicomSeries( const String& filePath ); - + inline virtual ~DicomSeries(); inline int getImagesCount(); - + template< typename Real, typename Device, typename Index, @@ -66,52 +67,51 @@ class DicomSeries : public Image< int > const Meshes::Grid< 2, Real, Device, Index >& grid, const RegionOfInterest< int > roi, Vector& vector ); - + #ifdef HAVE_DCMTK_H inline const Uint16 *getData( int imageNumber = 0 ); #endif - + inline int getColorCount(); - + inline int getBitsPerSampleCount(); - + inline int getMinColorValue(); - + inline WindowCenterWidth getWindowDefaults(); - + inline int getMaxColorValue(); - + inline void freeData(); - + inline DicomHeader &getHeader(int image); - + inline bool isDicomSeriesLoaded(); private: - + bool loadDicomSeries( const String& filePath ); - + bool retrieveFileList( const String& filePath ); - + bool loadImage( const String& filePath, int number ); std::list< String > fileList; - + Containers::Array<DicomHeader *,Devices::Host,int> dicomSeriesHeaders; bool isLoaded; - + #ifdef HAVE_DCMTK_H DicomImage *dicomImage; - + Uint16 *pixelData; #endif - + ImagesInfo imagesInfo; }; } // namespace Images } // namespace TNL -#include <TNL/Images//DicomSeries_impl.h> - +#include <TNL/Images/DicomSeries_impl.h> diff --git a/src/TNL/Images/DicomSeriesInfo.h b/src/TNL/Images/DicomSeriesInfo.h index 312a40299847b18cc28e09f427f9b7748452968c..c630b299e38deafa1ba5a302e139ed4e6cada1db 100644 --- a/src/TNL/Images/DicomSeriesInfo.h +++ b/src/TNL/Images/DicomSeriesInfo.h @@ -17,7 +17,7 @@ #endif namespace TNL { -namespace Images { +namespace Images { class DicomHeader; @@ -28,41 +28,41 @@ class DicomHeader; class DicomSeriesInfo { public: - + inline DicomSeriesInfo( DicomHeader &dicomHeader ); - + inline virtual ~DicomSeriesInfo(); inline const String& getModality(); - + inline const String& getStudyInstanceUID(); - + inline const String& getSeriesInstanceUID(); - + inline const String& getSeriesDescription(); - + inline const String& getSeriesNumber(); - + inline const String& getSeriesDate(); - + inline const String& getSeriesTime(); - + inline const String& getPerformingPhysiciansName(); - + inline const String& getPerformingPhysicianIdentificationSequence(); - + inline const String& getOperatorsName(); - + inline const String& getOperatorIdentificationSequence(); - + inline const String& getAcquisitionTime(); - + private: - + DicomHeader &dicomHeader; - + bool retrieveInfo(); - + bool isObjectRetrieved; String modality; @@ -101,5 +101,4 @@ class DicomSeriesInfo } // namespace Images } // namespace TNL -#include <TNL/Images//DicomSeriesInfo_impl.h> - +#include <TNL/Images/DicomSeriesInfo_impl.h> diff --git a/src/TNL/Images/DicomSeriesInfo_impl.h b/src/TNL/Images/DicomSeriesInfo_impl.h index 34648101894027f8f8afd2705f7526a8f62acfc1..6a90666ec7a1e94280a64f828260d1288cb39ca8 100644 --- a/src/TNL/Images/DicomSeriesInfo_impl.h +++ b/src/TNL/Images/DicomSeriesInfo_impl.h @@ -6,12 +6,13 @@ #pragma once -#include <TNL/Images//DicomSeriesInfo.h> -#include <TNL/Images//DicomHeader.h> #include <stdio.h> +#include <TNL/Images/DicomHeader.h> +#include <TNL/Images/DicomSeriesInfo.h> + namespace TNL { -namespace Images { +namespace Images { inline DicomSeriesInfo::DicomSeriesInfo( DicomHeader &dicomHeader) : dicomHeader( dicomHeader ) @@ -29,49 +30,49 @@ inline bool DicomSeriesInfo::retrieveInfo() OFString str; dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_Modality, str ); this->modality = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_StudyInstanceUID, str ); this->studyInstanceUID = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_SeriesInstanceUID, str ); this->seriesInstanceUID = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_SeriesNumber, str ); this->seriesNumber = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_SeriesDescription, str ); this->seriesDescription = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_SeriesDate, str ); this->seriesDate = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_SeriesTime, str ); this->seriesTime = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_PerformingPhysicianName, str ); this->performingPhysiciansName = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_PerformingPhysicianIdentificationSequence, str ); this->performingPhysicianIdentificationSequence = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_OperatorsName, str ); this->operatorsName = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_OperatorIdentificationSequence, str ); this->operatorIdentificationSequence = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_FrameAcquisitionDuration, str ); this->frameTime = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_FrameAcquisitionDateTime, str ); this->faDateTime = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_FrameReferenceTime, str ); this->faRefTime = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_ActualFrameDuration, str ); this->AFD = str.data(); - + dicomHeader.getFileFormat().getDataset()->findAndGetOFString( DCM_AcquisitionTime, str ); this->acquisitionTime = str.data(); diff --git a/src/TNL/Images/DicomSeries_impl.h b/src/TNL/Images/DicomSeries_impl.h index a90c5c93696242895737254f7006180b7d36a6ea..b6253a5baaa23f5c036806438823f9cbac508b51 100644 --- a/src/TNL/Images/DicomSeries_impl.h +++ b/src/TNL/Images/DicomSeries_impl.h @@ -6,12 +6,13 @@ #pragma once -#include <TNL/Images//DicomSeries.h> -#include <TNL/Images//DicomSeriesInfo.h> #include <dirent.h> +#include <TNL/Images/DicomSeries.h> +#include <TNL/Images/DicomSeriesInfo.h> + namespace TNL { -namespace Images { +namespace Images { int findLastIndexOf(String &str, const char* c) { @@ -83,7 +84,7 @@ getImage( const int imageIdx, const Uint16* imageData = this->getData( imageIdx ); typedef Meshes::Grid< 2, Real, Device, Index > GridType; typename GridType::Cell cell( grid ); - + Index i, j; int position( 0 ); for( i = 0; i < this->height; i ++ ) diff --git a/src/TNL/Images/JPEGImage.h b/src/TNL/Images/JPEGImage.h index 92b64468e34ca6807081fe362f611b1561ae7984..ce08b43b186078c39bce20eb95e34daf30bd9f2d 100644 --- a/src/TNL/Images/JPEGImage.h +++ b/src/TNL/Images/JPEGImage.h @@ -23,56 +23,56 @@ struct my_error_mgr #endif namespace TNL { -namespace Images { +namespace Images { template< typename Index = int > class JPEGImage : public Image< Index > { public: - + typedef Index IndexType; - + JPEGImage(); - + bool openForRead( const String& fileName ); - + template< typename MeshReal, typename Device, typename Real > bool read( const RegionOfInterest< Index > roi, Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - - + + template< typename Real, typename Device > bool openForWrite( const String& fileName, Meshes::Grid< 2, Real, Device, Index >& grid ); - + // TODO: Obsolete template< typename Real, typename Device, typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); - + template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - - + + void close(); - + ~JPEGImage(); - + protected: - + bool readHeader(); - + template< typename Real, typename Device > bool writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid ); - + FILE* file; bool fileOpen; @@ -89,5 +89,4 @@ class JPEGImage : public Image< Index > } // namespace Images } // namespace TNL -#include <TNL/Images//JPEGImage_impl.h> - +#include <TNL/Images/JPEGImage_impl.h> diff --git a/src/TNL/Images/JPEGImage_impl.h b/src/TNL/Images/JPEGImage_impl.h index 7b89d5d0ca863bb2537fc43567b1365b16502851..cc94c1f7cbc0886a9c3f4cb0c0e52b7df2f431d7 100644 --- a/src/TNL/Images/JPEGImage_impl.h +++ b/src/TNL/Images/JPEGImage_impl.h @@ -6,11 +6,12 @@ #pragma once -#include <TNL/Images//JPEGImage.h> #include <setjmp.h> +#include <TNL/Images/JPEGImage.h> + namespace TNL { -namespace Images { +namespace Images { #ifdef HAVE_JPEG_H inline void my_error_exit( j_common_ptr cinfo ) @@ -42,7 +43,7 @@ readHeader() #ifdef HAVE_JPEG_H this->decinfo.err = jpeg_std_error(&jerr.pub); this->jerr.pub.error_exit = my_error_exit; - + /*** * Prepare the long jump back from libjpeg. */ @@ -55,7 +56,7 @@ readHeader() jpeg_destroy_decompress( &this->decinfo ); return false; } - + jpeg_create_decompress( &this->decinfo ); jpeg_stdio_src( &this->decinfo, this->file ); if( jpeg_read_header( &this->decinfo, true ) != JPEG_HEADER_OK ) @@ -103,7 +104,7 @@ read( const RegionOfInterest< Index > roi, typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); - + /*** * Prepare the long jump back from libjpeg. */ @@ -116,14 +117,14 @@ read( const RegionOfInterest< Index > roi, jpeg_destroy_decompress( &this->decinfo ); return false; } - + jpeg_start_decompress( &this->decinfo ); int row_stride = this->decinfo.output_width * this->decinfo.output_components; JSAMPARRAY row = ( *( this->decinfo.mem->alloc_sarray ) )( ( j_common_ptr ) &this->decinfo, JPOOL_IMAGE, row_stride, - 1 ); - + 1 ); + Index i( 0 ), j; while( this->decinfo.output_scanline < this->decinfo.output_height) { @@ -132,7 +133,7 @@ read( const RegionOfInterest< Index > roi, { if( !roi.isIn( i, j ) ) continue; - + cell.getCoordinates().x() = j - roi.getLeft(); cell.getCoordinates().y() = roi.getBottom() - 1 - i; //Index cellIndex = grid.getCellIndex( CoordinatesType( j - roi.getLeft(), @@ -296,7 +297,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > return true; #else return false; -#endif +#endif } diff --git a/src/TNL/Images/PGMImage.h b/src/TNL/Images/PGMImage.h index baad1e299d94af3da75c71b1096a4a63ccbb9e97..e8a6adc4b09567bfedd2f16ecfcdd54933490393 100644 --- a/src/TNL/Images/PGMImage.h +++ b/src/TNL/Images/PGMImage.h @@ -4,33 +4,35 @@ // // SPDX-License-Identifier: MIT -#pragma once +#pragma once -#include <TNL/String.h> -#include <TNL/Images//Image.h> -#include <TNL/Images//RegionOfInterest.h> #include <fstream> +#include <TNL/String.h> + +#include <TNL/Images/Image.h> +#include <TNL/Images/RegionOfInterest.h> + namespace TNL { -namespace Images { +namespace Images { template< typename Index = int > class PGMImage : public Image< Index > { public: - + typedef Index IndexType; - + PGMImage(); - + bool openForRead( const String& fileName ); - + template< typename MeshReal, typename Device, typename Real > bool read( const RegionOfInterest< Index > roi, Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - + template< typename Real, typename Device > bool openForWrite( const String& fileName, @@ -43,37 +45,35 @@ class PGMImage : public Image< Index > typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); - + template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - + void close(); - + ~PGMImage(); - + protected: - + bool readHeader(); - + template< typename Real, typename Device > bool writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid, bool binary ); - + bool binary; - + IndexType maxColors; - + std::fstream file; - + bool fileOpen; }; } // namespace Images } // namespace TNL -#include <TNL/Images//PGMImage_impl.h> - - +#include <TNL/Images/PGMImage_impl.h> diff --git a/src/TNL/Images/PGMImage_impl.h b/src/TNL/Images/PGMImage_impl.h index d3023d4dd363bb3b22966bcc42f40ee230baab9d..7dc64823392f24910ac25d2231da9fd193de8fed 100644 --- a/src/TNL/Images/PGMImage_impl.h +++ b/src/TNL/Images/PGMImage_impl.h @@ -4,13 +4,14 @@ // // SPDX-License-Identifier: MIT -#pragma once +#pragma once #include <cstring> -#include <TNL/Images//PGMImage.h> + +#include <TNL/Images/PGMImage.h> namespace TNL { -namespace Images { +namespace Images { template< typename Index > PGMImage< Index >:: @@ -34,7 +35,7 @@ readHeader() if( magicNumber != "P5" && magicNumber != "P2" ) return false; - + if( magicNumber == "P5" ) this->binary = true; @@ -48,7 +49,7 @@ readHeader() this->file.get( character ); } this->file.unget(); - + this->file >> this->width >> this->height >> this->maxColors; return true; } @@ -164,7 +165,7 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, { typedef Meshes::Grid< 2, Real, Device, Index > GridType; typename GridType::Cell cell( grid ); - + Index i, j; for( i = 0; i < grid.getDimensions().y(); i ++ ) { @@ -173,7 +174,7 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; cell.refresh(); - + //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); @@ -185,7 +186,7 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, this->file << ' '; } else this->file << color; - } + } if ( ! this->binary ) this->file << '\n'; } @@ -203,7 +204,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); - + Index i, j; for( i = 0; i < grid.getDimensions().y(); i ++ ) { @@ -212,7 +213,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > cell.getCoordinates().x() = j; cell.getCoordinates().y() = grid.getDimensions().y() - 1 - i; cell.refresh(); - + //Index cellIndex = grid.getCellIndex( CoordinatesType( j, // grid.getDimensions().y() - 1 - i ) ); @@ -224,7 +225,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > this->file << ' '; } else this->file << color; - } + } if ( ! this->binary ) this->file << '\n'; } diff --git a/src/TNL/Images/PNGImage.h b/src/TNL/Images/PNGImage.h index ec03126f9abc9efce0eccd80b30a181671f70734..16ae7a0ebaadda432b19fbf1b132e58d38924834 100644 --- a/src/TNL/Images/PNGImage.h +++ b/src/TNL/Images/PNGImage.h @@ -16,25 +16,25 @@ #include <TNL/Functions/MeshFunction.h> namespace TNL { -namespace Images { +namespace Images { template< typename Index = int > class PNGImage : public Image< Index > { public: - + using IndexType = Index; - + PNGImage(); - + bool openForRead( const String& fileName ); - + template< typename MeshReal, typename Device, typename Real > bool read( const RegionOfInterest< Index > roi, Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - + template< typename Real, typename Device > bool openForWrite( const String& fileName, @@ -46,25 +46,25 @@ class PNGImage : public Image< Index > typename Vector > bool write( const Meshes::Grid< 2, Real, Device, Index >& grid, Vector& vector ); - + template< typename MeshReal, typename Device, typename Real > bool write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index >, 2, Real >& function ); - - + + void close(); - + ~PNGImage(); - + protected: - + bool readHeader(); - + template< typename Real, typename Device > bool writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid ); - + FILE* file; bool fileOpen; @@ -73,7 +73,7 @@ class PNGImage : public Image< Index > png_structp png_ptr; png_infop info_ptr, end_info; - + png_byte color_type, bit_depth; #endif }; @@ -81,5 +81,4 @@ class PNGImage : public Image< Index > } // namespace Images } // namespace TNL -#include <TNL/Images//PNGImage_impl.h> - +#include <TNL/Images/PNGImage_impl.h> diff --git a/src/TNL/Images/PNGImage_impl.h b/src/TNL/Images/PNGImage_impl.h index 3f1140e4f09baa43eb187e1af0c16827c5685438..b75528ee651218eba2d1fe300aa2fface630d5dd 100644 --- a/src/TNL/Images/PNGImage_impl.h +++ b/src/TNL/Images/PNGImage_impl.h @@ -4,12 +4,12 @@ // // SPDX-License-Identifier: MIT -#pragma once +#pragma once -#include <TNL/Images//PNGImage.h> +#include <TNL/Images/PNGImage.h> namespace TNL { -namespace Images { +namespace Images { template< typename Index > PNGImage< Index >:: @@ -37,7 +37,7 @@ readHeader() bool isPNG = !png_sig_cmp( header, 0, headerSize ); if( ! isPNG ) return false; - + /**** * Allocate necessary memory */ @@ -78,7 +78,7 @@ readHeader() } png_init_io( this->png_ptr, this->file ); png_set_sig_bytes( this->png_ptr, headerSize ); - + /**** * Read the header */ @@ -126,7 +126,7 @@ read( const RegionOfInterest< Index > roi, typedef Meshes::Grid< 2, MeshReal, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); - + /*** * Prepare the long jump back from libpng. */ @@ -137,9 +137,9 @@ read( const RegionOfInterest< Index > roi, &this->end_info ); return false; } - + png_bytepp row_pointers = png_get_rows( this->png_ptr, this->info_ptr ); - + Index i, j; for( i = 0; i < this->height; i ++ ) { @@ -147,7 +147,7 @@ read( const RegionOfInterest< Index > roi, { if( !roi.isIn( i, j ) ) continue; - + cell.getCoordinates().x() = j - roi.getLeft(); cell.getCoordinates().y() = roi.getBottom() - 1 - i; cell.refresh(); @@ -232,7 +232,7 @@ writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid ) NULL); return false; } - + /*** * Prepare the long jump back from libpng. */ @@ -248,7 +248,7 @@ writeHeader( const Meshes::Grid< 2, Real, Device, Index >& grid ) * Set the zlib compression level */ //png_set_compression_level( this->png_ptr, Z_BEST_COMPRESSION ); - + //const int bitDepth( 8 ); png_set_IHDR( this->png_ptr, this->info_ptr, @@ -301,7 +301,7 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, #ifdef HAVE_PNG_H typedef Meshes::Grid< 2, Real, Device, Index > GridType; typename GridType::Cell cell( grid ); - + /*** * Prepare the long jump back from libpng. */ @@ -312,7 +312,7 @@ write( const Meshes::Grid< 2, Real, Device, Index >& grid, &this->end_info ); return false; } - + Index i, j; png_bytep row = new png_byte[ 3 * grid.getDimensions().x() ]; for( i = 0; i < grid.getDimensions().y(); i ++ ) @@ -348,7 +348,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > typedef Meshes::Grid< 2, Real, Device, Index > GridType; const GridType& grid = function.getMesh(); typename GridType::Cell cell( grid ); - + /*** * Prepare the long jump back from libpng. */ @@ -359,7 +359,7 @@ write( const Functions::MeshFunction< Meshes::Grid< 2, MeshReal, Device, Index > &this->end_info ); return false; } - + Index i, j; png_bytep row = new png_byte[ 3 * grid.getDimensions().x() ]; for( i = 0; i < grid.getDimensions().y(); i ++ ) diff --git a/src/TNL/Images/RegionOfInterest.h b/src/TNL/Images/RegionOfInterest.h index 87e1f89cde02d15e7468c72dfcdb13fccbd5cd9a..4fc399b34622551579ad9703f8b1e740a7f06b66 100644 --- a/src/TNL/Images/RegionOfInterest.h +++ b/src/TNL/Images/RegionOfInterest.h @@ -7,50 +7,48 @@ #pragma once #include <TNL/Config/ParameterContainer.h> +#include <TNL/Images/Image.h> #include <TNL/Meshes/Grid.h> -#include <TNL/Images//Image.h> namespace TNL { -namespace Images { +namespace Images { template< typename Index = int > class RegionOfInterest { public: - + RegionOfInterest(); - + bool setup( const Config::ParameterContainer& parameters, const Image< Index >* image ); - + bool check( const Image< Index >* image ) const; - + Index getTop() const; - + Index getBottom() const; - + Index getLeft() const; - + Index getRight() const; - + Index getWidth() const; - + Index getHeight() const; - + template< typename Grid > bool setGrid( Grid& grid, bool verbose = false ); - + bool isIn( const Index row, const Index column ) const; - + protected: - + Index top, bottom, left, right; }; } // namespace Images } // namespace TNL -#include <TNL/Images//RegionOfInterest_impl.h> - - +#include <TNL/Images/RegionOfInterest_impl.h> diff --git a/src/UnitTests/Matrices/Legacy/CMakeLists.txt b/src/UnitTests/Matrices/Legacy/CMakeLists.txt index e4aa19a7fb5c8df037b96e784fc5c8afe7c13b7a..879604a4cec13ad57b30a129786bf44bb161c030 100644 --- a/src/UnitTests/Matrices/Legacy/CMakeLists.txt +++ b/src/UnitTests/Matrices/Legacy/CMakeLists.txt @@ -1,5 +1,4 @@ set( COMMON_TESTS - #Legacy_SparseMatrixCopyTest Legacy_SparseMatrixTest # TODO: Uncomment the following when AdEllpack works #SparseMatrixTest_AdEllpack diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cpp b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cpp deleted file mode 100644 index e4399b06125b4775778ea8a8850393c0e60bc863..0000000000000000000000000000000000000000 --- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Legacy_SparseMatrixCopyTest.h" diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cu b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cu deleted file mode 100644 index e4399b06125b4775778ea8a8850393c0e60bc863..0000000000000000000000000000000000000000 --- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.cu +++ /dev/null @@ -1 +0,0 @@ -#include "Legacy_SparseMatrixCopyTest.h" diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.h deleted file mode 100644 index 2407754d00b7a64ab3191db52f932935c74be411..0000000000000000000000000000000000000000 --- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixCopyTest.h +++ /dev/null @@ -1,563 +0,0 @@ -#include <TNL/Matrices/Legacy/CSR.h> -#include <TNL/Matrices/Legacy/Ellpack.h> -#include <TNL/Matrices/Legacy/SlicedEllpack.h> - -#include <TNL/Matrices/SparseMatrix.h> -#include <TNL/Matrices/MatrixType.h> -#include <TNL/Algorithms/Segments/CSR.h> -#include <TNL/Algorithms/Segments/Ellpack.h> -#include <TNL/Algorithms/Segments/SlicedEllpack.h> - -using CSR_host = TNL::Matrices::CSR< int, TNL::Devices::Host, int >; -using CSR_cuda = TNL::Matrices::CSR< int, TNL::Devices::Cuda, int >; -using E_host = TNL::Matrices::Ellpack< int, TNL::Devices::Host, int >; -using E_cuda = TNL::Matrices::Ellpack< int, TNL::Devices::Cuda, int >; -using SE_host = TNL::Matrices::SlicedEllpack< int, TNL::Devices::Host, int, 2 >; -using SE_cuda = TNL::Matrices::SlicedEllpack< int, TNL::Devices::Cuda, int, 2 >; - -/*template< typename Device, typename Index, typename IndexAllocator > -using EllpackSegments = TNL::Algorithms::Segments::Ellpack< Device, Index, IndexAllocator >; - -template< typename Device, typename Index, typename IndexAllocator > -using SlicedEllpackSegments = TNL::Algorithms::Segments::SlicedEllpack< Device, Index, IndexAllocator >; - -using CSR_host = TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Algorithms::Segments::CSR >; -using CSR_cuda = TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Algorithms::Segments::CSR >; -using E_host = TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, EllpackSegments >; -using E_cuda = TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, EllpackSegments >; -using SE_host = TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, SlicedEllpackSegments >; -using SE_cuda = TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, SlicedEllpackSegments >;*/ - - -#ifdef HAVE_GTEST -#include <gtest/gtest.h> - -/* - * Sets up the following 10x6 sparse matrix: - * - * / 1 2 \ - * | 3 4 5 | - * | 6 7 8 | - * | 9 10 11 12 13 | - * | 14 15 16 17 18 | - * | 19 20 | - * | 21 | - * | 22 | - * | 23 24 25 26 27 | - * \ 28 / - */ -template< typename Matrix > -void setupUnevenRowSizeMatrix( Matrix& m ) -{ - const int rows = 10; - const int cols = 6; - m.reset(); - m.setDimensions( rows, cols ); - typename Matrix::RowsCapacitiesType rowLengths; - rowLengths.setSize( rows ); - rowLengths.setValue( 5 ); - rowLengths.setElement( 0, 2 ); - rowLengths.setElement( 1, 3 ); - rowLengths.setElement( 2, 3 ); - rowLengths.setElement( 5, 2 ); - rowLengths.setElement( 6, 1 ); - rowLengths.setElement( 7, 1 ); - rowLengths.setElement( 9, 1 ); - m.setCompressedRowLengths( rowLengths ); - - int value = 1; - for( int i = 0; i < cols - 4; i++ ) // 0th row - m.setElement( 0, i, value++ ); - - for( int i = 3; i < cols; i++ ) // 1st row - m.setElement( 1, i, value++ ); - - for( int i = 0; i < cols - 3; i++ ) // 2nd row - m.setElement( 2, i, value++ ); - - for( int i = 1; i < cols; i++ ) // 3rd row - m.setElement( 3, i, value++ ); - - for( int i = 0; i < cols - 1; i++ ) // 4th row - m.setElement( 4, i, value++ ); - - for( int i = 0; i < cols - 4; i++ ) // 5th row - m.setElement( 5, i, value++ ); - - m.setElement( 6, 0, value++ ); // 6th row - - m.setElement( 7, 0, value++ ); // 7th row - - for( int i = 0; i < cols - 1; i++ ) // 8th row - m.setElement( 8, i, value++ ); - - m.setElement( 9, 5, value++ ); // 9th row -} - -template< typename Matrix > -void checkUnevenRowSizeMatrix( Matrix& m ) -{ - ASSERT_EQ( m.getRows(), 10 ); - ASSERT_EQ( m.getColumns(), 6 ); - - EXPECT_EQ( m.getElement( 0, 0 ), 1 ); - EXPECT_EQ( m.getElement( 0, 1 ), 2 ); - EXPECT_EQ( m.getElement( 0, 2 ), 0 ); - EXPECT_EQ( m.getElement( 0, 3 ), 0 ); - EXPECT_EQ( m.getElement( 0, 4 ), 0 ); - EXPECT_EQ( m.getElement( 0, 5 ), 0); - - EXPECT_EQ( m.getElement( 1, 0 ), 0 ); - EXPECT_EQ( m.getElement( 1, 1 ), 0 ); - EXPECT_EQ( m.getElement( 1, 2 ), 0 ); - EXPECT_EQ( m.getElement( 1, 3 ), 3 ); - EXPECT_EQ( m.getElement( 1, 4 ), 4 ); - EXPECT_EQ( m.getElement( 1, 5 ), 5 ); - - EXPECT_EQ( m.getElement( 2, 0 ), 6 ); - EXPECT_EQ( m.getElement( 2, 1 ), 7 ); - EXPECT_EQ( m.getElement( 2, 2 ), 8 ); - EXPECT_EQ( m.getElement( 2, 3 ), 0 ); - EXPECT_EQ( m.getElement( 2, 4 ), 0 ); - EXPECT_EQ( m.getElement( 2, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 3, 0 ), 0 ); - EXPECT_EQ( m.getElement( 3, 1 ), 9 ); - EXPECT_EQ( m.getElement( 3, 2 ), 10 ); - EXPECT_EQ( m.getElement( 3, 3 ), 11 ); - EXPECT_EQ( m.getElement( 3, 4 ), 12 ); - EXPECT_EQ( m.getElement( 3, 5 ), 13 ); - - EXPECT_EQ( m.getElement( 4, 0 ), 14 ); - EXPECT_EQ( m.getElement( 4, 1 ), 15 ); - EXPECT_EQ( m.getElement( 4, 2 ), 16 ); - EXPECT_EQ( m.getElement( 4, 3 ), 17 ); - EXPECT_EQ( m.getElement( 4, 4 ), 18 ); - EXPECT_EQ( m.getElement( 4, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 5, 0 ), 19 ); - EXPECT_EQ( m.getElement( 5, 1 ), 20 ); - EXPECT_EQ( m.getElement( 5, 2 ), 0 ); - EXPECT_EQ( m.getElement( 5, 3 ), 0 ); - EXPECT_EQ( m.getElement( 5, 4 ), 0 ); - EXPECT_EQ( m.getElement( 5, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 6, 0 ), 21 ); - EXPECT_EQ( m.getElement( 6, 1 ), 0 ); - EXPECT_EQ( m.getElement( 6, 2 ), 0 ); - EXPECT_EQ( m.getElement( 6, 3 ), 0 ); - EXPECT_EQ( m.getElement( 6, 4 ), 0 ); - EXPECT_EQ( m.getElement( 6, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 7, 0 ), 22 ); - EXPECT_EQ( m.getElement( 7, 1 ), 0 ); - EXPECT_EQ( m.getElement( 7, 2 ), 0 ); - EXPECT_EQ( m.getElement( 7, 3 ), 0 ); - EXPECT_EQ( m.getElement( 7, 4 ), 0 ); - EXPECT_EQ( m.getElement( 7, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 8, 0 ), 23 ); - EXPECT_EQ( m.getElement( 8, 1 ), 24 ); - EXPECT_EQ( m.getElement( 8, 2 ), 25 ); - EXPECT_EQ( m.getElement( 8, 3 ), 26 ); - EXPECT_EQ( m.getElement( 8, 4 ), 27 ); - EXPECT_EQ( m.getElement( 8, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 9, 0 ), 0 ); - EXPECT_EQ( m.getElement( 9, 1 ), 0 ); - EXPECT_EQ( m.getElement( 9, 2 ), 0 ); - EXPECT_EQ( m.getElement( 9, 3 ), 0 ); - EXPECT_EQ( m.getElement( 9, 4 ), 0 ); - EXPECT_EQ( m.getElement( 9, 5 ), 28 ); -} - -/* - * Sets up the following 7x6 sparse matrix: - * - * / 2 1 \ - * | 5 4 3 | - * | 8 7 6 | - * | 11 10 9 | - * | 14 13 12 | - * | 16 15 | - * \ 17 / - */ -template< typename Matrix > -void setupAntiTriDiagMatrix( Matrix& m ) -{ - const int rows = 7; - const int cols = 6; - m.reset(); - m.setDimensions( rows, cols ); - typename Matrix::RowsCapacitiesType rowLengths; - rowLengths.setSize( rows ); - rowLengths.setValue( 3 ); - rowLengths.setElement( 0, 4); - rowLengths.setElement( 1, 4 ); - m.setCompressedRowLengths( rowLengths ); - - int value = 1; - for( int i = 0; i < rows; i++ ) - for( int j = cols - 1; j > 2; j-- ) - if( j - i + 1 < cols && j - i + 1 >= 0 ) - m.setElement( i, j - i + 1, value++ ); -} - -template< typename Matrix > -void checkAntiTriDiagMatrix( Matrix& m ) -{ - ASSERT_EQ( m.getRows(), 7 ); - ASSERT_EQ( m.getColumns(), 6 ); - - EXPECT_EQ( m.getElement( 0, 0 ), 0 ); - EXPECT_EQ( m.getElement( 0, 1 ), 0 ); - EXPECT_EQ( m.getElement( 0, 2 ), 0 ); - EXPECT_EQ( m.getElement( 0, 3 ), 0 ); - EXPECT_EQ( m.getElement( 0, 4 ), 2 ); - EXPECT_EQ( m.getElement( 0, 5 ), 1); - - EXPECT_EQ( m.getElement( 1, 0 ), 0 ); - EXPECT_EQ( m.getElement( 1, 1 ), 0 ); - EXPECT_EQ( m.getElement( 1, 2 ), 0 ); - EXPECT_EQ( m.getElement( 1, 3 ), 5 ); - EXPECT_EQ( m.getElement( 1, 4 ), 4 ); - EXPECT_EQ( m.getElement( 1, 5 ), 3 ); - - EXPECT_EQ( m.getElement( 2, 0 ), 0 ); - EXPECT_EQ( m.getElement( 2, 1 ), 0 ); - EXPECT_EQ( m.getElement( 2, 2 ), 8 ); - EXPECT_EQ( m.getElement( 2, 3 ), 7 ); - EXPECT_EQ( m.getElement( 2, 4 ), 6 ); - EXPECT_EQ( m.getElement( 2, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 3, 0 ), 0 ); - EXPECT_EQ( m.getElement( 3, 1 ), 11 ); - EXPECT_EQ( m.getElement( 3, 2 ), 10 ); - EXPECT_EQ( m.getElement( 3, 3 ), 9 ); - EXPECT_EQ( m.getElement( 3, 4 ), 0 ); - EXPECT_EQ( m.getElement( 3, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 4, 0 ), 14 ); - EXPECT_EQ( m.getElement( 4, 1 ), 13 ); - EXPECT_EQ( m.getElement( 4, 2 ), 12 ); - EXPECT_EQ( m.getElement( 4, 3 ), 0 ); - EXPECT_EQ( m.getElement( 4, 4 ), 0 ); - EXPECT_EQ( m.getElement( 4, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 5, 0 ), 16 ); - EXPECT_EQ( m.getElement( 5, 1 ), 15 ); - EXPECT_EQ( m.getElement( 5, 2 ), 0 ); - EXPECT_EQ( m.getElement( 5, 3 ), 0 ); - EXPECT_EQ( m.getElement( 5, 4 ), 0 ); - EXPECT_EQ( m.getElement( 5, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 6, 0 ), 17 ); - EXPECT_EQ( m.getElement( 6, 1 ), 0 ); - EXPECT_EQ( m.getElement( 6, 2 ), 0 ); - EXPECT_EQ( m.getElement( 6, 3 ), 0 ); - EXPECT_EQ( m.getElement( 6, 4 ), 0 ); - EXPECT_EQ( m.getElement( 6, 5 ), 0 ); -} - -/* - * Sets up the following 7x6 sparse matrix: - * - * / 1 2 \ - * | 3 4 5 | - * | 6 7 8 | - * | 9 10 11 | - * | 12 13 14 | - * | 15 16 | - * \ 17 / - */ -template< typename Matrix > -void setupTriDiagMatrix( Matrix& m ) -{ - const int rows = 7; - const int cols = 6; - m.reset(); - m.setDimensions( rows, cols ); - typename Matrix::RowsCapacitiesType rowLengths; - rowLengths.setSize( rows ); - rowLengths.setValue( 3 ); - rowLengths.setElement( 0 , 4 ); - rowLengths.setElement( 1, 4 ); - m.setCompressedRowLengths( rowLengths ); - - int value = 1; - for( int i = 0; i < rows; i++ ) - for( int j = 0; j < 3; j++ ) - if( i + j - 1 >= 0 && i + j - 1 < cols ) - m.setElement( i, i + j - 1, value++ ); -} - -template< typename Matrix > -void checkTriDiagMatrix( Matrix& m ) -{ - ASSERT_EQ( m.getRows(), 7 ); - ASSERT_EQ( m.getColumns(), 6 ); - - EXPECT_EQ( m.getElement( 0, 0 ), 1 ); - EXPECT_EQ( m.getElement( 0, 1 ), 2 ); - EXPECT_EQ( m.getElement( 0, 2 ), 0 ); - EXPECT_EQ( m.getElement( 0, 3 ), 0 ); - EXPECT_EQ( m.getElement( 0, 4 ), 0 ); - EXPECT_EQ( m.getElement( 0, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 1, 0 ), 3 ); - EXPECT_EQ( m.getElement( 1, 1 ), 4 ); - EXPECT_EQ( m.getElement( 1, 2 ), 5 ); - EXPECT_EQ( m.getElement( 1, 3 ), 0 ); - EXPECT_EQ( m.getElement( 1, 4 ), 0 ); - EXPECT_EQ( m.getElement( 1, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 2, 0 ), 0 ); - EXPECT_EQ( m.getElement( 2, 1 ), 6 ); - EXPECT_EQ( m.getElement( 2, 2 ), 7 ); - EXPECT_EQ( m.getElement( 2, 3 ), 8 ); - EXPECT_EQ( m.getElement( 2, 4 ), 0 ); - EXPECT_EQ( m.getElement( 2, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 3, 0 ), 0 ); - EXPECT_EQ( m.getElement( 3, 1 ), 0 ); - EXPECT_EQ( m.getElement( 3, 2 ), 9 ); - EXPECT_EQ( m.getElement( 3, 3 ), 10 ); - EXPECT_EQ( m.getElement( 3, 4 ), 11 ); - EXPECT_EQ( m.getElement( 3, 5 ), 0 ); - - EXPECT_EQ( m.getElement( 4, 0 ), 0 ); - EXPECT_EQ( m.getElement( 4, 1 ), 0 ); - EXPECT_EQ( m.getElement( 4, 2 ), 0 ); - EXPECT_EQ( m.getElement( 4, 3 ), 12 ); - EXPECT_EQ( m.getElement( 4, 4 ), 13 ); - EXPECT_EQ( m.getElement( 4, 5 ), 14 ); - - EXPECT_EQ( m.getElement( 5, 0 ), 0 ); - EXPECT_EQ( m.getElement( 5, 1 ), 0 ); - EXPECT_EQ( m.getElement( 5, 2 ), 0 ); - EXPECT_EQ( m.getElement( 5, 3 ), 0 ); - EXPECT_EQ( m.getElement( 5, 4 ), 15 ); - EXPECT_EQ( m.getElement( 5, 5 ), 16 ); - - EXPECT_EQ( m.getElement( 6, 0 ), 0 ); - EXPECT_EQ( m.getElement( 6, 1 ), 0 ); - EXPECT_EQ( m.getElement( 6, 2 ), 0 ); - EXPECT_EQ( m.getElement( 6, 3 ), 0 ); - EXPECT_EQ( m.getElement( 6, 4 ), 0 ); - EXPECT_EQ( m.getElement( 6, 5 ), 17 ); -} - -template< typename Matrix1, typename Matrix2 > -void testCopyAssignment() -{ - { - SCOPED_TRACE("Tri Diagonal Matrix"); - - Matrix1 triDiag1; - setupTriDiagMatrix( triDiag1 ); - checkTriDiagMatrix( triDiag1 ); - - Matrix2 triDiag2; - triDiag2 = triDiag1; - checkTriDiagMatrix( triDiag2 ); - } - { - SCOPED_TRACE("Anti Tri Diagonal Matrix"); - Matrix1 antiTriDiag1; - setupAntiTriDiagMatrix( antiTriDiag1 ); - checkAntiTriDiagMatrix( antiTriDiag1 ); - - Matrix2 antiTriDiag2; - antiTriDiag2 = antiTriDiag1; - checkAntiTriDiagMatrix( antiTriDiag2 ); - } - { - SCOPED_TRACE("Uneven Row Size Matrix"); - Matrix1 unevenRowSize1; - setupUnevenRowSizeMatrix( unevenRowSize1 ); - checkUnevenRowSizeMatrix( unevenRowSize1 ); - - Matrix2 unevenRowSize2; - unevenRowSize2 = unevenRowSize1; - checkUnevenRowSizeMatrix( unevenRowSize2 ); - } -} - -template< typename Matrix1, typename Matrix2 > -void testConversion() -{ - - { - SCOPED_TRACE("Tri Diagonal Matrix"); - - Matrix1 triDiag1; - setupTriDiagMatrix( triDiag1 ); - checkTriDiagMatrix( triDiag1 ); - - Matrix2 triDiag2; - //TNL::Matrices::copySparseMatrix( triDiag2, triDiag1 ); - triDiag2 = triDiag1; - checkTriDiagMatrix( triDiag2 ); - } - - { - SCOPED_TRACE("Anti Tri Diagonal Matrix"); - - Matrix1 antiTriDiag1; - setupAntiTriDiagMatrix( antiTriDiag1 ); - checkAntiTriDiagMatrix( antiTriDiag1 ); - - Matrix2 antiTriDiag2; - //TNL::Matrices::copySparseMatrix( antiTriDiag2, antiTriDiag1 ); - antiTriDiag2 = antiTriDiag1; - checkAntiTriDiagMatrix( antiTriDiag2 ); - } - - { - SCOPED_TRACE("Uneven Row Size Matrix"); - Matrix1 unevenRowSize1; - setupUnevenRowSizeMatrix( unevenRowSize1 ); - checkUnevenRowSizeMatrix( unevenRowSize1 ); - - Matrix2 unevenRowSize2; - //TNL::Matrices::copySparseMatrix( unevenRowSize2, unevenRowSize1 ); - unevenRowSize2 = unevenRowSize1; - checkUnevenRowSizeMatrix( unevenRowSize2 ); - } -} - -TEST( SparseMatrixCopyTest, CSR_HostToHost ) -{ - testCopyAssignment< CSR_host, CSR_host >(); -} - -#ifdef HAVE_CUDA -TEST( SparseMatrixCopyTest, CSR_HostToCuda ) -{ - testCopyAssignment< CSR_host, CSR_cuda >(); -} - -TEST( SparseMatrixCopyTest, CSR_CudaToHost ) -{ - testCopyAssignment< CSR_cuda, CSR_host >(); -} - -TEST( SparseMatrixCopyTest, CSR_CudaToCuda ) -{ - testCopyAssignment< CSR_cuda, CSR_cuda >(); -} -#endif - - -TEST( SparseMatrixCopyTest, Ellpack_HostToHost ) -{ - testCopyAssignment< E_host, E_host >(); -} - -#ifdef HAVE_CUDA -TEST( SparseMatrixCopyTest, Ellpack_HostToCuda ) -{ - testCopyAssignment< E_host, E_cuda >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_CudaToHost ) -{ - testCopyAssignment< E_cuda, E_host >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_CudaToCuda ) -{ - testCopyAssignment< E_cuda, E_cuda >(); -} -#endif - - -TEST( SparseMatrixCopyTest, SlicedEllpack_HostToHost ) -{ - testCopyAssignment< SE_host, SE_host >(); -} - -#ifdef HAVE_CUDA -TEST( SparseMatrixCopyTest, SlicedEllpack_HostToCuda ) -{ - testCopyAssignment< SE_host, SE_cuda >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_CudaToHost ) -{ - testCopyAssignment< SE_cuda, SE_host >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_CudaToCuda ) -{ - testCopyAssignment< SE_cuda, SE_cuda >(); -} -#endif - - -// test conversion between formats -TEST( SparseMatrixCopyTest, CSR_to_Ellpack_host ) -{ - testConversion< CSR_host, E_host >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_to_CSR_host ) -{ - testConversion< E_host, CSR_host >(); -} - -TEST( SparseMatrixCopyTest, CSR_to_SlicedEllpack_host ) -{ - testConversion< CSR_host, SE_host >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_to_CSR_host ) -{ - testConversion< SE_host, CSR_host >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_to_SlicedEllpack_host ) -{ - testConversion< E_host, SE_host >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_to_Ellpack_host ) -{ - testConversion< SE_host, E_host >(); -} - -#ifdef HAVE_CUDA -TEST( SparseMatrixCopyTest, CSR_to_Ellpack_cuda ) -{ - testConversion< CSR_cuda, E_cuda >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_to_CSR_cuda ) -{ - testConversion< E_cuda, CSR_cuda >(); -} - -TEST( SparseMatrixCopyTest, CSR_to_SlicedEllpack_cuda ) -{ - testConversion< CSR_cuda, SE_cuda >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_to_CSR_cuda ) -{ - testConversion< SE_cuda, CSR_cuda >(); -} - -TEST( SparseMatrixCopyTest, Ellpack_to_SlicedEllpack_cuda ) -{ - testConversion< E_cuda, SE_cuda >(); -} - -TEST( SparseMatrixCopyTest, SlicedEllpack_to_Ellpack_cuda ) -{ - testConversion< SE_cuda, E_cuda >(); -} -#endif - -#endif - -#include "../../main.h"