int main(void){ // test arrays int a[] = {2,5,8,3,1}; int b[] = {2,5,8,3,1}; int c[] = {2,6,7,8,2}; int d[] = {4,5,4,6,3}; size_t n = 5; check(array_max(a,n) == 8); printf("%d \n", array_max(a,n) == 8); printf("%d \n", array_index_of_first_max(a, n) == 2); printf("%d \n",array_index_of_last_max(a,n) == 2); printf("%d \n",array_equal(a, b, n) == 1); printf("%d \n", array_max(b,n) == 8); printf("%d \n", array_index_of_first_max(b, n) == 2); printf("%d \n",array_index_of_last_max(b,n) == 2); printf("%d \n",array_equal(a, b, n) == 1); printf("%d \n", array_max(c,n) == 8); printf("%d \n", array_index_of_first_max(c, n) == 3); printf("%d \n",array_index_of_last_max(c,n) == 3); printf("%d \n",array_equal(c, d, n) == 0); return 0; }
// **TODO**: Add an test. This function shows only the usage of `append_cb`. static char * test_single() { mpz_t a, b; mpz_array array1, array2, array_expect; mpz_pool pool; pool_init(&pool, 0); array_init(&array1, 3); array_init(&array2, 3); array_init(&array_expect, 3); // primes: 577, 727, 863 mpz_init_set_str(a, "577", 10); array_add(&array_expect, a); mpz_set_str(a, "727", 10); array_add(&array_expect, a); mpz_set_str(a, "863", 10); array_add(&array_expect, a); // `a = 727 * 577 = 419479` // `b = 727 * 863 = 627401` mpz_set_str(a, "419479", 10); mpz_init_set_str(b, "627401", 10); append_cb(&pool, &array1, a, b); if (mpz_cmp_ui(a, 419479) != 0) { return "append_cb has changed the input value a!"; } if (mpz_cmp_ui(b, 627401) != 0) { return "append_cb has changed the input value b!"; } array_msort(&array1); if (!array_equal(&array_expect, &array1)) { return "array1 and array_expect differ!"; } append_cb(&pool, &array2, b, a); if (mpz_cmp_ui(a, 419479) != 0) { return "append_cb has changed the input value a!"; } if (mpz_cmp_ui(b, 627401) != 0) { return "append_cb has changed the input value b!"; } array_msort(&array2); if (!array_equal(&array_expect, &array2)) { return "array2 and array_expect differ!"; } mpz_clear(a); mpz_clear(b); array_clear(&array1); array_clear(&array2); array_clear(&array_expect); pool_clear(&pool); return 0; }
// it should merge arrays of different sizes void test2(void) { double a[] = { 8.0 }; double b[] = { 4.0, 15.0, 16.0, 23.0, 42.0 }; double out[6]; double expected[6] = { 4, 8, 15, 16, 23, 42 }; merge(a, b, out, 1, 5); assert(array_equal(out, expected, 6)); merge(b, a, out, 5, 1); assert(array_equal(out, expected, 6)); }
// the result array should contain no duplicate values void test4(void) { double a[] = { 4, 15, 16, 23 }; double b[] = { 4, 8, 23, 42 }; double out[6]; double expected[] = { 4, 8, 15, 16, 23, 42 }; merge(a, b, out, 4, 4); assert(array_equal(out, expected, 6)); merge(b, a, out, 4, 4); assert(array_equal(out, expected, 6)); }
static void test_unallocated() { array x = {0}, y = {0}, z = {0}; array_cat(&x, &y); assert(array_equal(&x, &y)); assert(array_equal(&x, &z)); array_cat(&y, &x); assert(array_equal(&x, &y)); assert(array_equal(&x, &z)); }
// it should merge two sorted arrays void test1(void) { double a[] = { 4, 15, 16 }; double b[] = { 8, 23, 42 }; double out[6]; double expected[6] = { 4, 8, 15, 16, 23, 42 }; merge(a, b, out, 3, 3); assert(array_equal(out, expected, 6)); // the input order should not matter merge(b, a, out, 3, 3); assert(array_equal(out, expected, 6)); }
// **TODO**: Add an test. This function shows only the usage of `append_cb`. static char * test_multiple() { mpz_t a, b; mpz_array array1, array2, array_expect; mpz_pool pool; pool_init(&pool, 0); array_init(&array1, 3); array_init(&array2, 3); array_init(&array_expect, 3); // `30997 = 139 * 223` // `627401 = 727 * 863` // `182909 = 317 * 577` mpz_init_set_str(a, "30997", 10); array_add(&array_expect, a); mpz_set_str(a, "182909", 10); array_add(&array_expect, a); mpz_set_str(a, "627401", 10); array_add(&array_expect, a); // primes: 139, 223, 317, 577, 727, 863 // `a = 139 * 223 * 317 * 577 = 5669630273` // `b = 317 * 577 * 727 * 863 = 114757289509` mpz_set_str(a, "5669630273", 10); mpz_init_set_str(b, "114757289509", 10); append_cb(&pool, &array1, a, b); array_msort(&array1); if (!array_equal(&array_expect, &array1)) { return "array1 and array_expect differ!"; } append_cb(&pool, &array2, b, a); array_msort(&array2); if (!array_equal(&array_expect, &array2)) { return "array2 and array_expect differ!"; } mpz_clear(a); mpz_clear(b); array_clear(&array1); array_clear(&array2); array_clear(&array_expect); pool_clear(&pool); return 0; }
int main(){ int a[6]={1,3,5,7,9,11}; int b[3]={1,3,5}; printf("%s",array_equal(a,3,b,3)?"True":"False"); }
bool array_equal(struct array_descriptor* a1, struct array_descriptor* a2){ if(a1 == NULL && a2 == NULL) return true; if(a1 == NULL || a2 == NULL) return false; return array_equal(a1 -> subarray, a2 -> subarray); }
// **Test `test`**. static char * test() { mpz_array in1, in2, out, array_expect; mpz_t b; mpz_pool pool; pool_init(&pool, 0); array_init(&in1, 2); array_init(&in2, 2); array_init(&out, 5); array_init(&array_expect, 5); mpz_init_set_str(b, "317", 10); array_add(&array_expect, b); mpz_set_str(b, "577", 10); array_add(&array_expect, b); mpz_set_str(b, "727", 10); array_add(&array_expect, b); mpz_set_str(b, "196463", 10); array_add(&array_expect, b); mpz_set_str(b, "346063", 10); array_add(&array_expect, b); // primes: 401, [577], 727, 863 // `a = 727 * 577 = 419479` // `b = 401 * 863 = 346063` mpz_set_str(b, "419479", 10); array_add(&in1, b); mpz_set_str(b, "346063", 10); array_add(&in1, b); // primes: 317, 223, [577], 881 // `a = 317 * 577 = 182909` // `b = 223 * 881 = 196463` mpz_set_str(b, "182909", 10); array_add(&in2, b); mpz_set_str(b, "196463", 10); array_add(&in2, b); cbmerge(&pool, &out, &in1, &in2); array_msort(&out); if (!array_equal(&array_expect, &out)) { return "out and array_expect differ!"; } array_clear(&in1); array_clear(&in2); array_clear(&out); array_clear(&array_expect); mpz_clear(b); pool_clear(&pool); return 0; }
int main(int argc, char* argv[]) { int debug_flag; int n; int t; if (parse_args(argc, argv, &debug_flag, "input size", &n, "threads", &t, NULL, NULL, NULL, NULL) != 0) { fail("Error while parsing args."); } if ((n < 1) || (t < 1)) { fail("Bad input"); } omp_set_num_threads(t); ATYPE* data = geninput(n); int plus_ops = 0; int acc_ops = 0; if (debug_flag) print_array("input", data, n); double dtime; benchmark(data, n, &plus_ops, &acc_ops, &dtime); if (debug_flag) { /* ========== OUTPUT =========== */ print_array("output", data, n); print_perf_debug(n, t, plus_ops, acc_ops, dtime); ATYPE* ref = reference(n); if (array_equal(data, ref, n)) { printf("SUCCESS\n"); } else { printf("EPIC FAILURE\n"); } free(ref); } else { print_perf(n, t, plus_ops, acc_ops, dtime); } free(data); }
/*type compare and array compare*/ bool var_type_equal(struct var_descriptor* v1, struct var_descriptor* v2){ assert(v1 != NULL && v2 != NULL); if(!type_equal(v1 -> var_type, v2 -> var_type)) return false; if(!array_equal(v1 -> var_array, v2 -> var_array)) return false; //printf("equal\n"); return true; }
static void test_content() { static const char a[] = "left "; static const char b[] = "right"; static const char ab[] = "left right"; array x = {0}, y = {0}, z = {0}; array_catb(&x, a, strlen(a)); array_catb(&y, b, strlen(b)); array_catb(&z, ab, strlen(ab)); array_cat(&x, &y); assert(array_equal(&x, &z)); }
int main() { int aaa[] = { 1, 4, 3, 0, 8, 10, 48, 31 }; int bbb[] = { 1, 4, 3, 1000, 8, 10, 48, 31 }; int cmp_result = array_equal(aaa, bbb, 8); if (cmp_result) { printf("두 배열의 원소는 같다.\n"); } else { printf("두 배열의 원소는 다르다.\n"); } return 0; }
typename std::enable_if<types::has_shape<U>::value and types::has_shape<V>::value,bool>::type array_equiv(U const& u, V const&v) { if(u.shape == v.shape) { return array_equal(u,v); } else if(u.size() > v.size()) { return array_equiv(v,u); } else if(v.size()%u.size() ==0) { auto uu = asarray(u); auto vv = asarray(v); for(auto vi = vv.fbegin(), ve = vv.fend(); vi != ve;) for(auto ui = uu.fbegin(), ue = uu.fend(); ui != ue; ++ui, ++vi) if(*ui != *vi) return false; return true; } return false; }
int avro_datum_equal(const avro_datum_t a, const avro_datum_t b) { if (!(is_avro_datum(a) && is_avro_datum(b))) { return 0; } if (avro_typeof(a) != avro_typeof(b)) { return 0; } switch (avro_typeof(a)) { case AVRO_STRING: return strcmp(avro_datum_to_string(a)->s, avro_datum_to_string(b)->s) == 0; case AVRO_BYTES: return (avro_datum_to_bytes(a)->size == avro_datum_to_bytes(b)->size) && memcmp(avro_datum_to_bytes(a)->bytes, avro_datum_to_bytes(b)->bytes, avro_datum_to_bytes(a)->size) == 0; case AVRO_INT32: return avro_datum_to_int32(a)->i32 == avro_datum_to_int32(b)->i32; case AVRO_INT64: return avro_datum_to_int64(a)->i64 == avro_datum_to_int64(b)->i64; case AVRO_FLOAT: return avro_datum_to_float(a)->f == avro_datum_to_float(b)->f; case AVRO_DOUBLE: return avro_datum_to_double(a)->d == avro_datum_to_double(b)->d; case AVRO_BOOLEAN: return avro_datum_to_boolean(a)->i == avro_datum_to_boolean(b)->i; case AVRO_NULL: return 1; case AVRO_ARRAY: return array_equal(avro_datum_to_array(a), avro_datum_to_array(b)); case AVRO_MAP: return map_equal(avro_datum_to_map(a), avro_datum_to_map(b)); case AVRO_RECORD: return record_equal(avro_datum_to_record(a), avro_datum_to_record(b)); case AVRO_ENUM: return enum_equal(avro_datum_to_enum(a), avro_datum_to_enum(b)); case AVRO_FIXED: return fixed_equal(avro_datum_to_fixed(a), avro_datum_to_fixed(b)); case AVRO_UNION: return union_equal(avro_datum_to_union(a), avro_datum_to_union(b)); case AVRO_LINK: /* * TODO */ return 0; } return 0; }
typename std::enable_if<U::value == V::value, bool>::type array_equiv(U const &u, V const &v) { return array_equal(u, v); }
typename std::enable_if<types::has_shape<V>::value,bool>::type array_equal(types::list<U> const& u, V const&v) { return array_equal(typename types::numpy_expr_to_ndarray<types::list<U>>::type(u), v); }
typename std::enable_if<types::has_shape<U>::value,bool>::type array_equal(U const& u, types::list<V> const&v) { return array_equal(u, typename types::numpy_expr_to_ndarray<types::list<V>>::type(v)); }
bool array_equal(types::list<U> const& u, types::list<V> const&v) { return array_equal(typename types::numpy_expr_to_ndarray<types::list<U>>::type(u), typename types::numpy_expr_to_ndarray<types::list<V>>::type(v)); }
void SparseVectorCompressed<T>::set(const MyT& v) { makeSimilar(v); array_equal(vals,v.vals,num_entries); }