24static struct yac_param * utest_get_subparam(
25 struct yac_param * param,
char const * subparam_name);
39 if (!copy)
PUT_ERR(
"copy failed");
48 if (!config2)
PUT_ERR(
"avg_create failed (config2)");
51 struct yac_param * partial_coverage_param = NULL;
53 config2_param,
"partial_coverage", &partial_coverage_param) != 0)
54 PUT_ERR(
"failed to get avg.partial_coverage parameter");
56 PUT_ERR(
"failed to set avg.partial_coverage parameter");
58 PUT_ERR(
"compare should detect difference");
64 if (interp_stack[0] == NULL)
PUT_ERR(
"generate should not return NULL");
80 if (param_a != param_b)
81 PUT_ERR(
"get_param should return cached handle");
83 struct yac_param *partial_coverage_a = NULL;
85 param_a,
"partial_coverage", &partial_coverage_a) != 0)
86 PUT_ERR(
"failed to get avg.partial_coverage parameter");
88 PUT_ERR(
"failed to set avg.partial_coverage parameter");
90 struct yac_param *partial_coverage_b = NULL;
92 param_b,
"partial_coverage", &partial_coverage_b) != 0)
93 PUT_ERR(
"failed to re-get avg.partial_coverage parameter");
94 int partial_coverage = 0;
96 PUT_ERR(
"failed to read avg.partial_coverage parameter");
97 if (partial_coverage != 1)
98 PUT_ERR(
"cached parameter handle did not expose latest value");
102 if (!copy)
PUT_ERR(
"copy failed");
105 if (copy_param == param_a)
106 PUT_ERR(
"copied config must not share cached parameter handle");
110 int mpi_pack_size = (int)pack_size;
111 void *sendbuf = malloc(mpi_pack_size);
112 void *recvbuf = malloc(mpi_pack_size);
115 config, sendbuf, mpi_pack_size, &pos, MPI_COMM_SELF);
117 sendbuf, mpi_pack_size, MPI_PACKED, 0, 0,
118 recvbuf, mpi_pack_size, MPI_PACKED, 0, 0,
119 MPI_COMM_SELF, MPI_STATUS_IGNORE);
123 recvbuf, mpi_pack_size, &rpos, MPI_COMM_SELF);
124 if (!unpacked)
PUT_ERR(
"avg_unpack failed");
127 if (unpacked_param == param_a)
128 PUT_ERR(
"unpacked config must not share cached parameter handle");
140 if (!send_config)
PUT_ERR(
"avg_create failed");
143 int mpi_pack_size = (int)pack_size;
144 void *sendbuf = malloc(mpi_pack_size);
145 void *recvbuf = malloc(mpi_pack_size);
148 send_config, sendbuf, mpi_pack_size, &pos, MPI_COMM_SELF);
150 sendbuf, mpi_pack_size, MPI_PACKED, 0, 0,
151 recvbuf, mpi_pack_size, MPI_PACKED, 0, 0,
152 MPI_COMM_SELF, MPI_STATUS_IGNORE);
156 if (!recv_config)
PUT_ERR(
"avg_unpack failed");
171 PUT_ERR(
"copy(NULL) should return NULL");
175 PUT_ERR(
"compare(NULL, NULL) should return 0");
181 PUT_ERR(
"compare(NULL, valid) should return -1");
183 PUT_ERR(
"compare(valid, NULL) should return 1");
190 int mpi_pack_size = (int)pack_size;
191 void *sendbuf = malloc(mpi_pack_size);
192 void *recvbuf = malloc(mpi_pack_size);
195 NULL, sendbuf, mpi_pack_size, &pos, MPI_COMM_SELF);
197 sendbuf, mpi_pack_size, MPI_PACKED, 0, 0,
198 recvbuf, mpi_pack_size, MPI_PACKED, 0, 0,
199 MPI_COMM_SELF, MPI_STATUS_IGNORE);
203 recvbuf, mpi_pack_size, &rpos, MPI_COMM_SELF);
208 if (recv_config)
PUT_ERR(
"undefined_unpack failed");
214 PUT_ERR(
"get_type(NULL) should return YAC_UNDEFINED");
218 PUT_ERR(
"get_param(NULL) should return NULL");
222 PUT_ERR(
"generate(NULL) should return NULL");
248 for (
size_t i = 0;
i <
sizeof(test_cases) /
sizeof(test_cases[0]); ++
i) {
254 PUT_ERR(
"yac_interp_method_config_default_from_name_new returned NULL");
259 "yac_interp_method_config_default_from_name_new returned wrong type");
265 PUT_ERR(
"yac_interp_method_config_get_param returned NULL");
274 "%s config parameters should not be default", test_cases[i].
name);
278 "default config parameters of %s should be in default state",
286 PUT_ERR(
"yac_interp_method_config_copy returned NULL");
288 PUT_ERR(
"yac_interp_method_config_compare failed for copied config");
298 config,
"func_compute_weights",
"test_callback");
304 int mpi_pack_size = (int)pack_size;
305 void *sendbuf = malloc(mpi_pack_size);
306 void *recvbuf = malloc(mpi_pack_size);
309 config, sendbuf, mpi_pack_size, &pos, MPI_COMM_SELF);
311 sendbuf, mpi_pack_size, MPI_PACKED, 0, 0,
312 recvbuf, mpi_pack_size, MPI_PACKED, 0, 0,
313 MPI_COMM_SELF, MPI_STATUS_IGNORE);
317 recvbuf, mpi_pack_size, &rpos, MPI_COMM_SELF);
319 PUT_ERR(
"yac_interp_method_config_unpack returned NULL");
321 PUT_ERR(
"pack/unpack roundtrip compare failed");
333 if (stack[0] == NULL)
334 PUT_ERR(
"yac_interp_method_config_generate returned NULL");
352 if (!param)
PUT_ERR(
"rbf get_param returned NULL");
357 PUT_ERR(
"rbf get_param root type should be STRUCT");
359 if (!
name || strcmp(
name,
"rbf") != 0)
360 PUT_ERR(
"rbf get_param root name should be 'rbf'");
364 enum {REF_NUM_SUBPARAMS = 5};
367 PUT_ERR(
"rbf get_param get_sub_count failed");
368 if (count != REF_NUM_SUBPARAMS)
369 PUT_ERR(
"rbf get_param should have 5 subparams");
374 PUT_ERR(
"rbf get_param missing 'n' subparam");
377 PUT_ERR(
"rbf get_param missing 'n_min' subparam");
379 param,
"max_search_distance", &sub) != 0 || !sub)
380 PUT_ERR(
"rbf get_param missing 'max_search_distance' subparam");
382 param,
"rbf_scale", &sub) != 0 || !sub)
383 PUT_ERR(
"rbf get_param missing 'rbf_scale' subparam");
385 param,
"rbf_kernel", &sub) != 0 || !sub)
386 PUT_ERR(
"rbf get_param missing 'rbf_kernel' subparam");
390 PUT_ERR(
"rbf get_param should report all-default");
402 PUT_ERR(
"nnn default 'n_min' value is wrong");
407 PUT_ERR(
"failed to set nnn 'n_min' parameter");
418 config_default_n_min, config_explicit_n_min) != 0)
419 PUT_ERR(
"n_min == 0 and n_min == n should compare as equal");
421 PUT_ERR(
"compare should detect different n_min");
431 if (test_failed)
PUT_ERR(
"n_min > n should abort");
481 if (!root_param)
PUT_ERR(
"dnn get_param returned NULL");
483 struct yac_param * search_distance_param = NULL;
485 root_param,
"search_distance", &search_distance_param) != 0)
486 PUT_ERR(
"dnn get_param missing 'search_distance' subparam");
490 search_distance_param,
"fixed", &fixed_param) != 0)
491 PUT_ERR(
"dnn get_param failed to select search_distance.fixed");
493 PUT_ERR(
"dnn failed to set search_distance.fixed");
495 struct yac_param * cell_area_param = NULL;
497 search_distance_param,
"cell_area", &cell_area_param) == 0)
498 PUT_ERR(
"dnn oneof allowed selecting fixed and cell_area together");
510 if (!root_param)
PUT_ERR(
"dnn get_param returned NULL");
512 struct yac_param * search_distance_param = NULL;
514 root_param,
"search_distance", &search_distance_param) != 0)
515 PUT_ERR(
"dnn get_param missing 'search_distance' subparam");
517 struct yac_param * cell_area_param = NULL;
519 search_distance_param,
"cell_area", &cell_area_param) != 0)
520 PUT_ERR(
"dnn get_param failed to select search_distance.cell_area");
522 PUT_ERR(
"dnn failed to set search_distance.cell_area");
526 search_distance_param,
"fixed", &fixed_param) == 0)
527 PUT_ERR(
"dnn oneof allowed selecting cell_area and fixed together");
540 PUT_ERR(
"dnn default config has wrong type");
543 if (!root)
PUT_ERR(
"dnn get_param returned NULL");
547 PUT_ERR(
"dnn root param type should be STRUCT");
549 PUT_ERR(
"dnn root param name should be 'dnn'");
553 enum {REF_NUM_SUBPARAMS = 5};
556 PUT_ERR(
"dnn get_sub_count failed");
557 if (count != REF_NUM_SUBPARAMS)
558 PUT_ERR(
"dnn root should have 5 subparams");
564 PUT_ERR(
"dnn missing 'n_min' subparam");
567 PUT_ERR(
"dnn failed to read 'n_min' value");
569 PUT_ERR(
"dnn default 'n_min' value is wrong");
571 PUT_ERR(
"dnn 'n_min' should be at default");
577 PUT_ERR(
"dnn missing 'weighted' subparam");
578 int weighted_val = -1;
580 PUT_ERR(
"dnn failed to read 'weighted' value");
582 PUT_ERR(
"dnn default 'weighted' value is wrong");
584 PUT_ERR(
"dnn 'weighted' should be at default");
590 PUT_ERR(
"dnn missing 'search_distance' subparam");
593 struct yac_param *cell_area_param = NULL;
596 PUT_ERR(
"dnn default search_distance branch should be 'cell_area'");
599 double cell_area_val = -1.0;
601 PUT_ERR(
"dnn failed to read 'cell_area' value");
603 PUT_ERR(
"dnn default 'cell_area' scale value is wrong");
605 PUT_ERR(
"dnn 'cell_area' should be at default");
610 PUT_ERR(
"dnn default: 'fixed' branch should not be accessible "
611 "when 'cell_area' is active");
615 PUT_ERR(
"dnn root should report all-default");
627 if (!root_param)
PUT_ERR(
"dnn get_param returned NULL");
629 struct yac_param *search_distance_param = NULL;
631 root_param,
"search_distance", &search_distance_param) != 0)
632 PUT_ERR(
"dnn get_param missing 'search_distance' subparam");
638 search_distance_param,
"invalid_search_distance_type",
639 &invalid_param) == 0)
641 "config_dnn_search_distance_factory accepted invalid search "
642 "distance type name");
654 if (!root_param)
PUT_ERR(
"spmap get_param returned NULL");
656 struct yac_param *src_cell_area_param = NULL;
658 root_param,
"src_cell_area", &src_cell_area_param) != 0)
659 PUT_ERR(
"spmap get_param missing 'src_cell_area' subparam");
665 src_cell_area_param,
"invalid_area_type", &invalid_param) == 0)
667 "spmap_cell_area_config_factory accepted invalid cell area type");
681 PUT_ERR(
"convenience set/get int: expected n==7");
695 PUT_ERR(
"convenience set/get dble: expected max_search_distance==0.5");
708 if (!val || strcmp(val,
"gauss_weighted") != 0)
709 PUT_ERR(
"convenience set/get str: expected 'gauss_weighted'");
726 PUT_ERR(
"dot-path set/get dble: wrong value");
741 if (stack[0] == NULL)
742 PUT_ERR(
"generate after convenience set should not return NULL");
753 if (!a || !b)
PUT_ERR(
"nnn_create failed");
759 PUT_ERR(
"two configs set to same value should compare equal");
764 PUT_ERR(
"configs with different n should not compare equal");
779 int mpi_pack_size = (int)pack_size;
780 void *sendbuf = malloc(mpi_pack_size);
781 void *recvbuf = malloc(mpi_pack_size);
784 config, sendbuf, mpi_pack_size, &pos, MPI_COMM_SELF);
786 sendbuf, mpi_pack_size, MPI_PACKED, 0, 0,
787 recvbuf, mpi_pack_size, MPI_PACKED, 0, 0,
788 MPI_COMM_SELF, MPI_STATUS_IGNORE);
793 PUT_ERR(
"unpack after convenience set returned NULL");
795 PUT_ERR(
"pack/unpack roundtrip failed after convenience set");
799 PUT_ERR(
"convenience get after unpack: expected n==9");
812 PUT_ERR(
"spmap config creation failed");
815 size_t initial_size =
817 if (initial_size != 0)
818 PUT_ERR(
"expected empty overwrite list initially");
824 PUT_ERR(
"expected index 0 for first appended element");
826 size_t size_after_1 =
828 if (size_after_1 != 1)
829 PUT_ERR(
"expected list size 1 after one append");
833 config,
"overwrite.0.spread_distance", 0.05);
836 config,
"overwrite.0.spread_distance");
838 PUT_ERR(
"overwrite.0.spread_distance round-trip failed");
844 PUT_ERR(
"expected index 1 for second appended element");
847 config,
"overwrite.1.spread_distance", 0.10);
850 config,
"overwrite.1.spread_distance");
852 PUT_ERR(
"overwrite.1.spread_distance round-trip failed");
857 config,
"overwrite.0.spread_distance");
859 PUT_ERR(
"overwrite.0 was modified when setting overwrite.1");
880static struct yac_param * utest_get_subparam(
881 struct yac_param * param,
char const * subparam_name) {
886 fputs(
"failed to retrieve sub-parameter", stderr);
void yac_interp_method_delete(struct interp_method **method)
Delete an interpolation stack and free its resources (but not the pointer array).
@ YAC_N_NEAREST_NEIGHBOR
N-nearest-neighbor interpolation.
@ YAC_CREEP
Creep-fill interpolation.
@ YAC_USER_FILE
User-supplied weights from file.
@ YAC_SOURCE_TO_TARGET_MAP
Source-to-target mapping (inverse N-nearest-neighbor)
@ YAC_CONSERVATIVE
Conservative remapping (area/flux conserving)
@ YAC_FIXED_VALUE
Assigns a fixed value to all targets.
@ YAC_UNDEFINED
Undefined interpolation method.
@ YAC_CHECK
Diagnostic check method (for testing)
@ YAC_BERNSTEIN_BEZIER
Bernstein-Bezier interpolation.
@ YAC_DISTANCE_NEAREST_NEIGHBOR
Distance-nearest-neighbor interpolation.
@ YAC_NEAREST_CORNER_CELLS
Nearest-corner-cell interpolation.
@ YAC_RADIAL_BASIS_FUNCTION
Radial basis function interpolation.
@ YAC_AVERAGE
Simple averaging (or linear) interpolation.
int yac_interp_method_config_compare(const struct yac_interp_method_config *a, const struct yac_interp_method_config *b)
void yac_interp_method_config_set_param_int(struct yac_interp_method_config *config, char const *path, int value)
struct yac_param * yac_interp_method_config_get_param(struct yac_interp_method_config const *config)
enum yac_interpolation_list yac_interp_method_config_get_type(struct yac_interp_method_config const *config)
double yac_interp_method_config_get_param_dble(struct yac_interp_method_config const *config, char const *path)
size_t yac_interp_method_config_append_list_element(struct yac_interp_method_config *config, char const *path)
int yac_interp_method_config_get_param_int(struct yac_interp_method_config const *config, char const *path)
void yac_interp_method_config_pack(const struct yac_interp_method_config *config, void *buffer, int buffer_size, int *position, MPI_Comm comm)
size_t yac_interp_method_config_get_pack_size(const struct yac_interp_method_config *config, MPI_Comm comm)
struct yac_interp_method_config * yac_interp_method_config_copy(const struct yac_interp_method_config *config)
void yac_interp_method_config_set_param_dble(struct yac_interp_method_config *config, char const *path, double value)
char * yac_interp_method_config_get_param_str(struct yac_interp_method_config const *config, char const *path)
struct yac_interp_method_config * yac_interp_method_config_unpack(void *buffer, int buffer_size, int *position, MPI_Comm comm)
struct yac_interp_method_config * yac_interp_method_config_default_from_name_new(char const *method_name)
struct interp_method * yac_interp_method_config_generate(const struct yac_interp_method_config *config)
void yac_interp_method_config_set_param_str(struct yac_interp_method_config *config, char const *path, char const *value)
size_t yac_interp_method_config_get_list_size(struct yac_interp_method_config const *config, char const *path)
Defines the interface for interpolation method configuration "base class" in YAC.
void yac_interp_method_config_delete(struct yac_interp_method_config *config)
#define YAC_INTERP_DNN_N_MIN_DEFAULT
#define YAC_INTERP_DNN_WEIGHT_DEFAULT
#define YAC_INTERP_DNN_SEARCH_DISTANCE_CELL_AREA_DEFAULT
#define YAC_INTERP_NNN_N_MIN_DEFAULT
a value of 0 is interpreted as "use the value of n"
int yac_param_get_scalar_dble(const struct yac_param *param, double *value)
Get the value of a scalar parameter as a double.
int yac_param_is_default(const struct yac_param *param)
Check whether a parameter is at its default value.
int yac_param_set_scalar(struct yac_param *param, const char *value_str)
Set the value of a scalar parameter from a string.
enum yac_param_type yac_param_get_type(const struct yac_param *param)
Get the type of a parameter.
int yac_param_set_scalar_int(struct yac_param *param, int value)
Set the value of a scalar parameter as an int.
int yac_param_get_sub_count(const struct yac_param *param, size_t *count)
Get the number of subparameters.
int yac_param_set_scalar_dble(struct yac_param *param, double value)
Set the value of a scalar parameter as a double.
int yac_param_get_scalar_int(const struct yac_param *param, int *value)
Get the value of a scalar parameter as an int.
const char * yac_param_get_name(const struct yac_param *param)
Get the name of the current parameter.
int yac_param_get_sub_by_name(struct yac_param *param, const char *name, struct yac_param **sub_param)
Get a handle to a subparameter by name.
Public interface for YAC parameters.
@ YAC_PARAM_TYPE_STRUCT
Named, fixed set of subparameters.
Macros for testing code paths that are expected to abort.
#define YAC_TEST_EXPECT_ABORT_SERIAL( test_failed, expected_result, expected_substr,...)
@ YAC_TEST_ABORT_EXPECTED
abort was called with expected message
static struct yac_interp_method_config * config
#define PUT_ERR_F(fmt,...)