From 26cf2a62846eb4d2cbac97378bb6cef22b440f78 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 24 Oct 2022 13:28:30 +0200 Subject: [PATCH 01/47] initialize the first value of ne_counter to 0 --- src/numerics/APRDownsampleGPU.cu | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/numerics/APRDownsampleGPU.cu b/src/numerics/APRDownsampleGPU.cu index 909728d4..9da3410e 100644 --- a/src/numerics/APRDownsampleGPU.cu +++ b/src/numerics/APRDownsampleGPU.cu @@ -900,6 +900,7 @@ template void compute_ne_rows_tree_cuda(GPUAccessHelper& tree_access, VectorData& ne_count, ScopedCudaMemHandler& ne_rows_gpu) { ne_count.resize(tree_access.level_max() + 3); + ne_count[0] = 0; int z_blocks_max = (tree_access.z_num(tree_access.level_max()) + blockSize_z - 1) / blockSize_z; int num_levels = tree_access.level_max() - tree_access.level_min() + 1; @@ -973,12 +974,13 @@ void compute_ne_rows_tree_cuda(GPUAccessHelper& tree_access, VectorData& ne ne_rows_gpu.get()); } - error_check(cudaFree(block_sums_device) ) + error_check(cudaFree(block_sums_device)) } void compute_ne_rows_tree(GPUAccessHelper& tree_access, VectorData& ne_counter, VectorData& ne_rows) { ne_counter.resize(tree_access.level_max() + 3); + ne_counter[0] = 0; int z = 0; int x = 0; From 0b1a7b3832da660ceadd38fc3cbd6ab5a1e7d1d5 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 24 Oct 2022 13:29:02 +0200 Subject: [PATCH 02/47] indentation --- src/numerics/miscCuda.cu | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/numerics/miscCuda.cu b/src/numerics/miscCuda.cu index 4dc043b6..93b5b94e 100644 --- a/src/numerics/miscCuda.cu +++ b/src/numerics/miscCuda.cu @@ -237,6 +237,7 @@ __global__ void fill_ne_rows_cuda(const uint64_t* level_xz_vec, } + template void compute_ne_rows_cuda(GPUAccessHelper& access, VectorData& ne_count, ScopedCudaMemHandler& ne_rows_gpu, int blockSize) { @@ -264,12 +265,12 @@ void compute_ne_rows_cuda(GPUAccessHelper& access, VectorData& ne_count, Sc count_ne_rows_cuda << < grid_dim, block_dim >> > (access.get_level_xz_vec_ptr(), - access.get_xz_end_vec_ptr(), - access.z_num(level), - access.x_num(level), - level, - blockSize, - block_sums_device + offset); + access.get_xz_end_vec_ptr(), + access.z_num(level), + access.x_num(level), + level, + blockSize, + block_sums_device + offset); offset += z_blocks_max; } @@ -305,14 +306,14 @@ void compute_ne_rows_cuda(GPUAccessHelper& access, VectorData& ne_count, Sc fill_ne_rows_cuda<<< grid_dim, block_dim >>> (access.get_level_xz_vec_ptr(), - access.get_xz_end_vec_ptr(), - access.z_num(level), - access.x_num(level), - level, - blockSize, - ne_sz, - ne_count[level], - ne_rows_gpu.get()); + access.get_xz_end_vec_ptr(), + access.z_num(level), + access.x_num(level), + level, + blockSize, + ne_sz, + ne_count[level], + ne_rows_gpu.get()); } error_check( cudaFree(block_sums_device) ) From 66a5c0cd06610b1f919d408b4f923cc41776b9c0 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 24 Oct 2022 13:31:28 +0200 Subject: [PATCH 03/47] inline hdf5 file creation call to avoid undefined symbol errors in certain uses of the library --- src/io/APRWriter.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/io/APRWriter.hpp b/src/io/APRWriter.hpp index 4ad6231a..2fbe4dee 100644 --- a/src/io/APRWriter.hpp +++ b/src/io/APRWriter.hpp @@ -702,7 +702,8 @@ class APRWriter { break; case Operation::WRITE: - fileId = hdf5_create_file_blosc(aFileName); +// fileId = hdf5_create_file_blosc(aFileName); + fileId = H5Fcreate(aFileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if (fileId == -1) { std::cerr << "Could not create file [" << aFileName << "]" << std::endl; From 2b38a7bab1c25e2c7a575fdd6ba810fa77585295 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 24 Oct 2022 13:33:40 +0200 Subject: [PATCH 04/47] bump submodule gtest --- external/gtest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/gtest b/external/gtest index 6b74da47..e07617d6 160000 --- a/external/gtest +++ b/external/gtest @@ -1 +1 @@ -Subproject commit 6b74da4757a549563d7c37c8fae3e704662a043b +Subproject commit e07617d6c692a96e126f11f85c3e38e46b10b4d0 From afb5261709c9b3a9022d087b761014e8bf76f8b6 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Thu, 24 Nov 2022 17:54:05 +0100 Subject: [PATCH 05/47] make protected APR members public to allow access for pickling in pyapr --- src/data_structures/APR/APR.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/data_structures/APR/APR.hpp b/src/data_structures/APR/APR.hpp index 83ae95b3..2de9854d 100644 --- a/src/data_structures/APR/APR.hpp +++ b/src/data_structures/APR/APR.hpp @@ -23,7 +23,7 @@ class APR { friend class APRConverterBatch; friend class APRBenchHelper; -protected: +public: // initialize tree RandomAccess void initialize_tree_random_sparse(); @@ -60,8 +60,6 @@ class APR { APRParameters parameters; // this is here to keep a record of what parameters were used, to then be written if needed. -public: - #ifdef APR_USE_CUDA From cf7f7bbfdd300ed1cd226a19727db00ce46c9c5c Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Sun, 27 Nov 2022 14:28:18 +0100 Subject: [PATCH 06/47] ensure correct GenInfo for linearAccess/gpuAccess --- src/data_structures/APR/APR.hpp | 4 ++++ src/data_structures/APR/access/GPUAccess.hpp | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/data_structures/APR/APR.hpp b/src/data_structures/APR/APR.hpp index 2de9854d..80549843 100644 --- a/src/data_structures/APR/APR.hpp +++ b/src/data_structures/APR/APR.hpp @@ -84,6 +84,10 @@ class APR { * @param with_tree include the tree access */ void init_cuda(bool with_tree=true) { + gpuAccess.genInfo = &aprInfo; + gpuTreeAccess.genInfo = &treeInfo; + linearAccess.genInfo = &aprInfo; + linearAccessTree.genInfo = &treeInfo; auto apr_helper = gpuAPRHelper(); if(with_tree) { auto tree_helper = gpuTreeHelper(); diff --git a/src/data_structures/APR/access/GPUAccess.hpp b/src/data_structures/APR/access/GPUAccess.hpp index 9d57b09d..4d5f676a 100644 --- a/src/data_structures/APR/access/GPUAccess.hpp +++ b/src/data_structures/APR/access/GPUAccess.hpp @@ -67,7 +67,6 @@ class GPUAccessHelper { gpuAccess->init_y_vec(linearAccess->y_vec); gpuAccess->init_level_xz_vec(linearAccess->level_xz_vec); gpuAccess->init_xz_end_vec(linearAccess->xz_end_vec); - gpuAccess->genInfo = linearAccess->genInfo; gpuAccess->copy2Device(); gpuAccess->initialized = true; } @@ -78,7 +77,6 @@ class GPUAccessHelper { gpuAccess->init_y_vec(linearAccess->y_vec); gpuAccess->init_level_xz_vec(linearAccess->level_xz_vec); gpuAccess->init_xz_end_vec(linearAccess->xz_end_vec); - gpuAccess->genInfo = linearAccess->genInfo; gpuAccess->copy2Device(total_number_particles(tree_access.level_max()), tree_access.gpuAccess); gpuAccess->initialized = true; } @@ -88,7 +86,7 @@ class GPUAccessHelper { gpuAccess->copy2Host(); } - uint64_t total_number_particles() { return gpuAccess->total_number_particles(); } + uint64_t total_number_particles() { return gpuAccess->genInfo->total_number_particles; } uint64_t total_number_particles(const int level) { uint64_t index = linearAccess->level_xz_vec[level] + linearAccess->x_num(level) - 1 + (linearAccess->z_num(level)-1)*linearAccess->x_num(level); From 374c01ffb5b7a3993122d6bb21b4fc4911d63464 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 01:42:28 +0100 Subject: [PATCH 07/47] make addition of gaussian noise an option (off by default) --- examples/Example_reconstruct_image.cpp | 46 ++++++++++++-------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/Example_reconstruct_image.cpp b/examples/Example_reconstruct_image.cpp index dcebde0e..f821d3c4 100644 --- a/examples/Example_reconstruct_image.cpp +++ b/examples/Example_reconstruct_image.cpp @@ -47,7 +47,7 @@ struct cmdLineOptions{ bool output_spatial_properties = false; bool output_pc_recon = false; bool output_smooth_recon = false; - + float gaussian_noise_sigma = 0.0f; }; static bool command_option_exists(char **begin, char **end, const std::string &option) { @@ -99,6 +99,10 @@ static cmdLineOptions read_command_line_options(int argc, char **argv) { result.output_spatial_properties = true; } + if(command_option_exists(argv, argv + argc, "-noise")) { + result.gaussian_noise_sigma = std::stof(std::string(get_command_option(argv, argv + argc, "-noise"))); + } + if(!(result.output_pc_recon || result.output_smooth_recon || result.output_spatial_properties)){ //default is pc recon result.output_pc_recon = true; @@ -107,7 +111,7 @@ static cmdLineOptions read_command_line_options(int argc, char **argv) { return result; } template -void add_random_to_img(PixelData& img,float sd){ +void add_random_to_img(PixelData& img, float sd){ std::default_random_engine generator; std::normal_distribution distribution(0.0,sd); @@ -149,32 +153,26 @@ int main(int argc, char **argv) { apr.name = options.output; timer.stop_timer(); - // Intentionaly block-scoped since local recon_pc will be destructed when block ends and release memory. - { - - if(options.output_pc_recon) { - //create mesh data structure for reconstruction - bool add_random_gitter = true; - - PixelData recon_pc; + if(options.output_pc_recon) { + //create mesh data structure for reconstruction + PixelData recon_pc; - timer.start_timer("pc interp"); - //perform piece-wise constant interpolation - APRReconstruction::reconstruct_constant(apr,recon_pc, parts); - timer.stop_timer(); + timer.start_timer("pc interp"); + //perform piece-wise constant interpolation + APRReconstruction::reconstruct_constant(apr, recon_pc, parts); + timer.stop_timer(); - if(add_random_gitter){ - add_random_to_img(recon_pc,1.0f); - } + if(options.gaussian_noise_sigma > 0.0f) { + add_random_to_img(recon_pc, options.gaussian_noise_sigma); + } - float elapsed_seconds = timer.t2 - timer.t1; - std::cout << "PC recon " - << (recon_pc.x_num * recon_pc.y_num * recon_pc.z_num * 2) / (elapsed_seconds * 1000000.0f) - << " MB per second" << std::endl; + float elapsed_seconds = timer.t2 - timer.t1; + std::cout << "PC recon " + << (recon_pc.x_num * recon_pc.y_num * recon_pc.z_num * 2) / (elapsed_seconds * 1000000.0f) + << " MB per second" << std::endl; - // write output as tiff - TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_pc.tif", recon_pc); - } + // write output as tiff + TiffUtils::saveMeshAsTiff(options.directory + apr.name + "_pc.tif", recon_pc); } ////////////////////////// From 69a3fe55b7906d8013ecf0c45347135469caa4d8 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 12:51:56 +0100 Subject: [PATCH 08/47] Fix unsafe addition of bspline_offset for APRConverter of integer type to avoid overflows when the input image has values near the largest representable number. New behavior is that no offset is added when either a) `lambda<=0` or b) the image covers the entire range of values. --- src/algorithm/APRConverter.hpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/algorithm/APRConverter.hpp b/src/algorithm/APRConverter.hpp index d6728f5f..9fea1252 100644 --- a/src/algorithm/APRConverter.hpp +++ b/src/algorithm/APRConverter.hpp @@ -210,6 +210,22 @@ void APRConverter::get_apr_custom_grad_scale(APR& aAPR,PixelData +float compute_bspline_offset(PixelData& input_image, float lambda) { + // if bspline smoothing is disabled, there is no need for an offset + if(lambda <= 0) return 0; + + // compute offset to center the intensities in the ImageType range (can be negative) + auto img_range = getMinMax(input_image); + float offset = (std::numeric_limits::max() - (img_range.max - img_range.min)) / 2 - img_range.min; + + // clamp the offset to [-100, 100] + return std::max(std::min(offset, 100.f), -100.f); +} + template template void APRConverter::computeL(APR& aAPR,PixelData& input_image){ // @@ -233,17 +249,12 @@ void APRConverter::computeL(APR& aAPR,PixelData& input_image){ //////////////////////// fine_grained_timer.start_timer("offset image"); - //offset image by factor (this is required if there are zero areas in the background with uint16_t and uint8_t images, as the Bspline co-efficients otherwise may be negative!) - // Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set image_type = "", i.e. uncomment the following line) - if (std::is_same::value) { - bspline_offset = 100; - image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); - } else if (std::is_same::value){ - bspline_offset = 5; - image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); - } else { + if (std::is_floating_point::value) { image_temp.copyFromMesh(input_image); + } else { + bspline_offset = compute_bspline_offset(input_image, par.lambda); + image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); } fine_grained_timer.stop_timer(); From ad3a5b5a95b1f53df219ee787bf16acf5cea9904 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 13:03:53 +0100 Subject: [PATCH 09/47] set pinned memory to false as cuda pipeline is not functional --- src/algorithm/APRConverter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithm/APRConverter.hpp b/src/algorithm/APRConverter.hpp index 9fea1252..bbe6a5a2 100644 --- a/src/algorithm/APRConverter.hpp +++ b/src/algorithm/APRConverter.hpp @@ -240,7 +240,7 @@ void APRConverter::computeL(APR& aAPR,PixelData& input_image){ //assuming uint16, the total memory cost shoudl be approximately (1 + 1 + 1/8 + 2/8 + 2/8) = 2 5/8 original image size in u16bit //storage of the particle cell tree for computing the pulling scheme allocation_timer.start_timer("init and copy image"); - PixelData image_temp(input_image, false /* don't copy */, true /* pinned memory */); // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image) + PixelData image_temp(input_image, false /* don't copy */, false /* pinned memory */); // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image) allocation_timer.stop_timer(); From 5bc9d8edf2927646efa7cddcd5860f1bfb62aac7 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 13:05:19 +0100 Subject: [PATCH 10/47] Use APRConverter in Example_get_apr.cpp --- examples/Example_get_apr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Example_get_apr.cpp b/examples/Example_get_apr.cpp index bfbaf31d..6ac8e9c7 100644 --- a/examples/Example_get_apr.cpp +++ b/examples/Example_get_apr.cpp @@ -48,7 +48,7 @@ int runAPR(cmdLineOptions options) { //the apr datastructure APR apr; - APRConverter aprConverter; + APRConverter aprConverter; //read in the command line options into the parameters file aprConverter.par.Ip_th = options.Ip_th; From 3705021afb0dc856e2f6b9edea38782d290cc151 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 14:53:47 +0100 Subject: [PATCH 11/47] add auto_parameters option and use float converter --- examples/Example_get_apr_by_block.cpp | 9 +++++++-- examples/Example_get_apr_by_block.hpp | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/Example_get_apr_by_block.cpp b/examples/Example_get_apr_by_block.cpp index 70805a4c..10217a56 100644 --- a/examples/Example_get_apr_by_block.cpp +++ b/examples/Example_get_apr_by_block.cpp @@ -44,7 +44,7 @@ must be used. The exact influence of this has not yet been studied. int runAPR(cmdLineOptions options) { APR apr; - APRConverterBatch aprConverter; + APRConverterBatch aprConverter; //read in the command line options into the parameters file aprConverter.par.Ip_th = options.Ip_th; @@ -55,6 +55,7 @@ int runAPR(cmdLineOptions options) { aprConverter.par.neighborhood_optimization = options.neighborhood_optimization; aprConverter.par.output_steps = options.output_steps; aprConverter.par.grad_th = options.grad_th; + aprConverter.par.auto_parameters = options.auto_parameters; //where things are aprConverter.par.input_image_name = options.input; @@ -234,7 +235,6 @@ cmdLineOptions read_command_line_options(int argc, char **argv){ if(command_option_exists(argv, argv + argc, "-neighborhood_optimization_off")) { result.neighborhood_optimization = false; - } if(command_option_exists(argv, argv + argc, "-output_steps")) @@ -247,5 +247,10 @@ cmdLineOptions read_command_line_options(int argc, char **argv){ result.store_tree = true; } + if(command_option_exists(argv, argv + argc, "-auto_parameters")) + { + result.auto_parameters = true; + } + return result; } \ No newline at end of file diff --git a/examples/Example_get_apr_by_block.hpp b/examples/Example_get_apr_by_block.hpp index 019cddc2..1902f00b 100644 --- a/examples/Example_get_apr_by_block.hpp +++ b/examples/Example_get_apr_by_block.hpp @@ -30,6 +30,8 @@ struct cmdLineOptions{ float rel_error = 0.1; float grad_th = 1; + bool auto_parameters = false; + int z_block_size = 128; int z_ghost = 16; // number of "ghost slices" to use in the APR pipeline int z_ghost_sampling = 64; // number of "ghost slices" to use when sampling intensities From 08506116c482fcc02d2d5f4744eec4e8fe50ed51 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 15:04:10 +0100 Subject: [PATCH 12/47] move compute_bspline_offset method to AutoParameters.hpp --- src/algorithm/APRConverter.hpp | 16 ---------------- src/algorithm/AutoParameters.hpp | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/algorithm/APRConverter.hpp b/src/algorithm/APRConverter.hpp index bbe6a5a2..8e641c84 100644 --- a/src/algorithm/APRConverter.hpp +++ b/src/algorithm/APRConverter.hpp @@ -210,22 +210,6 @@ void APRConverter::get_apr_custom_grad_scale(APR& aAPR,PixelData -float compute_bspline_offset(PixelData& input_image, float lambda) { - // if bspline smoothing is disabled, there is no need for an offset - if(lambda <= 0) return 0; - - // compute offset to center the intensities in the ImageType range (can be negative) - auto img_range = getMinMax(input_image); - float offset = (std::numeric_limits::max() - (img_range.max - img_range.min)) / 2 - img_range.min; - - // clamp the offset to [-100, 100] - return std::max(std::min(offset, 100.f), -100.f); -} - template template void APRConverter::computeL(APR& aAPR,PixelData& input_image){ // diff --git a/src/algorithm/AutoParameters.hpp b/src/algorithm/AutoParameters.hpp index 948d0636..cd8eff81 100644 --- a/src/algorithm/AutoParameters.hpp +++ b/src/algorithm/AutoParameters.hpp @@ -157,4 +157,22 @@ void autoParametersLiEntropy(APRParameters& par, } } + +/** + * Compute bspline offset for APRConverter of integer type ImageType + */ +template +float compute_bspline_offset(PixelData& input_image, float lambda) { + // if bspline smoothing is disabled, there is no need for an offset + if(lambda <= 0) return 0; + + // compute offset to center the intensities in the ImageType range (can be negative) + auto img_range = getMinMax(input_image); + float offset = (std::numeric_limits::max() - (img_range.max - img_range.min)) / 2 - img_range.min; + + // clamp the offset to [-100, 100] + return std::max(std::min(offset, 100.f), -100.f); +} + + #endif //APR_AUTOPARAMETERS_HPP From a3c5365b7d3fc30ab347bd34909cfa5a809987e3 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 15:05:12 +0100 Subject: [PATCH 13/47] use compute_bspline_offset method in blocked pipeline --- src/algorithm/APRConverterBatch.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/algorithm/APRConverterBatch.hpp b/src/algorithm/APRConverterBatch.hpp index 3d611a9b..ea8c7b0b 100644 --- a/src/algorithm/APRConverterBatch.hpp +++ b/src/algorithm/APRConverterBatch.hpp @@ -214,17 +214,14 @@ bool APRConverterBatch::get_apr_method_patch(APR &aAPR, PixelData& computation_timer.start_timer("Calculations"); fine_grained_timer.start_timer("offset image"); - //offset image by factor (this is required if there are zero areas in the background with uint16_t and uint8_t images, as the Bspline co-efficients otherwise may be negative!) - // Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set image_type = "", i.e. uncomment the following line) - if (std::is_same::value) { - bspline_offset = 100; - image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); - } else if (std::is_same::value){ - bspline_offset = 5; - image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); - } else { + + if (std::is_floating_point::value) { image_temp.copyFromMesh(input_image); + } else { + bspline_offset = compute_bspline_offset(input_image, par.lambda); + image_temp.copyFromMeshWithUnaryOp(input_image, [=](const auto &a) { return (a + bspline_offset); }); } + fine_grained_timer.stop_timer(); method_timer.start_timer("compute_gradient_magnitude_using_bsplines"); From a2f55eb6e76e5ae4b9b946b5a68eb0ed96af13b1 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 15:33:05 +0100 Subject: [PATCH 14/47] move getMinMax function to AutoParameters.hpp --- src/algorithm/APRConverter.hpp | 20 -------------------- src/algorithm/AutoParameters.hpp | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/algorithm/APRConverter.hpp b/src/algorithm/APRConverter.hpp index 8e641c84..d72b2f0b 100644 --- a/src/algorithm/APRConverter.hpp +++ b/src/algorithm/APRConverter.hpp @@ -133,26 +133,6 @@ class APRConverter { }; -template -struct MinMax{T min; T max; }; - -template -static MinMax getMinMax(const PixelData& input_image) { - T minVal = std::numeric_limits::max(); - T maxVal = std::numeric_limits::min(); - -#ifdef HAVE_OPENMP -#pragma omp parallel for default(shared) reduction(max:maxVal) reduction(min:minVal) -#endif - for (size_t i = 0; i < input_image.mesh.size(); ++i) { - T val = input_image.mesh[i]; - if (val > maxVal) maxVal = val; - if (val < minVal) minVal = val; - } - - return MinMax{minVal, maxVal}; -} - template void APRConverter::initPipelineMemory(int y_num,int x_num,int z_num){ //initializes the internal memory to be used in the pipeline. diff --git a/src/algorithm/AutoParameters.hpp b/src/algorithm/AutoParameters.hpp index cd8eff81..14d87cd1 100644 --- a/src/algorithm/AutoParameters.hpp +++ b/src/algorithm/AutoParameters.hpp @@ -158,6 +158,27 @@ void autoParametersLiEntropy(APRParameters& par, } + +template +struct MinMax{T min; T max; }; + +template +static MinMax getMinMax(const PixelData& input_image) { + T minVal = std::numeric_limits::max(); + T maxVal = std::numeric_limits::min(); + +#ifdef HAVE_OPENMP +#pragma omp parallel for default(shared) reduction(max:maxVal) reduction(min:minVal) +#endif + for (size_t i = 0; i < input_image.mesh.size(); ++i) { + const T val = input_image.mesh[i]; + if (val > maxVal) maxVal = val; + if (val < minVal) minVal = val; + } + + return MinMax{minVal, maxVal}; +} + /** * Compute bspline offset for APRConverter of integer type ImageType */ From 52f5f9aef8beed7b8901302769eaefdd09cc55b5 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 15:58:45 +0100 Subject: [PATCH 15/47] bump vcpkg --- vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg b/vcpkg index d72783cb..a3252282 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit d72783cb3aeddfd667861caef1060e54ca6fa7a9 +Subproject commit a325228200d7f229f3337e612e0077f2a5307090 From e303f19bb5c9cfec314027929b554a7ea15c9408 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:07:20 +0100 Subject: [PATCH 16/47] add brew install pkg-config in macos workflow --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 43e86178..474277b5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -64,7 +64,7 @@ jobs: - name: Install OpenMP dependencies with brew for OSX if: contains(matrix.os,'macos') - run: brew install libomp #todo caching + run: brew install libomp pkg-config #todo caching - name: Show content of workspace after cache has been restored run: find $RUNNER_WORKSPACE From 10cb3eaba8c2da9c7b219933d0b1e80face4a842 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:14:54 +0100 Subject: [PATCH 17/47] bump action versions --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 474277b5..f4b88d2a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -37,7 +37,7 @@ jobs: VCPKG_ROOT: ${{ github.workspace }}/vcpkg steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true @@ -45,7 +45,7 @@ jobs: - uses: lukka/get-cmake@latest # Restore both vcpkg and its artifacts from the GitHub cache service. - name: Restore vcpkg and its artifacts. - uses: actions/cache@v2 + uses: actions/cache@v3 with: # The first path is where vcpkg generates artifacts while consuming the vcpkg.json manifest file. # The second path is the location of vcpkg (it contains the vcpkg executable and data files). From 01f2f1f2f433452519d25f4b7e2b524344156cd6 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:25:01 +0100 Subject: [PATCH 18/47] add --output-on-failure flag to ctest command --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f4b88d2a..a56bee2f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -85,7 +85,7 @@ jobs: # Run tests - name: tests run: | - ctest --test-dir "${{ env.CMAKE_BUILD_DIR }}" + ctest --test-dir "${{ env.CMAKE_BUILD_DIR }}" --output-on-failure - name: Show content of workspace at its completion run: find $RUNNER_WORKSPACE From ec057d4b6f9d85fc2c2050c79e2f94f0396b8ff6 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:29:30 +0100 Subject: [PATCH 19/47] fix duplicate option --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a56bee2f..3938a8e6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -75,7 +75,7 @@ jobs: # Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json. - name: Install dependencies and generate project files run: | - cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} + cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_GTEST=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} # Build the whole project with Ninja (which is spawn by CMake). - name: Build From c9f508eb8ba3769e97878b514a7d3ee8fe1597a1 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:43:09 +0100 Subject: [PATCH 20/47] bump blosc submodule --- external/c-blosc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/c-blosc b/external/c-blosc index 5352508a..77be44a5 160000 --- a/external/c-blosc +++ b/external/c-blosc @@ -1 +1 @@ -Subproject commit 5352508a420bec865c57cda116a5e5303df898d2 +Subproject commit 77be44a58da10b2261c346b514878ba4d5c020e4 From 99fd77b776a2ef6f1671bf409422ffa599ccbfd9 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 16:43:21 +0100 Subject: [PATCH 21/47] bump gtest submodule --- external/gtest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/gtest b/external/gtest index 6b74da47..7a7231c4 160000 --- a/external/gtest +++ b/external/gtest @@ -1 +1 @@ -Subproject commit 6b74da4757a549563d7c37c8fae3e704662a043b +Subproject commit 7a7231c442484be389fdf01594310349ca0e42a8 From ad548b21dd0dff06859c8cc34731dc8e999583ce Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 20 Feb 2023 17:25:49 +0100 Subject: [PATCH 22/47] try downloading gtest in config instead of using submodule --- CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4912458..eff8db7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,12 +360,22 @@ if(APR_TESTS) if(GTEST_FOUND) include_directories(${GTEST_INCLUDE_DIRS}) else(GTEST_FOUND) + message(STATUS "APR: GTest not found, it will be downloaded and built") + + include(FetchContent) + FetchContent_Declare( + googletest + # Specify the commit you depend on and update it regularly. + URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip + ) + + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) - set(BUILD_GTEST ON CACHE BOOL "" FORCE) set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - message(STATUS "APR: GTest not found, using internal gtest") - add_subdirectory("external/gtest") - set(GTEST_LIBRARIES gtest) + FetchContent_MakeAvailable(googletest) + + set(GTEST_LIBRARIES GTest::gtest_main) endif(GTEST_FOUND) enable_testing() From b86b6f6e0e98169e87cc2ce11830a57afdca2a63 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 21 Feb 2023 00:18:14 +0100 Subject: [PATCH 23/47] bump minimum cmake version to 3.10 -> 3.14 required for `FetchContent_MakeAvailable` when building gtest --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eff8db7a..0e5615de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ ############################################################################### # APR - Adaptive Particle Representation ############################################################################### -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) project(APR DESCRIPTION "Adaptive Particle Representation library") message(STATUS "CMAKE VERSION ${CMAKE_VERSION}") From e6cf415172f974ad1bf1c9eb88fe7cf2bc2a4f6d Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 21 Feb 2023 00:23:13 +0100 Subject: [PATCH 24/47] set cmake policy CMP0135 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e5615de..81db1a84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ message(STATUS "CMAKE VERSION ${CMAKE_VERSION}") set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif(POLICY CMP0135) + # APR build options: option(APR_INSTALL "Install APR library" OFF) option(APR_BUILD_SHARED_LIB "Builds shared library" OFF) From 10d9f67d82e9df81d7da60a1ee301a1021768a1a Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 21 Feb 2023 00:32:01 +0100 Subject: [PATCH 25/47] set CMAKE_BUILD_TYPE to Release --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3938a8e6..e043da6d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -75,7 +75,7 @@ jobs: # Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json. - name: Install dependencies and generate project files run: | - cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_GTEST=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} + cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_GTEST=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} # Build the whole project with Ninja (which is spawn by CMake). - name: Build From 0e5916c55a7b8a8184849863c578372ccd21906c Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 21 Feb 2023 11:44:40 +0100 Subject: [PATCH 26/47] revert to old behaviour (not setting APR_PREFER_EXTERNAL_GTEST) --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e043da6d..c737eaa1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -75,7 +75,7 @@ jobs: # Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json. - name: Install dependencies and generate project files run: | - cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_PREFER_EXTERNAL_GTEST=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} + cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON -DAPR_USE_CUDA=OFF -DAPR_PREFER_EXTERNAL_BLOSC=${{ matrix.extblosc }} -DAPR_USE_OPENMP=${{ matrix.openmp }} ${{ matrix.buildargs }} # Build the whole project with Ninja (which is spawn by CMake). - name: Build From f3138d67944b5d83334ba09a8af5aecfbec7784a Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 21 Feb 2023 11:51:02 +0100 Subject: [PATCH 27/47] remove submodule gtest If not externally available, gtest is downlaoded and built using CMake's FetchContent --- .gitmodules | 3 --- external/gtest | 1 - 2 files changed, 4 deletions(-) delete mode 160000 external/gtest diff --git a/.gitmodules b/.gitmodules index e08c9430..09d41da6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "external/glm"] path = external/glm url = https://github.com/g-truc/glm.git -[submodule "external/gtest"] - path = external/gtest - url = https://github.com/google/googletest [submodule "external/c-blosc"] path = external/c-blosc url = https://github.com/Blosc/c-blosc diff --git a/external/gtest b/external/gtest deleted file mode 160000 index 7a7231c4..00000000 --- a/external/gtest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7a7231c442484be389fdf01594310349ca0e42a8 From 98ea8eee2c2d6542bb102bc4848ac2294c135d81 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Wed, 22 Feb 2023 16:31:46 +0100 Subject: [PATCH 28/47] add parameters to copy constructor --- src/data_structures/APR/APR.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data_structures/APR/APR.hpp b/src/data_structures/APR/APR.hpp index 80549843..b2b34fd5 100644 --- a/src/data_structures/APR/APR.hpp +++ b/src/data_structures/APR/APR.hpp @@ -192,6 +192,7 @@ class APR { tree_initialized = apr2copy.tree_initialized; apr_initialized = apr2copy.apr_initialized; name = apr2copy.name; + parameters = apr2copy.parameters; //old data structures apr_access = apr2copy.apr_access; From b3f4409bdf16a9fb426a056e468944d0825d1cd9 Mon Sep 17 00:00:00 2001 From: Joel Jonsson <38280105+joeljonsson@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:26:52 +0100 Subject: [PATCH 29/47] rerun workflow From 10ab24a2a08a79246b52e931b3a0e4bf6cb8f2f4 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 5 Sep 2023 14:13:45 +0200 Subject: [PATCH 30/47] empty From d9609174b93068ca11b4de00a07b427fd5db00ba Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 16:26:15 +0200 Subject: [PATCH 31/47] bump vcpkg --- vcpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg b/vcpkg index a3252282..486a4640 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit a325228200d7f229f3337e612e0077f2a5307090 +Subproject commit 486a4640db740f5994e492eb60748111dfc48de7 From d22017180fc0debb52367f34f0fe01585265fe0c Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 16:26:57 +0200 Subject: [PATCH 32/47] add vcpkg baseline ref --- vcpkg.json | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index f7b8b7f0..5a553b4a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,10 +2,20 @@ "name": "libapr", "version-string": "0.0.1", "dependencies": [ - "blosc", - "hdf5", - "szip", - "gtest", - "tiff" - ] -} \ No newline at end of file + { + "name": "blosc" + }, + { + "name": "hdf5", + "version>=": "1.8.20" + }, + { + "name": "szip" + }, + { + "name": "tiff", + "version>=": "4.0" + } + ], + "builtin-baseline": "486a4640db740f5994e492eb60748111dfc48de7" +} From bb90fa389ec9941f47ee3eef8ed5aa117fd2825d Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 16:42:21 +0200 Subject: [PATCH 33/47] update hdf5 version in vcpkg manifest --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 5a553b4a..6003653b 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -7,7 +7,7 @@ }, { "name": "hdf5", - "version>=": "1.8.20" + "version>=": "1.12.2" }, { "name": "szip" From e9eb89d1b70b13b3e95e260c3f285532001c56d9 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 16:42:45 +0200 Subject: [PATCH 34/47] update package version --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 6003653b..7685cfd9 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "libapr", - "version-string": "0.0.1", + "version-string": "2.1.0", "dependencies": [ { "name": "blosc" From 4dca4f9025e7410b6469356af9b16eb264cc8f0d Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 16:54:31 +0200 Subject: [PATCH 35/47] update tiff version in vcpkg manifest --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 7685cfd9..aac24396 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -14,7 +14,7 @@ }, { "name": "tiff", - "version>=": "4.0" + "version>=": "4.6.0" } ], "builtin-baseline": "486a4640db740f5994e492eb60748111dfc48de7" From 6853443e8831218a4d2030eae19c1530e257f2b7 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 17:41:16 +0200 Subject: [PATCH 36/47] bump checkout action --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index c737eaa1..6c7c3f83 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -37,7 +37,7 @@ jobs: VCPKG_ROOT: ${{ github.workspace }}/vcpkg steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true From 1e27c7abac0b8276bd4f13e02fb4c953958b935d Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 18:16:38 +0200 Subject: [PATCH 37/47] remove version specification for dependencies --- vcpkg.json | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/vcpkg.json b/vcpkg.json index aac24396..193ac9b0 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,20 +2,10 @@ "name": "libapr", "version-string": "2.1.0", "dependencies": [ - { - "name": "blosc" - }, - { - "name": "hdf5", - "version>=": "1.12.2" - }, - { - "name": "szip" - }, - { - "name": "tiff", - "version>=": "4.6.0" - } + "blosc", + "hdf5", + "szip", + "tiff" ], "builtin-baseline": "486a4640db740f5994e492eb60748111dfc48de7" } From e31ad7e91029900e3c353b39a3fbbebd5c109f8d Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 20:00:12 +0200 Subject: [PATCH 38/47] make iterator comparison and pipeline_test_u16 more informative --- test/APRTest.cpp | 165 +++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 112 deletions(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index 9f2d990e..7bef03aa 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -123,106 +123,62 @@ class CreateGTSmall1DTest : public CreateAPRTest }; template -bool compare_two_iterators(Iterator1& it1, Iterator2& it2,bool success = true){ +bool compare_two_iterators(Iterator1& it1, Iterator2& it2, int maxNumOfErrPrinted = 10){ - if(it1.total_number_particles() != it2.total_number_particles()){ - success = false; - std::cout << "Number of particles mismatch" << std::endl; + if(it1.total_number_particles() != it2.total_number_particles()) { + std::cout << "Number of particles mismatch: " << it1.total_number_particles() " vs " << it2.total_number_particles() << std::endl; + return false; } uint64_t counter_1 = 0; uint64_t counter_2 = 0; - for (int level = it1.level_min(); level <= it1.level_max(); ++level) { - int z = 0; - int x = 0; + uint64_t errors = 0; - for (z = 0; z < it1.z_num(level); z++) { - for (x = 0; x < it1.x_num(level); ++x) { + for (int level = it1.level_min(); level <= it1.level_max(); ++level) { + for (int z = 0; z < it1.z_num(level); z++) { + for (int x = 0; x < it1.x_num(level); ++x) { it2.begin(level, z, x); - for (it1.begin(level, z, x); it1 < it1.end(); - it1++) { + for (it1.begin(level, z, x); it1 < it1.end(); it1++) { counter_1++; - if(it1 != it1){ - - uint64_t new_index = it1; - uint64_t org_index = it2; - - (void) new_index; - (void) org_index; - - - success = false; -// std::cout << "1" << std::endl; - } - - if(it1.y() != it2.y()){ - - auto y_new = it1.y(); - auto y_org = it2.y(); - - (void) y_new; - (void) y_org; - - success = false; -// std::cout << "y_new" << y_new << std::endl; -// std::cout << "y_org" << y_org << std::endl; + if( (it1 != it2) || (it1.y() != it2.y()) ){ + if(errors < maxNumOfErrPrinted || maxNumOfErrPrinted == -1) { + std::cout << "iterator mismatch, idx " << (uint64_t) it1 << " vs " << (uint64_t) it2 << ", y value " << it2.y() << " vs " << it1.y() << std::endl; + } + errors++; } if(it2 < it2.end()){ it2++; } - } } } } - - for (int level = it2.level_min(); level <= it2.level_max(); ++level) { - int z = 0; - int x = 0; - - for (z = 0; z < it2.z_num(level); z++) { - for (x = 0; x < it2.x_num(level); ++x) { + for (int z = 0; z < it2.z_num(level); z++) { + for (int x = 0; x < it2.x_num(level); ++x) { it1.begin(level, z, x); - for (it2.begin(level, z, x); it2 < it2.end(); - it2++) { + for (it2.begin(level, z, x); it2 < it2.end(); it2++) { counter_2++; - if(it1 != it1){ - - uint64_t new_index = it1; - uint64_t org_index = it2; - - (void) new_index; - (void) org_index; - - - success = false; - } - - if(it1.y() != it2.y()){ - - auto y_new = it1.y(); - auto y_org = it2.y(); - - (void) y_new; - (void) y_org; - - success = false; + if( (it1 != it2) || (it1.y() != it2.y()) ){ + if(errors < maxNumOfErrPrinted || maxNumOfErrPrinted == -1) { + std::cout << "iterator mismatch, idx " << (uint64_t) it1 << " vs " << (uint64_t) it2 << " y value " << it1.y() << " vs " << it2.y() << std::endl; + } + errors++; } - if(it1 < it1.end()){ + if(it1 < it1.end()) { it1++; } @@ -231,13 +187,12 @@ bool compare_two_iterators(Iterator1& it1, Iterator2& it2,bool success = true){ } } - if(counter_1 != counter_2){ - success = false; + if((counter_1 != counter_2) || (errors > 0)){ std::cout << "Iteration mismatch" << std::endl; + return false; } - - return success; + return true; } bool check_neighbours(APR& apr,APRIterator ¤t, APRIterator &neigh){ @@ -870,9 +825,9 @@ bool test_pulling_scheme_sparse(TestData& test_data){ auto sparse_lin_it = apr_lin_sparse.iterator(); - success = compare_two_iterators(org_it,sparse_it,success); - success = compare_two_iterators(sparse_lin_it,sparse_it,success); - success = compare_two_iterators(org_it,sparse_lin_it,success); + success = success && compare_two_iterators(org_it, sparse_it); + success = success && compare_two_iterators(sparse_lin_it, sparse_it); + success = success && compare_two_iterators(org_it, sparse_lin_it); return success; } @@ -973,12 +928,12 @@ bool test_linear_access_create(TestData& test_data) { //apr_lin.init_linear(); auto it_new = apr_lin.iterator(); - success = compare_two_iterators(it_lin_old,it_new,success); + success = success && compare_two_iterators(it_lin_old, it_new); //Test Linear -> Random generation auto it_new_random = apr_lin.random_iterator(); - success = compare_two_iterators(it_new_random,it_new,success); + success = success && compare_two_iterators(it_new_random, it_new); //Test the APR Tree construction. @@ -992,7 +947,7 @@ bool test_linear_access_create(TestData& test_data) { std::cout << "PARTS: " << total_number_parts << " " << total_number_parts_lin << std::endl; - success = compare_two_iterators(tree_it_org,tree_it_lin,success); + success = success && compare_two_iterators(tree_it_org, tree_it_lin); return success; @@ -1298,16 +1253,16 @@ bool test_linear_access_io(TestData& test_data) { auto it_new = apr_lin.iterator(); auto it_read = test_data.apr.iterator(); - success = compare_two_iterators(it_org,it_new,success); - success = compare_two_iterators(it_org,it_read,success); - success = compare_two_iterators(it_new,it_read,success); + success = success && compare_two_iterators(it_org, it_new); + success = success && compare_two_iterators(it_org, it_read); + success = success && compare_two_iterators(it_new, it_read); // Test the tree IO auto tree_it_org = apr_random.random_tree_iterator(); auto tree_it_lin = apr_lin.tree_iterator(); - success = compare_two_iterators(tree_it_org,tree_it_lin,success); + success = success && compare_two_iterators(tree_it_org, tree_it_lin); return success; } @@ -1325,11 +1280,11 @@ bool test_apr_tree(TestData& test_data) { auto it_lin = test_data.apr.iterator(); auto it_random = test_data.apr.random_iterator(); - success = compare_two_iterators(it_lin,it_random,success); + success = success && compare_two_iterators(it_lin, it_random); auto it_tree_t = test_data.apr.random_tree_iterator(); - success = compare_two_iterators(it_lin,it_random,success); + success = success && compare_two_iterators(it_lin, it_random); ParticleData tree_data; @@ -1338,7 +1293,7 @@ bool test_apr_tree(TestData& test_data) { auto apr_tree_iterator = test_data.apr.random_tree_iterator(); auto apr_tree_iterator_lin = test_data.apr.tree_iterator(); - success = compare_two_iterators(apr_tree_iterator,apr_tree_iterator_lin,success); + success = success && compare_two_iterators(apr_tree_iterator, apr_tree_iterator_lin); for (int level = (apr_tree_iterator.level_max()); level >= apr_tree_iterator.level_min(); --level) { @@ -1620,7 +1575,7 @@ bool test_apr_file(TestData& test_data){ auto apr_iterator = test_data.apr.iterator(); auto apr_iterator_read = aprRead.iterator(); - success = compare_two_iterators(apr_iterator,apr_iterator_read,success); + success = success && compare_two_iterators(apr_iterator, apr_iterator_read); //test apr iterator with channel writeFile.open(file_name,"WRITE"); @@ -1662,11 +1617,11 @@ bool test_apr_file(TestData& test_data){ auto it1 = apr_channel_0.iterator(); auto it2 = test_data.apr.iterator(); - success = compare_two_iterators(it1,it2,success); + success = success && compare_two_iterators(it1, it2); it1 = apr_channel_0_55.iterator(); it2 = test_data.apr.iterator(); - success = compare_two_iterators(it1,it2,success); + success = success && compare_two_iterators(it1, it2); @@ -1710,7 +1665,7 @@ bool test_apr_file(TestData& test_data){ auto tree_it = aprRead2.random_tree_iterator(); auto tree_it_org = test_data.apr.random_tree_iterator(); - success = compare_two_iterators(tree_it,tree_it_org,success); + success = success && compare_two_iterators(tree_it, tree_it_org); //Test file list std::vector correct_names = {"tree_parts","tree_parts1","tree_parts2"}; @@ -2819,8 +2774,6 @@ bool test_pipeline_u16(TestData& test_data){ // // - bool success = true; - //the apr datastructure APR apr; APRConverter aprConverter; @@ -2855,34 +2808,26 @@ bool test_pipeline_u16(TestData& test_data){ PixelData scale_saved = TiffUtils::getMesh(test_data.output_dir + "scale_saved.tif"); PixelData gradient_saved = TiffUtils::getMesh(test_data.output_dir + "gradient_saved.tif"); - for (size_t i = 0; i < scale_computed.mesh.size(); ++i) { - float computed_val = scale_computed.mesh[i]; - float saved_val = scale_saved.mesh[i]; + std::cout << "comparing local intensity scales" << std::endl; + int scale_errors = compareMeshes(scale_saved, scale_computed); + std::cout << "errors: " << scale_errors << " out of " << scale_saved.size() << std::endl; - if(std::abs(computed_val - saved_val) > 1){ - success = false; - } - } + std::cout << "comparing gradients" << std::endl; + int grad_errors = compareMeshes(scale_saved, scale_computed); + std::cout << "errors: " << grad_errors << " out of " << scale_saved.size() << std::endl; - for (size_t i = 0; i < gradient_computed.mesh.size(); ++i) { - float computed_val = gradient_computed.mesh[i]; - float saved_val = gradient_saved.mesh[i]; - - if(std::abs(computed_val - saved_val) > 1){ - success = false; - } - } + bool success = (scale_errors == 0) && (grad_errors == 0); APR apr_c; aprConverter.initPipelineAPR(apr_c, test_data.img_original); - aprConverter.get_apr_custom_grad_scale(apr_c,gradient_saved,scale_saved); + aprConverter.get_apr_custom_grad_scale(apr_c, gradient_saved, scale_saved); auto it_org = test_data.apr.iterator(); auto it_gen = apr_c.iterator(); //test the access - success = compare_two_iterators(it_org,it_gen,success); + success = success && compare_two_iterators(it_org, it_gen); ParticleData particles_intensities; @@ -3423,16 +3368,12 @@ bool test_iterator_methods(TestData &test_data){ bool test_apr_copy(TestData &test_data){ - bool success = true; - APR aprCopy(test_data.apr); auto it_org = test_data.apr.iterator(); auto it_copy = aprCopy.iterator(); - success = compare_two_iterators(it_org,it_copy,success); - - return success; + return compare_two_iterators(it_org, it_copy); } From dd1dfb3c0cf194a28e0ac7eaef0615ff229115cc Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 20:14:35 +0200 Subject: [PATCH 39/47] fix error --- test/APRTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index 7bef03aa..13624b24 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -127,7 +127,7 @@ bool compare_two_iterators(Iterator1& it1, Iterator2& it2, int maxNumOfErrPrinte if(it1.total_number_particles() != it2.total_number_particles()) { - std::cout << "Number of particles mismatch: " << it1.total_number_particles() " vs " << it2.total_number_particles() << std::endl; + std::cout << "Number of particles mismatch: " << it1.total_number_particles() << " vs " << it2.total_number_particles() << std::endl; return false; } From f2247d9469b04aab83049a6207eb75fba80a670c Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 20:22:38 +0200 Subject: [PATCH 40/47] increase compareMeshes error threshold for u16 pipeline test --- test/APRTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index 13624b24..a4f9f3a2 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -2809,11 +2809,11 @@ bool test_pipeline_u16(TestData& test_data){ PixelData gradient_saved = TiffUtils::getMesh(test_data.output_dir + "gradient_saved.tif"); std::cout << "comparing local intensity scales" << std::endl; - int scale_errors = compareMeshes(scale_saved, scale_computed); + int scale_errors = compareMeshes(scale_saved, scale_computed, 0.5); std::cout << "errors: " << scale_errors << " out of " << scale_saved.size() << std::endl; std::cout << "comparing gradients" << std::endl; - int grad_errors = compareMeshes(scale_saved, scale_computed); + int grad_errors = compareMeshes(scale_saved, scale_computed, 0.5); std::cout << "errors: " << grad_errors << " out of " << scale_saved.size() << std::endl; bool success = (scale_errors == 0) && (grad_errors == 0); From fba2358f298857a2b694fcf525b4c580293e20ef Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 22:43:57 +0200 Subject: [PATCH 41/47] actually check gradient --- test/APRTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index a4f9f3a2..f2d7a70a 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -2809,12 +2809,12 @@ bool test_pipeline_u16(TestData& test_data){ PixelData gradient_saved = TiffUtils::getMesh(test_data.output_dir + "gradient_saved.tif"); std::cout << "comparing local intensity scales" << std::endl; - int scale_errors = compareMeshes(scale_saved, scale_computed, 0.5); + int scale_errors = compareMeshes(scale_saved, scale_computed, 1); std::cout << "errors: " << scale_errors << " out of " << scale_saved.size() << std::endl; std::cout << "comparing gradients" << std::endl; - int grad_errors = compareMeshes(scale_saved, scale_computed, 0.5); - std::cout << "errors: " << grad_errors << " out of " << scale_saved.size() << std::endl; + int grad_errors = compareMeshes(gradient_saved, gradient_computed, 1); + std::cout << "errors: " << grad_errors << " out of " << gradient_saved.size() << std::endl; bool success = (scale_errors == 0) && (grad_errors == 0); From fabc9ac6ddaa5ec3168c811f49a95da62777b997 Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Mon, 16 Oct 2023 23:24:51 +0200 Subject: [PATCH 42/47] remove duplicate printouts --- test/APRTest.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index f2d7a70a..3672a202 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -2808,13 +2808,11 @@ bool test_pipeline_u16(TestData& test_data){ PixelData scale_saved = TiffUtils::getMesh(test_data.output_dir + "scale_saved.tif"); PixelData gradient_saved = TiffUtils::getMesh(test_data.output_dir + "gradient_saved.tif"); - std::cout << "comparing local intensity scales" << std::endl; + std::cout << "Comparing local intensity scales" << std::endl; int scale_errors = compareMeshes(scale_saved, scale_computed, 1); - std::cout << "errors: " << scale_errors << " out of " << scale_saved.size() << std::endl; - std::cout << "comparing gradients" << std::endl; + std::cout << "Comparing gradients" << std::endl; int grad_errors = compareMeshes(gradient_saved, gradient_computed, 1); - std::cout << "errors: " << grad_errors << " out of " << gradient_saved.size() << std::endl; bool success = (scale_errors == 0) && (grad_errors == 0); From c94ed44a01f76eaf42e1f7599a210dde3aad713b Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 17 Oct 2023 00:12:37 +0200 Subject: [PATCH 43/47] make bspline_offset public --- src/algorithm/APRConverter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithm/APRConverter.hpp b/src/algorithm/APRConverter.hpp index d72b2f0b..3f8c1271 100644 --- a/src/algorithm/APRConverter.hpp +++ b/src/algorithm/APRConverter.hpp @@ -99,6 +99,8 @@ class APRConverter { return true; } + float bspline_offset = 0; + protected: template @@ -108,8 +110,6 @@ class APRConverter { //get apr without setting parameters, and with an already loaded image. - float bspline_offset = 0; - //DATA (so it can be re-used) PixelData grad_temp; // should be a down-sampled image From 40e807b87e8d57f1cc4ae14a9c3f6a38286c61ca Mon Sep 17 00:00:00 2001 From: joeljonsson Date: Tue, 17 Oct 2023 00:15:10 +0200 Subject: [PATCH 44/47] reset bspline_offset before computing APR with saved grad and lis --- test/APRTest.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/APRTest.cpp b/test/APRTest.cpp index 3672a202..5f909933 100644 --- a/test/APRTest.cpp +++ b/test/APRTest.cpp @@ -2784,12 +2784,9 @@ bool test_pipeline_u16(TestData& test_data){ aprConverter.par.Ip_th = 0; aprConverter.par.rel_error = readPars.rel_error; aprConverter.par.lambda = readPars.lambda; - aprConverter.par.sigma_th_max = readPars.sigma_th_max; aprConverter.par.sigma_th = readPars.sigma_th; - aprConverter.par.grad_th = readPars.grad_th; - aprConverter.par.auto_parameters = false; //where things are @@ -2817,8 +2814,8 @@ bool test_pipeline_u16(TestData& test_data){ bool success = (scale_errors == 0) && (grad_errors == 0); APR apr_c; + aprConverter.bspline_offset = 0; aprConverter.initPipelineAPR(apr_c, test_data.img_original); - aprConverter.get_apr_custom_grad_scale(apr_c, gradient_saved, scale_saved); auto it_org = test_data.apr.iterator(); From c6c627e920050391f38e5bf51ff0dfce57b36b8b Mon Sep 17 00:00:00 2001 From: Bevan Cheeseman Date: Fri, 3 Nov 2023 14:57:23 +0000 Subject: [PATCH 45/47] Interactive debug --- .github/workflows/cmake.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6c7c3f83..3e905ffe 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -82,6 +82,9 @@ jobs: run: | cmake --build "${{ env.CMAKE_BUILD_DIR }}" --parallel 4 --config Release + - name: Setup upterm session + uses: lhotari/action-upterm@v1 + # Run tests - name: tests run: | From d8a471ecadde42fe962877d4da8055265413da80 Mon Sep 17 00:00:00 2001 From: Bevan Cheeseman Date: Fri, 3 Nov 2023 15:03:55 +0000 Subject: [PATCH 46/47] Update cmake.yml --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3e905ffe..2e0ff392 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -82,6 +82,7 @@ jobs: run: | cmake --build "${{ env.CMAKE_BUILD_DIR }}" --parallel 4 --config Release + - name: Setup upterm session uses: lhotari/action-upterm@v1 From c37416a170ab039af1587fe637be8a2e5f16d4b2 Mon Sep 17 00:00:00 2001 From: Bevan Cheeseman Date: Fri, 3 Nov 2023 15:17:51 +0000 Subject: [PATCH 47/47] Change out to tmate action --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2e0ff392..8050dce7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -83,8 +83,8 @@ jobs: cmake --build "${{ env.CMAKE_BUILD_DIR }}" --parallel 4 --config Release - - name: Setup upterm session - uses: lhotari/action-upterm@v1 + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 # Run tests - name: tests