MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / TEST

Function TEST

test/index.cpp:588–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586}
587
588TEST(Index, Docs_Util_C_API) {
589 // clang-format off
590 ASSERT_EQ(0, ([]() -> int {
591 //![ex_index_util_0]
592 af_index_t *indexers = 0;
593 af_err err = af_create_indexers(&indexers); // Memory is allocated on heap by the callee
594 // by default all the indexers span all the elements along
595 // the given dimension
596
597 // Create array
598 af_array a;
599 unsigned ndims = 2;
600 dim_t dim[] = {10, 10};
601 af_randu(&a, ndims, dim, f32);
602
603 // Create index array
604 af_array idx;
605 unsigned n = 1;
606 dim_t d[] = {5};
607 af_range(&idx, n, d, 0, s32);
608
609 af_print_array(a);
610 af_print_array(idx);
611
612 // create array indexer
613 err = af_set_array_indexer(indexers, idx, 1);
614
615 // index with indexers
616 af_array out;
617 err = af_index_gen(&out, a, 2, indexers); // number of indexers should be two since
618 // we have set only second af_index_t
619 if (err != AF_SUCCESS) {
620 printf("Failed in af_index_gen: %d\n", err);
621 return 1;
622 }
623 af_print_array(out);
624 af_release_array(out);
625
626 af_seq zeroIndices = af_make_seq(0.0, 9.0, 2.0);
627
628 err = af_set_seq_indexer(indexers, &zeroIndices, 0, false);
629
630 err = af_index_gen(&out, a, 2, indexers);
631 if (err != AF_SUCCESS) {
632 printf("Failed in af_index_gen: %d\n", err);
633 return 1;
634 }
635 af_print_array(out);
636
637 af_release_indexers(indexers);
638 af_release_array(a);
639 af_release_array(idx);
640 af_release_array(out);
641 return 0;
642 //![ex_index_util_0]
643 }()));
644 // clang-format on
645}

Callers

nothing calls this directly

Calls 15

make_vecFunction · 0.85
cleanSlateFunction · 0.85
constantFunction · 0.85
moddimsFunction · 0.85
powFunction · 0.85
randuFunction · 0.85
freeHostFunction · 0.85
seqClass · 0.85
cpp_scope_seq_testFunction · 0.85
cpp_scope_arr_testFunction · 0.85
deviceGCFunction · 0.85
deviceMemInfoFunction · 0.85

Tested by

no test coverage detected