From eb3320020c526725b0a693d6ca4d09e06033a004 Mon Sep 17 00:00:00 2001 From: Martin Uecker Date: Sun, 29 Sep 2024 13:05:24 +0200 Subject: [PATCH] style --- scripts/rtreco.sh | 24 +++++++++---------- src/bart.c | 8 ++++--- src/ccapply.c | 4 ++++ src/iter/batch_gen.c | 4 ++-- src/join.c | 4 ++-- src/misc/debug.c | 2 +- src/misc/mmio.c | 11 +++++---- src/misc/stream.c | 49 ++++++++++++++++++++++----------------- src/moba/iter_l1.c | 2 +- src/motion/interpolate.c | 12 +++++----- src/motion/pyramide.c | 4 ++-- src/networks/nnet.c | 5 ++-- src/nlops/const.c | 2 +- src/nlops/mi_metric.c | 12 ---------- src/nlops/nlop_jacobian.c | 12 +++++----- src/nlops/tenmul.c | 2 +- src/nn/init.c | 2 +- src/nn/losses.c | 4 ++-- src/nn/tf_wrapper.c | 2 +- src/nn/weights.c | 13 ++++++----- src/num/gpuops.c | 4 ++-- src/num/vecops.c | 12 +++++----- src/reshape.c | 32 +++++++++++-------------- src/simu/phantom.c | 4 ++-- src/tee.c | 6 +++-- 25 files changed, 119 insertions(+), 117 deletions(-) diff --git a/scripts/rtreco.sh b/scripts/rtreco.sh index 74884eb0b..1ba3ba9ef 100755 --- a/scripts/rtreco.sh +++ b/scripts/rtreco.sh @@ -6,7 +6,7 @@ # Authors: # 2024 Moritz Blumenthal # 2024 Philip Schaten - + set -e LOGFILE=/dev/stderr @@ -73,7 +73,7 @@ while getopts "hl:t:fRTp:SG" opt; do GEOM=true ;; \?) - echo "$usage" >&2 + echo "$usage" >&2 exit 1 ;; esac @@ -230,11 +230,11 @@ trajectory () ( #FIXME DEADLOCK: #> ksp_tmp.fifo & - + READ=$(($(bart show -d 1 meta0.fifo)/2)) PHS1=$(bart show -d 2 meta1.fifo) TOT=$(bart show -d 10 meta2.fifo) - + topts=(-o2 -r -D -l -x"$READ" -y"$PHS1" -t"$TURNS" -O) bart traj "${topts[@]}" trj_tmp @@ -249,7 +249,7 @@ trajectory () ( bart -t4 -r - estdelay -p10 -R -r2 -- trj_gd - predelay.fifo | \ delay 11 $DELAY $DELAY predelay.fifo postdelay.fifo & - + bart -t4 -r postdelay.fifo traj "${topts[@]}" -V postdelay.fifo -- - | \ bart reshape -s 1024 -- $(bart bitmask 2 10 11) $PHS1 $TOT 1 - $DST ) @@ -289,9 +289,9 @@ coilcompression_svd () ( bart tee tmp.fifo | \ bart reshape -s1024 -- $(bart bitmask 2 10) $((PHS*TURNS)) $((TOT/TURNS)) - - | \ bart -r - cc -M -- - predelay.fifo & - + delay 10 $DELAY $DELAY predelay.fifo cc.fifo & - + bart -r cc.fifo repmat -- 9 $TURNS cc.fifo - | \ bart reshape -s1024 -- $(bart bitmask 9 10) 1 $TOT - - | \ bart -r - ccapply -p$CHANNELS -- tmp.fifo - $DST @@ -334,7 +334,7 @@ coilcompression_svd_first () ( bart reshape -s1024 -- $(bart bitmask 2 10) $((PHS*TURNS)) $((TOT/TURNS)) - - | \ bart -r - cc -M -- - - | bart tee -n cc.fifo & - bart -l 1024 copy -- cc.fifo cc2 + bart -l 1024 copy -- cc.fifo cc2 bart -r tmp.fifo ccapply -p$CHANNELS -- tmp.fifo cc2 $DST ) @@ -400,7 +400,7 @@ coilcompression_rovir () ( cat ksp_tmp.fifo | \ bart tee tmp.fifo | \ bart reshape -s1024 -- $(bart bitmask 2 10) $((PHS*TURNS)) $((TOT/TURNS)) - ksp_rovir.fifo & - + cat $TRJ | \ bart -t4 -r - scale -- 2 - - | \ bart reshape -s1024 -- $(bart bitmask 2 10) $((PHS*TURNS)) $((TOT/TURNS)) - - | \ @@ -415,9 +415,9 @@ coilcompression_rovir () ( bart -t4 -r trj_rovir2.fifo nufft -p pat -- trj_rovir2.fifo ineg.fifo neg.fifo & bart -t4 -r pos.fifo rovir -- pos.fifo neg.fifo predelay.fifo & - + delay 10 $DELAY $DELAY predelay.fifo cc.fifo & - + bart -r cc.fifo repmat -- 9 $TURNS cc.fifo - | \ bart reshape -s1024 -- $(bart bitmask 9 10) 1 $TOT - - | \ bart -r - ccapply -p$CHANNELS -- tmp.fifo - $DST @@ -520,7 +520,7 @@ bart tee $TIME | \ bart -r - flip -- 3 - - | \ bart -r - resize -c -- 0 $RDIMS 1 $RDIMS - reco.fifo & -if $FILTER ; then +if $FILTER ; then mkfifo reco_fil.fifo diff --git a/src/bart.c b/src/bart.c index 5340e19cb..68e42678f 100644 --- a/src/bart.c +++ b/src/bart.c @@ -218,8 +218,8 @@ static void parse_bart_opts(int* argcp, char*** argvp) if (NULL == s) { // normal reference file: - unmap_cfl(DIMS, ref_dims, tmp); + } else { // reference stream: @@ -299,7 +299,7 @@ static int batch_wrapper(main_fun_t* dispatch_func, int argc, char *argv[argc], char* thread_argv[argc + 1]; char* thread_argv_save[argc]; - for(int m = 0; m < argc; m++) { + for (int m = 0; m < argc; m++) { thread_argv[m] = strdup(argv[m]); thread_argv_save[m] = thread_argv[m]; @@ -309,11 +309,12 @@ static int batch_wrapper(main_fun_t* dispatch_func, int argc, char *argv[argc], set_cfl_loop_index(pos); num_rand_init(0ULL); + int ret = (*dispatch_func)(argc, thread_argv); io_memory_cleanup(); - for(int m = 0; m < argc; ++m) + for (int m = 0; m < argc; ++m) free(thread_argv_save[m]); return ret; @@ -393,6 +394,7 @@ int main_bart(int argc, char* argv[argc]) } } } + } else { long start = cfl_loop_worker_id(); diff --git a/src/ccapply.c b/src/ccapply.c index f047eac79..f89d07c83 100644 --- a/src/ccapply.c +++ b/src/ccapply.c @@ -73,6 +73,7 @@ int main_ccapply(int argc, char* argv[argc]) long in_dims_t[DIMS]; md_set_dims(DIMS, in_dims_t, 0); + long cc_dims_t[DIMS]; complex float* in_data_t = NULL; @@ -98,6 +99,7 @@ int main_ccapply(int argc, char* argv[argc]) strm_in = stream_lookup(in_data_t); strm_cc = stream_lookup(cc_data_t); + } else { in_data = load_cfl(ksp_file, DIMS, in_dims); @@ -138,6 +140,7 @@ int main_ccapply(int argc, char* argv[argc]) out_data_t = create_async_cfl(out_file, rtflags, DIMS, out_dims_t); strm_out = stream_lookup(out_data_t); + } else { out_data = create_cfl(out_file, DIMS, out_dims); @@ -278,6 +281,7 @@ int main_ccapply(int argc, char* argv[argc]) unmap_cfl(DIMS, in_dims_t, in_data_t); unmap_cfl(DIMS, out_dims_t, out_data_t); + } else { unmap_cfl(DIMS, in_dims, in_data); diff --git a/src/iter/batch_gen.c b/src/iter/batch_gen.c index 363efa3d1..5d09d0208 100644 --- a/src/iter/batch_gen.c +++ b/src/iter/batch_gen.c @@ -244,7 +244,7 @@ static void batch_gen_del(const nlop_data_t* _data) * @param type methode to compose new batches * @param seed seed for random reshuffeling of batches */ -const struct nlop_s* batch_gen_create(int D, const int Ns[D], const long* bat_dims[D], const long* tot_dims[D], const _Complex float* data[D], long Nc, enum BATCH_GEN_TYPE type, unsigned long long seed) +const struct nlop_s* batch_gen_create(int D, const int Ns[D], const long* bat_dims[D], const long* tot_dims[D], const complex float* data[D], long Nc, enum BATCH_GEN_TYPE type, unsigned long long seed) { int N = 0; @@ -317,7 +317,7 @@ const struct nlop_s* batch_gen_create(int D, const int Ns[D], const long* bat_di } -const struct nlop_s* batch_gen_create_from_iter(struct iter6_conf_s* iter_conf, int D, const int Ns[D], const long* bat_dims[D], const long* tot_dims[D], const _Complex float* data[D], long Nc) +const struct nlop_s* batch_gen_create_from_iter(struct iter6_conf_s* iter_conf, int D, const int Ns[D], const long* bat_dims[D], const long* tot_dims[D], const complex float* data[D], long Nc) { return batch_gen_create(D, Ns, bat_dims, tot_dims, data, Nc, iter_conf->batchgen_type, iter_conf->batch_seed); } diff --git a/src/join.c b/src/join.c index 3b6268e76..ff92db3e8 100644 --- a/src/join.c +++ b/src/join.c @@ -162,7 +162,7 @@ int main_join(int argc, char* argv[argc]) } complex float* out_data = NULL; - + if (stream) out_data = create_async_cfl(out_file, MD_BIT(dim), N, out_dims); else @@ -196,7 +196,7 @@ int main_join(int argc, char* argv[argc]) long opos[N]; long ipos[N]; - + md_singleton_strides(N, opos); md_singleton_strides(N, ipos); diff --git a/src/misc/debug.c b/src/misc/debug.c index ad4b5415c..8f53d1ad7 100644 --- a/src/misc/debug.c +++ b/src/misc/debug.c @@ -66,7 +66,7 @@ void dump_cfl(const char* name, int D, const long dimensions[D], const complex f unmap_cfl(D, dimensions, out); } -void dump_multi_cfl(const char* name, int N, int D[N], const long* dimensions[N], const _Complex float* x[N]) +void dump_multi_cfl(const char* name, int N, int D[N], const long* dimensions[N], const complex float* x[N]) { complex float* args[N]; create_multi_cfl(name, N, D, dimensions, args); diff --git a/src/misc/mmio.c b/src/misc/mmio.c index 8182fda47..f3ad4815a 100644 --- a/src/misc/mmio.c +++ b/src/misc/mmio.c @@ -858,8 +858,9 @@ static complex float* create_cfl_internal(const char* name, int D, const long di if (mmio_file_locking) { - #pragma omp critical (bart_file_access) +#pragma omp critical (bart_file_access) addr = create_cfl_typed(type, name, D, dims, stream_flags); + } else { assert(!cfl_loop_desc_active()); @@ -1289,7 +1290,7 @@ void unmap_shared_cfl(int D, const long dims[D], const complex float* x) * @param dimensions[N] pointer to dimensions of each array * @param args[N] pointer to the first element of each memory mapped array */ -void create_multi_cfl(const char* name, int N, int D[N], const long* dimensions[N], _Complex float* args[N]) +void create_multi_cfl(const char* name, int N, int D[N], const long* dimensions[N], complex float* args[N]) { io_register_output(name); @@ -1347,7 +1348,7 @@ void create_multi_cfl(const char* name, int N, int D[N], const long* dimensions[ } -static int load_multi_cfl_internal(const char* name, int N_max, int D_max, int D[N_max], long dimensions[N_max][D_max], _Complex float* args[N_max], bool priv) +static int load_multi_cfl_internal(const char* name, int N_max, int D_max, int D[N_max], long dimensions[N_max][D_max], complex float* args[N_max], bool priv) { io_register_input(name); @@ -1441,7 +1442,7 @@ static int load_multi_cfl_internal(const char* name, int N_max, int D_max, int D * @param dimensions[N_max][D_max] dimensions read from header * @param args[N] returned pointer to the first element of each memory mapped array */ -int load_multi_cfl(const char* name, int N_max, int D_max, int D[N_max], long dimensions[N_max][D_max], _Complex float* args[N_max]) +int load_multi_cfl(const char* name, int N_max, int D_max, int D[N_max], long dimensions[N_max][D_max], complex float* args[N_max]) { return load_multi_cfl_internal(name, N_max, D_max, D, dimensions, args, true); } @@ -1454,7 +1455,7 @@ int load_multi_cfl(const char* name, int N_max, int D_max, int D[N_max], long di * @param dimensions[N] pointer to dimensions of each array * @param args[N] pointer to the first element of each memory mapped array */ -void unmap_multi_cfl(int N, int D[N], const long* dimensions[N], _Complex float* args[N]) +void unmap_multi_cfl(int N, int D[N], const long* dimensions[N], complex float* args[N]) { #ifdef MEMONLY_CFL error("multi cfl not supported with MEMONLY_CFL\n"); diff --git a/src/misc/stream.c b/src/misc/stream.c index 7dbdffcf0..87ee769e9 100644 --- a/src/misc/stream.c +++ b/src/misc/stream.c @@ -95,8 +95,7 @@ struct stream_settings { * checked/written using various pcfl_* functions. * Necessary state is kept in the struct returned from this function */ -static -struct pcfl* pcfl_create(complex float* x, int D, const long dims[D], unsigned long flags) +static struct pcfl* pcfl_create(complex float* x, int D, const long dims[D], unsigned long flags) { assert(bitcount(flags) <= D); @@ -120,8 +119,7 @@ struct pcfl* pcfl_create(complex float* x, int D, const long dims[D], unsigned l return PTR_PASS(ret); } -static -void pcfl_free(struct pcfl* p) +static void pcfl_free(struct pcfl* p) { if (NULL != p->dims) xfree(p->dims); @@ -181,9 +179,7 @@ complex float* pcfl_get_data(struct pcfl* p) } - -static -void pcfl_get_dimensions(struct pcfl* p, int N, long dims[N]) +static void pcfl_get_dimensions(struct pcfl* p, int N, long dims[N]) { assert(N == p->D); @@ -330,8 +326,10 @@ stream_t stream_create(int N, const long dims[N], complex float* data, int pipef ret->input = input; ret->binary = binary; ret->call_msync = call_msync; + // msync only makes sense for output streams that are not binary. assert(!call_msync || !(input || binary)); + ret->data = NULL; ret->unmap = false; ret->events = NULL; @@ -381,6 +379,7 @@ stream_t stream_create(int N, const long dims[N], complex float* data, int pipef cleanup: stream_free(PTR_PASS(ret)); + return NULL; } @@ -594,6 +593,7 @@ bool stream_send_msg2(int pipefd, const struct stream_msg* msg, long n, const lo error("Stream_encode: Message failed to encode.\n"); int w = xwrite(pipefd, MSG_HDR_SIZE, buffer); + if (0 >= w) return false; @@ -606,10 +606,11 @@ bool stream_send_msg2(int pipefd, const struct stream_msg* msg, long n, const lo const void *ptr = ext + md_calc_offset(n, str, pos); int w = xwrite(pipefd, el, ptr); + if (0 >= w) return false; - } while (md_next(n, dims, ~(0UL), pos)); + } while (md_next(n, dims, ~0UL, pos)); } return true; @@ -633,6 +634,7 @@ static long get_transport_layout(int D, const long dims[D], long size, int index long pos[D]; md_set_dims(D, pos, 0); md_unravel_index(D, pos, flags, dims, MAX(0, index)); + md_calc_strides(D, nstr, dims, (size_t)size); *nptr = &MD_ACCESS(D, nstr, pos, ptr); @@ -749,6 +751,7 @@ static bool stream_receive_idx_locked(stream_t s) bart_cond_notify_all(s->cond); debug_printf(DP_DEBUG3, "data offset rcvd: %ld\n", s->data->index); + return true; } @@ -788,7 +791,8 @@ static bool stream_send_index_locked(stream_t s, long index) long xstr[ND]; long size = sizeof(complex float); - long tx_size = get_transport_layout(ND, s->data->dims, size, index, s->data->stream_flags, ptr, &ND, xdims, xstr, &size, &ptr); + long tx_size = get_transport_layout(ND, s->data->dims, size, index, s->data->stream_flags, + ptr, &ND, xdims, xstr, &size, &ptr); struct stream_msg msg = { @@ -799,9 +803,11 @@ static bool stream_send_index_locked(stream_t s, long index) if (!stream_send_msg2(s->pipefd, &msg, ND, xdims, xstr, size, ptr)) return false; + } else if (s->call_msync) { - if (0 != msync(s->data->ptr, (size_t)md_calc_size(s->data->D, s->data->dims) * sizeof(complex float), MS_SYNC)) + if (0 != msync(s->data->ptr, + (size_t)(md_calc_size(s->data->D, s->data->dims) * (long)sizeof(complex float)), MS_SYNC)) return false; } @@ -873,10 +879,10 @@ bool stream_sync_slice_try(stream_t s, int N, const long dims[N], unsigned long for (int i = 0; i < MIN(N, s->data->D); i++) { assert(MD_IS_SET(flags, i) || (0 == pos[i])); - assert(!MD_IS_SET(flags, i) || (dims[i] == s->data->dims[i])); + assert(!MD_IS_SET(flags, i) || (dims[i] == s->data->dims[i])); } - unsigned long loop_flags = s->data->stream_flags & (~flags); + unsigned long loop_flags = s->data->stream_flags & ~flags; do { if (!stream_sync_index(s, pcfl_pos2offset(s->data, N, pos), false)) @@ -998,12 +1004,12 @@ unsigned long stream_get_flags(stream_t s) return s->data->stream_flags; } -extern _Bool stream_is_binary(stream_t s) +extern bool stream_is_binary(stream_t s) { return s->binary; } -_Complex float* stream_get_data(stream_t s) +complex float* stream_get_data(stream_t s) { return pcfl_get_data(s->data); } @@ -1049,17 +1055,20 @@ static bool stream_event_id_eq(const void *item, const void* ref); */ bool stream_add_event(stream_t s, int N, long pos[N], int type, long size, const char* data) { + bool ret = false; + // only output streams can transmit events. // checking that here because stream_add_event_intern // should add events to an input stream. if (s->input) - return false; + return ret; int index = pcfl_pos2offset(stream_get_pcfl(s), N, pos); bart_lock(s->data->sync_lock); struct stream_event* item = stream_event_create(index, type, size, data); + if (NULL == item) goto fail; @@ -1069,13 +1078,11 @@ bool stream_add_event(stream_t s, int N, long pos[N], int type, long size, const goto fail; } - bart_unlock(s->data->sync_lock); - - return true; - + ret = true; fail: bart_unlock(s->data->sync_lock); - return false; + + return ret; } struct list_s* stream_get_events(struct stream* s, int N, long pos[N]) @@ -1088,7 +1095,7 @@ static bool stream_event_id_eq(const void *item, const void* ref) const struct stream_event* ev = item; long index = *((long*)ref); - return (ev->index == index) ? true : false; + return (ev->index == index); } static struct list_s* stream_get_events_at_index(struct stream* s, long index) diff --git a/src/moba/iter_l1.c b/src/moba/iter_l1.c index b7fce289c..1d736c3cf 100644 --- a/src/moba/iter_l1.c +++ b/src/moba/iter_l1.c @@ -180,7 +180,7 @@ static void combined_prox(iter_op_data* _data, float rho, float* dst, const floa } if (1 == data->conf->opt_reg) - operator_p_apply_unchecked(data->prox2, rho, (_Complex float*)dst, (const _Complex float*)dst); + operator_p_apply_unchecked(data->prox2, rho, (complex float*)dst, (const complex float*)dst); pos_value(_data, dst, dst); } diff --git a/src/motion/interpolate.c b/src/motion/interpolate.c index db77508d0..04a03ac3b 100644 --- a/src/motion/interpolate.c +++ b/src/motion/interpolate.c @@ -633,7 +633,7 @@ void md_interpolate_der_coor2(int d, unsigned long flags, int ord, int N, const -void md_interpolate(int d, unsigned long flags, int ord, int N, const long idims[N], _Complex float* intp, const long cdims[N], const _Complex float* coor, const long gdims[N], const _Complex float* grid) +void md_interpolate(int d, unsigned long flags, int ord, int N, const long idims[N], complex float* intp, const long cdims[N], const complex float* coor, const long gdims[N], const complex float* grid) { assert(md_check_compat(N, ~0ul, idims, cdims)); @@ -644,7 +644,7 @@ void md_interpolate(int d, unsigned long flags, int ord, int N, const long idims md_interpolate2(d, flags, ord, N, dims, MD_STRIDES(N, idims, CFL_SIZE), intp, MD_STRIDES(N, cdims, CFL_SIZE), coor, gdims, MD_STRIDES(N, gdims, CFL_SIZE), grid); } -void md_interpolateH(int d, unsigned long flags, int ord, int N, const long gdims[N], _Complex float* grid, const long idims[N], const _Complex float* intp, const long cdims[N], const _Complex float* coor) +void md_interpolateH(int d, unsigned long flags, int ord, int N, const long gdims[N], complex float* grid, const long idims[N], const complex float* intp, const long cdims[N], const complex float* coor) { assert(md_check_compat(N, ~0ul, idims, cdims)); @@ -655,7 +655,7 @@ void md_interpolateH(int d, unsigned long flags, int ord, int N, const long gdim md_interpolateH2(d, flags, ord, N, gdims, MD_STRIDES(N, gdims, CFL_SIZE), grid, dims, MD_STRIDES(N, idims, CFL_SIZE), intp, MD_STRIDES(N, cdims, CFL_SIZE), coor); } -void md_interpolate_adj_coor(int d, unsigned long flags, int ord, int N, const long cdims[N], const _Complex float* coor, _Complex float* dcoor, const long idims[N], const _Complex float* dintp, const long gdims[N], const _Complex float* grid) +void md_interpolate_adj_coor(int d, unsigned long flags, int ord, int N, const long cdims[N], const complex float* coor, complex float* dcoor, const long idims[N], const complex float* dintp, const long gdims[N], const complex float* grid) { assert(md_check_compat(N, ~0ul, idims, cdims)); @@ -666,7 +666,7 @@ void md_interpolate_adj_coor(int d, unsigned long flags, int ord, int N, const l md_interpolate_adj_coor2(d, flags, ord, N, dims, MD_STRIDES(N, cdims, CFL_SIZE), coor, dcoor, MD_STRIDES(N, idims, CFL_SIZE), dintp, gdims, MD_STRIDES(N, gdims, CFL_SIZE), grid); } -static void md_interpolate_adj_coor_shifted(int d, unsigned long flags, int ord, int N, const long cdims[N], const _Complex float* coor, _Complex float* dcoor, const long idims[N], const _Complex float* dintp, const long gdims[N], const _Complex float* grid) +static void md_interpolate_adj_coor_shifted(int d, unsigned long flags, int ord, int N, const long cdims[N], const complex float* coor, complex float* dcoor, const long idims[N], const complex float* dintp, const long gdims[N], const complex float* grid) { assert(md_check_compat(N, ~0ul, idims, cdims)); @@ -699,7 +699,7 @@ static void md_interpolate_adj_coor_shifted(int d, unsigned long flags, int ord, md_zmulc2(N, dims, MD_STRIDES(N, cdims, CFL_SIZE), dcoor, MD_STRIDES(N, idims, CFL_SIZE), dintp, MD_STRIDES(N, cdims, CFL_SIZE), dcoor); } -void md_interpolate_der_coor(int d, unsigned long flags, int ord, int N, const long idims[N], _Complex float* dintp, const long cdims[N], const _Complex float* coor, const _Complex float* dcoor, const long gdims[N], const _Complex float* grid) +void md_interpolate_der_coor(int d, unsigned long flags, int ord, int N, const long idims[N], complex float* dintp, const long cdims[N], const complex float* coor, const complex float* dcoor, const long gdims[N], const complex float* grid) { assert(md_check_compat(N, ~0ul, idims, cdims)); @@ -710,7 +710,7 @@ void md_interpolate_der_coor(int d, unsigned long flags, int ord, int N, const l md_interpolate_der_coor2(d, flags, ord, N, dims, MD_STRIDES(N, idims, CFL_SIZE), dintp, MD_STRIDES(N, cdims, CFL_SIZE), coor, dcoor, gdims, MD_STRIDES(N, gdims, CFL_SIZE), grid); } -void md_resample(unsigned long flags, int ord, int N, const long _odims[N], _Complex float* dst, const long _idims[N], const _Complex float* src) +void md_resample(unsigned long flags, int ord, int N, const long _odims[N], complex float* dst, const long _idims[N], const complex float* src) { assert(md_check_equal_dims(N, _odims, _idims, ~flags)); diff --git a/src/motion/pyramide.c b/src/motion/pyramide.c index e4255824c..e89bb584c 100644 --- a/src/motion/pyramide.c +++ b/src/motion/pyramide.c @@ -102,8 +102,8 @@ void debug_gaussian_pyramide(int levels, float factors[levels], float sigma[leve void upscale_displacement(int N, int d, unsigned long flags, - const long odims[N], _Complex float* out, - const long idims[N], const _Complex float* in) + const long odims[N], complex float* out, + const long idims[N], const complex float* in) { md_resample(flags, 3, N, odims, out, idims, in); diff --git a/src/networks/nnet.c b/src/networks/nnet.c index 1bfdb99ee..3548d4418 100644 --- a/src/networks/nnet.c +++ b/src/networks/nnet.c @@ -5,6 +5,7 @@ #include #include +#include #include #include "misc/debug.h" @@ -361,8 +362,8 @@ void apply_nnet_batchwise( const struct nnet_s* config, extern void eval_nnet( struct nnet_s* nnet, - int NO, const long odims[NO], const _Complex float* out, - int NI, const long idims[NI], const _Complex float* in, + int NO, const long odims[NO], const complex float* out, + int NI, const long idims[NI], const complex float* in, long Nb) { complex float* tmp_out = md_alloc(NO, odims, CFL_SIZE); diff --git a/src/nlops/const.c b/src/nlops/const.c index cba23cbff..5f29af3cd 100644 --- a/src/nlops/const.c +++ b/src/nlops/const.c @@ -218,7 +218,7 @@ struct nlop_s* nlop_set_input_const_F(const struct nlop_s* a, int i, int N, cons return result; } -struct nlop_s* nlop_set_input_scalar_F(const struct nlop_s* a, int i, _Complex float val) +struct nlop_s* nlop_set_input_scalar_F(const struct nlop_s* a, int i, complex float val) { auto iov = nlop_generic_domain(a, i); return nlop_set_input_const_F2(a, i, iov->N, iov->dims, MD_SINGLETON_STRS(iov->N), true, &val); diff --git a/src/nlops/mi_metric.c b/src/nlops/mi_metric.c index c4fd7375c..107c743a0 100644 --- a/src/nlops/mi_metric.c +++ b/src/nlops/mi_metric.c @@ -13,10 +13,8 @@ * Mattes, D., Haynor, D. R., Vesselle, H., Lewellen, T. K., & Eubank, W. * PET-CT image registration in the chest using free-form deformations. * IEEE TMI, 22(1), 120-8, 2003. - * */ - #include #include @@ -30,11 +28,6 @@ #include "mi_metric.h" -#define CFL_SIZE sizeof(_Complex float) -#define FL_SIZE sizeof(float) -#define CDL_SIZE sizeof(_Complex double) -#define DL_SIZE sizeof(double) - static float bin_normalize(float x, float mval, float delta); static inline int bin_index(float normalized, int nbins, int padding); @@ -361,8 +354,3 @@ struct nlop_s* nlop_mi_metric_create(int N, const long dims[N], int nbins, float - - - - - diff --git a/src/nlops/nlop_jacobian.c b/src/nlops/nlop_jacobian.c index 507e490a0..ec428ed79 100644 --- a/src/nlops/nlop_jacobian.c +++ b/src/nlops/nlop_jacobian.c @@ -598,7 +598,7 @@ bool nlop_block_diag_der_available(const struct nlop_s* op, int o, int i) } -static void zrdiag_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], _Complex float* dst[OO], int II, const long idims[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II], _Complex float* jacc[OO][II]) +static void zrdiag_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], complex float* dst[OO], int II, const long idims[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II], complex float* jacc[OO][II]) { auto data = CAST_DOWN(diag_s, _data); @@ -657,7 +657,7 @@ struct nlop_s* nlop_zrdiag_create(int N, const long dims[N], nlop_data_t* data, -static void zdiag_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], _Complex float* dst[OO], int II, const long idims[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II]) +static void zdiag_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], complex float* dst[OO], int II, const long idims[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II]) { auto data = CAST_DOWN(diag_s, _data); @@ -745,7 +745,7 @@ struct nlop_s* nlop_rdiag_create(int N, const long dims[N], nlop_data_t* data, n -static void zblock_diag_simple_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], _Complex float* dst[OO], int II, const long idims[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II]) +static void zblock_diag_simple_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], complex float* dst[OO], int II, const long idims[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II]) { auto data = CAST_DOWN(block_diag_simple_s, _data); @@ -804,7 +804,7 @@ static void rblock_diag_simple_fun(const nlop_data_t* _data, int N, int OO, cons data->rblock_diag_fun(data->data, N, odims[0], dst[0], idims[0], src[0], ddims[0][0], jac[0][0]); } -static void zrblock_diag_simple_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], _Complex float* dst[OO], int II, const long idims[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II], _Complex float* jacc[OO][II]) +static void zrblock_diag_simple_fun(const nlop_data_t* _data, int N, int OO, const long odims[OO][N], complex float* dst[OO], int II, const long idims[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II], complex float* jacc[OO][II]) { auto data = CAST_DOWN(block_diag_simple_s, _data); @@ -1205,7 +1205,7 @@ static void precomp_jacobian_del(const nlop_data_t* _data) } -static void zprecomp_jacobian_fun(const nlop_data_t* _data, int N, int OO, const long /*odims*/[OO][N], _Complex float* dst[OO], int II, const long /*idims*/[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II]) +static void zprecomp_jacobian_fun(const nlop_data_t* _data, int N, int OO, const long /*odims*/[OO][N], complex float* dst[OO], int II, const long /*idims*/[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II]) { auto data = CAST_DOWN(precomp_jacobian_s, _data); auto op = data->nlop; @@ -1216,7 +1216,7 @@ static void zprecomp_jacobian_fun(const nlop_data_t* _data, int N, int OO, const unsigned long out_der_flag = 0; unsigned long in_der_flag = 0; - for (int i = 0; i < II; i++) { + for (int i = 0; i < II; i++) { for (int o = 0; o < OO; o++) { if (NULL != jac[o][i]) { diff --git a/src/nlops/tenmul.c b/src/nlops/tenmul.c index a0469a5d8..d6c7db7fc 100644 --- a/src/nlops/tenmul.c +++ b/src/nlops/tenmul.c @@ -227,7 +227,7 @@ struct tenmul_block_diag_s { DEF_TYPEID(tenmul_block_diag_s); -static void tenmul_block_diag_fun(const nlop_data_t* /*_data*/, int N, int OO, const long odims[OO][N], _Complex float* dst[OO], int II, const long idims[II][N], const _Complex float* src[II], const long ddims[OO][II][N], _Complex float* jac[OO][II]) +static void tenmul_block_diag_fun(const nlop_data_t* /*_data*/, int N, int OO, const long odims[OO][N], complex float* dst[OO], int II, const long idims[II][N], const complex float* src[II], const long ddims[OO][II][N], complex float* jac[OO][II]) { assert(1 == OO); assert(2 == II); diff --git a/src/nn/init.c b/src/nn/init.c index 58fdfe39a..1762eea2e 100644 --- a/src/nn/init.c +++ b/src/nn/init.c @@ -163,7 +163,7 @@ static void init_const_fun(const init_t* conf_, int N, const long dims[N], compl * * @returns Constant initializer */ -const struct initializer_s* init_const_create(_Complex float val) +const struct initializer_s* init_const_create(complex float val) { PTR_ALLOC(struct initializer_const_s, data); SET_TYPEID(initializer_const_s, data); diff --git a/src/nn/losses.c b/src/nn/losses.c index 56f827e02..7c57ed0a3 100644 --- a/src/nn/losses.c +++ b/src/nn/losses.c @@ -1008,8 +1008,8 @@ static void dice_fun(const nlop_data_t* _data, int D, complex float* args[D]) //debug_print_dims(DP_INFO, data->N, data->rdims); complex float* dst = args[0]; - const _Complex float* src_pred = args[1]; - const _Complex float* src_true = args[2]; + const complex float* src_pred = args[1]; + const complex float* src_true = args[2]; #ifdef USE_CUDA assert((cuda_ondevice(dst) == cuda_ondevice(src_pred)) && (cuda_ondevice(src_pred) == cuda_ondevice(src_true))); diff --git a/src/nn/tf_wrapper.c b/src/nn/tf_wrapper.c index 584f56125..715268923 100644 --- a/src/nn/tf_wrapper.c +++ b/src/nn/tf_wrapper.c @@ -1180,7 +1180,7 @@ static void tf_jac_del(const nlop_data_t* _data) }; -static void tf_zjac(const nlop_data_t* _data, int N, const long odims[N], _Complex float* dst, const long idims[N], const _Complex float* src, const long ddims[N], _Complex float* jac) +static void tf_zjac(const nlop_data_t* _data, int N, const long odims[N], complex float* dst, const long idims[N], const complex float* src, const long ddims[N], complex float* jac) { auto data = CAST_DOWN(tf_jac_s, _data); diff --git a/src/nn/weights.c b/src/nn/weights.c index dcad72c64..58a9cb755 100644 --- a/src/nn/weights.c +++ b/src/nn/weights.c @@ -30,7 +30,7 @@ #include "weights.h" -const struct nn_weights_s* create_multi_md_array(int N, int D[N], const long* dimensions[N], const _Complex float* x[N], size_t sizes[N]) +const struct nn_weights_s* create_multi_md_array(int N, int D[N], const long* dimensions[N], const complex float* x[N], size_t sizes[N]) { const struct iovec_s* iovs[N]; for (int i = 0; i < N; i++) @@ -60,7 +60,7 @@ nn_weights_t nn_weights_create(int N, const struct iovec_s* iovs[N]) result->N = N; PTR_ALLOC(const struct iovec_s*[N], niov); - PTR_ALLOC(_Complex float*[N], ntensors); + PTR_ALLOC(complex float*[N], ntensors); for (int i = 0; i < N; i++) { @@ -95,15 +95,16 @@ nn_weights_t load_nn_weights(const char *name) result->N = N; PTR_ALLOC(const struct iovec_s*[N], niov); - PTR_ALLOC(_Complex float*[N], ntensors); + PTR_ALLOC(complex float*[N], ntensors); const long* dimensions_unmap[N]; for (int i = 0; i < N; i++) { - (*niov)[i] = iovec_create(D[i], dimensions[i], sizeof(_Complex float)); - (*ntensors)[i] = md_alloc(D[i], dimensions[i], sizeof(_Complex float)); - md_copy(D[i], dimensions[i], (*ntensors)[i], args[i], sizeof(_Complex float)); + (*niov)[i] = iovec_create(D[i], dimensions[i], sizeof(complex float)); + (*ntensors)[i] = md_alloc(D[i], dimensions[i], sizeof(complex float)); + + md_copy(D[i], dimensions[i], (*ntensors)[i], args[i], sizeof(complex float)); dimensions_unmap[i] = dimensions[i]; } diff --git a/src/num/gpuops.c b/src/num/gpuops.c index 9ae7aae0b..0d8d8606c 100644 --- a/src/num/gpuops.c +++ b/src/num/gpuops.c @@ -555,8 +555,8 @@ struct vec_iter_s { void (*sdiv)(long N, float* a, float x, const float* y); void (*le)(long N, float* a, const float* x, const float* y); - void (*zmul)(long N, _Complex float* dst, const _Complex float* src1, const _Complex float* src2); - void (*zsmax)(long N, float val, _Complex float* dst, const _Complex float* src1); + void (*zmul)(long N, complex float* dst, const complex float* src1, const complex float* src2); + void (*zsmax)(long N, float val, complex float* dst, const complex float* src1); void (*rand)(long N, float* dst); diff --git a/src/num/vecops.c b/src/num/vecops.c index 9a33d03ca..865ddfc96 100644 --- a/src/num/vecops.c +++ b/src/num/vecops.c @@ -708,37 +708,37 @@ static void pdf_gauss(long N, float mu, float sig, float* dst, const float* src) } -static void vec_real(long N, float* dst, const _Complex float* src) +static void vec_real(long N, float* dst, const complex float* src) { for (int i = 0; i < N; i ++) dst[i] = crealf(src[i]); } -static void vec_imag(long N, float* dst, const _Complex float* src) +static void vec_imag(long N, float* dst, const complex float* src) { for (int i = 0; i < N; i ++) dst[i] = cimagf(src[i]); } -static void vec_zcmpl_real(long N, _Complex float* dst, const float* src) +static void vec_zcmpl_real(long N, complex float* dst, const float* src) { for (int i = 0; i < N; i ++) dst[i] = src[i]; } -static void vec_zcmpl_imag(long N, _Complex float* dst, const float* src) +static void vec_zcmpl_imag(long N, complex float* dst, const float* src) { for (int i = 0; i < N; i ++) dst[i] = src[i] * I; } -static void vec_zcmpl(long N, _Complex float* dst, const float* real_src, const float* imag_src) +static void vec_zcmpl(long N, complex float* dst, const float* real_src, const float* imag_src) { for (int i = 0; i < N; i ++) dst[i] = real_src[i] + imag_src[i] * I; } -static void vec_zfill(long N, _Complex float val, _Complex float* dst) +static void vec_zfill(long N, complex float val, complex float* dst) { for (int i = 0; i < N; i ++) dst[i] = val; diff --git a/src/reshape.c b/src/reshape.c index 8ff52a77e..6a21d148a 100644 --- a/src/reshape.c +++ b/src/reshape.c @@ -92,25 +92,28 @@ int main_reshape(int argc, char* argv[argc]) complex float* out_data = NULL; - if (0 != stream_flags) - out_data = create_async_cfl(out_file, stream_flags, DIMS, out_dims); - else + if (0 == stream_flags) { + out_data = create_cfl(out_file, DIMS, out_dims); - if (0 != stream_flags) { + md_reshape(DIMS, flags, out_dims, out_data, in_dims, in_data, CFL_SIZE); + + } else { + + out_data = create_async_cfl(out_file, stream_flags, DIMS, out_dims); stream_t strm_in = stream_lookup(in_data); stream_t strm_out = stream_lookup(out_data); unsigned long iflags = 0; unsigned long oflags = 0; - + if (NULL != strm_in) iflags = stream_get_flags(strm_in); oflags = stream_get_flags(strm_out); - if (0 != ((~flags) & (iflags | oflags))) + if (0 != (~flags & (iflags | oflags))) error("All streamd dimensions must be reshaped!"); long slc_dims[DIMS]; @@ -126,12 +129,11 @@ int main_reshape(int argc, char* argv[argc]) stream_sync(strm_in, DIMS, ipos); do { - long index = md_ravel_index(DIMS, ipos, flags, in_dims); md_unravel_index(DIMS, opos, flags, out_dims, index); md_slice(DIMS, flags, ipos, in_dims, buf, in_data, CFL_SIZE); - + long zpos[DIMS] = { 0 }; md_move_block(DIMS, slc_dims, opos, out_dims, out_data, zpos, slc_dims, buf, CFL_SIZE); @@ -145,26 +147,21 @@ int main_reshape(int argc, char* argv[argc]) if (!MD_IS_SET(oflags, i) && (1 + opos[i] != out_dims[i])) cont = true; } - + if (cont) continue; - stream_sync(strm_out, DIMS, opos); - - } while (md_next(DIMS, in_dims, flags & (~iflags), ipos)); + + } while (md_next(DIMS, in_dims, flags & ~iflags, ipos)); for (int i = 0; i < DIMS; i++) - if (MD_IS_SET(flags & (~iflags), i)) + if (MD_IS_SET(flags & ~iflags, i)) ipos[i] = 0; } while (md_next(DIMS, in_dims, iflags, ipos)); md_free(buf); - - } else { - - md_reshape(DIMS, flags, out_dims, out_data, in_dims, in_data, CFL_SIZE); } unmap_cfl(DIMS, in_dims, in_data); @@ -174,4 +171,3 @@ int main_reshape(int argc, char* argv[argc]) return 0; } - diff --git a/src/simu/phantom.c b/src/simu/phantom.c index 786145906..dc0c860b6 100644 --- a/src/simu/phantom.c +++ b/src/simu/phantom.c @@ -371,7 +371,7 @@ void calc_ellipsoid(int D, long dims[D], complex float* optr, bool d3, bool kspa } -void calc_phantom(const long dims[DIMS], complex float* out, bool d3, bool kspace, const long tstrs[DIMS], const _Complex float* traj, struct pha_opts* popts) +void calc_phantom(const long dims[DIMS], complex float* out, bool d3, bool kspace, const long tstrs[DIMS], const complex float* traj, struct pha_opts* popts) { bool coeff = (dims[COEFF_DIM] > 1); @@ -382,7 +382,7 @@ void calc_phantom(const long dims[DIMS], complex float* out, bool d3, bool kspac } -void calc_geo_phantom(const long dims[DIMS], complex float* out, bool kspace, int phtype, const long tstrs[DIMS], const _Complex float* traj, struct pha_opts* popts) +void calc_geo_phantom(const long dims[DIMS], complex float* out, bool kspace, int phtype, const long tstrs[DIMS], const complex float* traj, struct pha_opts* popts) { bool coeff = (dims[COEFF_DIM] > 1); diff --git a/src/tee.c b/src/tee.c index 96d4c2556..5aeae9c91 100644 --- a/src/tee.c +++ b/src/tee.c @@ -97,6 +97,7 @@ int main_tee(int argc, char* argv[argc]) complex float* out0_addr = create_async_cfl(out0, stream_flags, DIMS, dims); stream_t strm = stream_lookup(out0_addr); + if (strm) { stream_sync_try(strm, DIMS, dims); @@ -116,8 +117,8 @@ int main_tee(int argc, char* argv[argc]) #pragma omp parallel for for (int i = 0; i < count; i++) { - const char* name = (0 == i && !no_stdout) ? "-" : out_files[i - files_offset]; - + const char* name = ((0 == i) && !no_stdout) ? "-" : out_files[i - files_offset]; + if (0 != strcmp(name, "-")) io_reserve_output(name); @@ -149,6 +150,7 @@ int main_tee(int argc, char* argv[argc]) if (timer) fprintf(stderr, "frame %ld: %fs\n", counter++, timestamp() - time); + time = timestamp(); } while (md_next(DIMS, dims, stream_flags, pos));