Skip to content

Commit

Permalink
resize front
Browse files Browse the repository at this point in the history
  • Loading branch information
uecker committed Jul 9, 2024
1 parent e2ba977 commit 8a0fc71
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
35 changes: 31 additions & 4 deletions src/num/multind.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,16 +1277,43 @@ void md_resize_center(int D, const long odim[D], void* optr, const long idim[D],

for (int i = 0; i < D; i++) {

if (odim[i] > idim[i]) {
if (odim[i] >= idim[i])
continue;

md_clear(D, odim, optr, size);
break;
}
md_clear(D, odim, optr, size);
break;
}

md_copy_block(D, pos, odim, optr, idim, iptr, size);
}



/**
* Resize an array by zero-padding or by truncation at the beginning.
*
* optr = [0 0 0 0 iptr]
*
*/
void md_resize_front(int D, const long odim[D], void* optr, const long idim[D], const void* iptr, size_t size)
{
long pos[D];
for (int i = 0; i < D; i++)
pos[i] = odim[i] - idim[i];

for (int i = 0; i < D; i++) {

if (odim[i] <= idim[i])
continue;

md_clear(D, odim, optr, size);
break;
}

md_copy_block(D, pos, odim, optr, idim, iptr, size);
}


/**
* Pad an array on both ends by val.
*
Expand Down
1 change: 1 addition & 0 deletions src/num/multind.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern void md_reflectpad_center2(int D, const long odim[__VLA(D)], const long o
extern void md_reflectpad_center(int D, const long odim[__VLA(D)], void* optr, const long idim[__VLA(D)], const void* iptr, size_t size);
extern void md_resize(int D, const long odim[__VLA(D)], void* optr, const long idim[__VLA(D)], const void* iptr, size_t size);
extern void md_resize_center(int D, const long odim[__VLA(D)], void* optr, const long idim[__VLA(D)], const void* iptr, size_t size);
extern void md_resize_front(int D, const long odim[__VLA(D)], void* optr, const long idim[__VLA(D)], const void* iptr, size_t size);
extern void md_fill2(int D, const long dim[__VLA(D)], const long str[__VLA(D)], void* ptr, const void* iptr, size_t size);
extern void md_fill(int D, const long dim[__VLA(D)], void* ptr, const void* iptr, size_t size);
extern void md_slice2(int D, unsigned long flags, const long pos[__VLA(D)], const long dim[__VLA(D)], const long ostr[__VLA(D)], void* optr, const long istr[__VLA(D)], const void* iptr, size_t size);
Expand Down
21 changes: 18 additions & 3 deletions src/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ int main_resize(int argc, char* argv[argc])
ARG_OUTFILE(true, &out_file, "output"),
};

bool center = false;
enum mode { FRONT, CENTER, END } mode = END;;

const struct opt_s opts[] = {

OPT_SET('c', &center, "center"),
OPT_SELECT('c', enum mode, &mode, CENTER, "center"),
OPT_SELECT('f', enum mode, &mode, FRONT, "front"),
};

cmdline(&argc, argv, ARRAY_SIZE(args), args, help_str, ARRAY_SIZE(opts), opts);
Expand Down Expand Up @@ -81,7 +82,21 @@ int main_resize(int argc, char* argv[argc])

void* out_data = create_cfl(out_file, N, out_dims);

(center ? md_resize_center : md_resize)(N, out_dims, out_data, in_dims, in_data, CFL_SIZE);
switch (mode) {
case FRONT:

md_resize_front(N, out_dims, out_data, in_dims, in_data, CFL_SIZE);
break;

case CENTER:

md_resize_center(N, out_dims, out_data, in_dims, in_data, CFL_SIZE);
break;

case END:
md_resize(N, out_dims, out_data, in_dims, in_data, CFL_SIZE);
break;
}

unmap_cfl(N, in_dims, in_data);
unmap_cfl(N, out_dims, out_data);
Expand Down

0 comments on commit 8a0fc71

Please sign in to comment.