From adba156763b8317ba1f6d3bc6cf232c867638fa3 Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 3 Jan 2023 14:56:56 -0500 Subject: [PATCH 1/3] Fix: Tdi SPREAD function does not work on scalars The TDI SPREAD and REPLICATE functions were treating the pointer 'pa' as an array descriptor, while it was copied from a scalar descriptor. Instead just copy the first sizeof(struct descriptor) bytes, and at the bottom of Tdi1Trans Build the array descriptor that we want. --- tdishr/TdiTrans.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tdishr/TdiTrans.c b/tdishr/TdiTrans.c index 90c6c24dc7..445fe185e3 100644 --- a/tdishr/TdiTrans.c +++ b/tdishr/TdiTrans.c @@ -327,8 +327,15 @@ int Tdi1Trans(int opcode, int narg, mdsdsc_t *list[], mdsdsc_xd_t *out_ptr) } pmask = (mdsdsc_t *)&ncopies; /** scalar to simple vector **/ - if (rank == 0) - memcpy((char *)&arr, (char *)pa, head); + if (rank == 0) { + memcpy((char *)&arr, (char *)pa, sizeof(struct descriptor)); + arr.dimct = 1; + arr.aflags.coeff = 0; + arr.a0 = arr.pointer; + arr.arsize = arr.length; + arr.m[1] = arr.m[0] = 1; + arr.m[dim] = ncopies; + } else if (rank >= MAX_DIMS) status = TdiNDIM_OVER; /** coefficient vector **/ From a34858e88b68c0fe69c05b26dc1a46ed892bdd7e Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Tue, 3 Jan 2023 15:56:41 -0500 Subject: [PATCH 2/3] Fix: Same fix for REPLICATE as SPREAD --- tdishr/TdiTrans.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tdishr/TdiTrans.c b/tdishr/TdiTrans.c index 445fe185e3..175a72d5b5 100644 --- a/tdishr/TdiTrans.c +++ b/tdishr/TdiTrans.c @@ -291,8 +291,15 @@ int Tdi1Trans(int opcode, int narg, mdsdsc_t *list[], mdsdsc_xd_t *out_ptr) psig->dimensions[dim] = 0; pmask = (mdsdsc_t *)&ncopies; /** scalar to simple vector **/ - if (rank == 0) - memcpy((char *)&arr, (char *)pa, head); + if (rank == 0) { + memcpy((char *)&arr, (char *)pa, sizeof(struct descriptor)); + arr.dimct = 1; + arr.aflags.coeff = 0; + arr.a0 = arr.pointer; + arr.arsize = arr.length; + arr.m[1] = arr.m[0] = 1; + arr.m[dim] = ncopies; + } /** simple and coefficient vector **/ else { From 2c6a6ff576ff5e41999b1ecba3dba802c36558da Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Wed, 4 Jan 2023 15:25:11 -0500 Subject: [PATCH 3/3] Fix: style as per slw --- tdishr/TdiTrans.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tdishr/TdiTrans.c b/tdishr/TdiTrans.c index 175a72d5b5..76307dfbba 100644 --- a/tdishr/TdiTrans.c +++ b/tdishr/TdiTrans.c @@ -297,7 +297,8 @@ int Tdi1Trans(int opcode, int narg, mdsdsc_t *list[], mdsdsc_xd_t *out_ptr) arr.aflags.coeff = 0; arr.a0 = arr.pointer; arr.arsize = arr.length; - arr.m[1] = arr.m[0] = 1; + arr.m[0] = 1; + arr.m[1] = 1; arr.m[dim] = ncopies; } /** simple and coefficient vector **/ @@ -340,7 +341,8 @@ int Tdi1Trans(int opcode, int narg, mdsdsc_t *list[], mdsdsc_xd_t *out_ptr) arr.aflags.coeff = 0; arr.a0 = arr.pointer; arr.arsize = arr.length; - arr.m[1] = arr.m[0] = 1; + arr.m[0] = 1; + arr.m[1] = 1; arr.m[dim] = ncopies; } else if (rank >= MAX_DIMS) @@ -366,7 +368,8 @@ int Tdi1Trans(int opcode, int narg, mdsdsc_t *list[], mdsdsc_xd_t *out_ptr) arr.dimct = 2; arr.aflags.coeff = 1; arr.a0 = arr.pointer; - arr.m[1] = arr.m[0] = (int)pa->arsize / (int)pa->length; + arr.m[0] = (int)pa->arsize / (int)pa->length; + arr.m[1] = arr.m[0]; arr.m[dim] = ncopies; } arr.arsize *= ncopies;