From f78633b8c38a99d499e5081fbb810f77b1abac08 Mon Sep 17 00:00:00 2001 From: oguyon Date: Wed, 14 Aug 2024 00:57:21 -1000 Subject: [PATCH] set3Daxes --- .../linalgebra/scripts/milk-modes-project-U | 1 + src/COREMOD_arith/CMakeLists.txt | 4 +- src/COREMOD_arith/COREMOD_arith.c | 4 +- .../{image_set_axes.c => image_set_3Daxes.c} | 67 ++++++++++++++----- src/COREMOD_arith/image_set_3Daxes.h | 13 ++++ src/COREMOD_arith/image_set_axes.h | 13 ---- 6 files changed, 67 insertions(+), 35 deletions(-) rename src/COREMOD_arith/{image_set_axes.c => image_set_3Daxes.c} (67%) create mode 100644 src/COREMOD_arith/image_set_3Daxes.h delete mode 100644 src/COREMOD_arith/image_set_axes.h diff --git a/plugins/milk-extra-src/linalgebra/scripts/milk-modes-project-U b/plugins/milk-extra-src/linalgebra/scripts/milk-modes-project-U index d2c52fe7..d8c958c9 100755 --- a/plugins/milk-extra-src/linalgebra/scripts/milk-modes-project-U +++ b/plugins/milk-extra-src/linalgebra/scripts/milk-modes-project-U @@ -45,6 +45,7 @@ outimres="${inputMSargARRAY[3]}" milk-all << EOF loadfits "$immA" modesA loadfits "$immB" modesB +set3Daxes modesB 0 0 0 linalg.sgemm .GPUdevice ${GPUindex} linalg.sgemm .transpA 1 linalg.sgemm modesA modesB mcoeff diff --git a/src/COREMOD_arith/CMakeLists.txt b/src/COREMOD_arith/CMakeLists.txt index ccc0aebc..f0d7b0dd 100644 --- a/src/COREMOD_arith/CMakeLists.txt +++ b/src/COREMOD_arith/CMakeLists.txt @@ -15,7 +15,7 @@ set(SOURCEFILES image_pixunmap.c image_set_1Dpixrange.c image_set_2Dpix.c - image_set_axes.c + image_set_3Daxes.c image_set_col.c image_set_row.c image_setzero.c @@ -44,7 +44,7 @@ set(INCLUDEFILES image_pixunmap.h image_set_1Dpixrange.h image_set_2Dpix.h - image_set_axes.h + image_set_3Daxes.h image_set_col.h image_set_row.h image_setzero.h diff --git a/src/COREMOD_arith/COREMOD_arith.c b/src/COREMOD_arith/COREMOD_arith.c index 8e5a2f64..097b1918 100644 --- a/src/COREMOD_arith/COREMOD_arith.c +++ b/src/COREMOD_arith/COREMOD_arith.c @@ -59,7 +59,7 @@ #include "image_set_1Dpixrange.h" #include "image_set_2Dpix.h" -#include "image_set_axes.h" +#include "image_set_3Daxes.h" #include "image_set_col.h" #include "image_set_row.h" #include "image_setzero.h" @@ -106,7 +106,7 @@ static errno_t init_module_CLI() CLIADDCMD_COREMOD_arith__imset_1Dpixrange(); CLIADDCMD_COREMOD_arith__imset_2Dpix(); - CLIADDCMD_COREMOD_arith__imset_axes(); + CLIADDCMD_COREMOD_arith__imset_3Daxes(); CLIADDCMD_COREMOD_arith__imset_col(); CLIADDCMD_COREMOD_arith__imset_row(); CLIADDCMD_COREMOD_arith__imsetzero(); diff --git a/src/COREMOD_arith/image_set_axes.c b/src/COREMOD_arith/image_set_3Daxes.c similarity index 67% rename from src/COREMOD_arith/image_set_axes.c rename to src/COREMOD_arith/image_set_3Daxes.c index e93ea303..8cfe3e4a 100644 --- a/src/COREMOD_arith/image_set_axes.c +++ b/src/COREMOD_arith/image_set_3Daxes.c @@ -58,8 +58,8 @@ static CLICMDARGDEF farg[] = static CLICMDDATA CLIcmddata = { - "setaxes", - "set image axes size", + "set3Daxes", + "set 3D image axes size", CLICMD_FIELDS_DEFAULTS }; @@ -75,7 +75,7 @@ static errno_t help_function() -errno_t image_set_axes( +errno_t image_set_3Daxes( IMGID inimg, uint32_t imsize0, uint32_t imsize1, @@ -88,28 +88,60 @@ errno_t image_set_axes( long nelem = inimg.md->nelement; - long nelemout = imsize0; - nelemout *= imsize1; - if(imsize2 != 0) + // if size=0, adopt input size + + + + + uint32_t imsize0c = imsize0; + if(imsize0 == 0) { - nelemout *= imsize2; + imsize0c = inimg.md->size[0]; } - if(nelemout == nelem) + + uint32_t imsize1c = imsize1; + if(imsize1 == 0) { - inimg.md->size[0] = imsize0; - inimg.md->size[1] = imsize1; - if(imsize2 == 0) + if (inimg.md->naxis < 2) { - inimg.md->size[2] = 1; - inimg.md->naxis = 2; + // if 1D image, promote to 3D with size1 = 1 + imsize1c = 1; } else { - inimg.md->size[2] = imsize2; - inimg.md->naxis = 3; + imsize1c = inimg.md->size[1]; } } + + uint32_t imsize2c = imsize2; + if(imsize2 == 0) + { + if (inimg.md->naxis < 3) + { + // if 1D or 2D image, promote to 3D with size1 = 1 + imsize2c = 1; + } + else + { + imsize2c = inimg.md->size[2]; + } + } + + + + long nelemout = imsize0c; + nelemout *= imsize1c; + nelemout *= imsize2c; + + + if(nelemout == nelem) + { + inimg.md->naxis = 3; + inimg.md->size[0] = imsize0c; + inimg.md->size[1] = imsize1c; + inimg.md->size[2] = imsize2c; + } else { printf("total number of element (%ld) does not match input (%ld) - invalid sizes\n", nelemout, nelem); @@ -130,10 +162,9 @@ static errno_t compute_function() IMGID inimg = mkIMGID_from_name(inimname); resolveIMGID(&inimg, ERRMODE_ABORT); - INSERT_STD_PROCINFO_COMPUTEFUNC_START { - image_set_axes(inimg, *size0, *size1, *size2); + image_set_3Daxes(inimg, *size0, *size1, *size2); processinfo_update_output_stream(processinfo, inimg.ID); } @@ -153,7 +184,7 @@ INSERT_STD_FPSCLIfunctions // Register function in CLI errno_t -CLIADDCMD_COREMOD_arith__imset_axes() +CLIADDCMD_COREMOD_arith__imset_3Daxes() { INSERT_STD_CLIREGISTERFUNC diff --git a/src/COREMOD_arith/image_set_3Daxes.h b/src/COREMOD_arith/image_set_3Daxes.h new file mode 100644 index 00000000..b21607cd --- /dev/null +++ b/src/COREMOD_arith/image_set_3Daxes.h @@ -0,0 +1,13 @@ +#ifndef COREMOD_MODULE_ARITH_IMSET_3DAXES_H +#define COREMOD_MODULE_ARITH_IMSET_3DAXES_H + +errno_t image_set_3Daxes( + IMGID inimg, + uint32_t size0, + uint32_t size1, + uint32_t size2 +); + +errno_t CLIADDCMD_COREMOD_arith__imset_3Daxes(); + +#endif diff --git a/src/COREMOD_arith/image_set_axes.h b/src/COREMOD_arith/image_set_axes.h deleted file mode 100644 index b541a8da..00000000 --- a/src/COREMOD_arith/image_set_axes.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COREMOD_MODULE_ARITH_IMSET_AXES_H -#define COREMOD_MODULE_ARITH_IMSET_AXES_H - -errno_t image_set_axes( - IMGID inimg, - uint32_t size0, - uint32_t size1, - uint32_t size2 -); - -errno_t CLIADDCMD_COREMOD_arith__imset_axes(); - -#endif