Skip to content

Commit 5ab3e99

Browse files
pradeepumar456
authored andcommitted
Fix checks in af::seq() & indexing/assignment fns
* Implement convert2Cononical helper function that converts the user provided af::seq to a canonical form where the sequences begin and end lie within the [0,len] range of the input array along a specified dimension. * Refactors moddims & flatten functions to enable using them from `src/api/c/` level * Adds createHandle version that accepts af_array * Reduces c-api calls to as minimum as possible in `src/api/c/index.cpp` and `src/api/c/assign.cpp` * Fixes style in lookup source files and asign test (cherry picked from commit 36dfda8)
1 parent cca98cb commit 5ab3e99

17 files changed

Lines changed: 574 additions & 445 deletions

File tree

include/af/index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/// object with the same \ref af_seq::begin and \ref af_seq::end with an
2121
/// af_seq::step of 1
2222
///
23-
typedef struct af_index_t{
23+
typedef struct af_index_t {
2424
union {
2525
af_array arr; ///< The af_array used for indexing
2626
af_seq seq; ///< The af_seq used for indexing

src/api/c/array.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,21 @@ af_err af_create_array(af_array *result, const void * const data,
7676
}
7777

7878
//Strong Exception Guarantee
79-
af_err af_create_handle(af_array *result, const unsigned ndims, const dim_t * const dims,
79+
af_err af_create_handle(af_array *result,
80+
const unsigned ndims, const dim_t * const dims,
8081
const af_dtype type)
8182
{
8283
try {
83-
af_array out = 0;
8484
AF_CHECK(af_init());
8585

86-
if (ndims > 0) {
87-
ARG_ASSERT(2, ndims > 0 && dims != NULL);
88-
}
86+
if (ndims > 0) ARG_ASSERT(2, ndims > 0 && dims != NULL);
87+
8988
dim4 d(0);
9089
for(unsigned i = 0; i < ndims; i++) {
9190
d[i] = dims[i];
9291
}
9392

94-
switch(type) {
95-
case f32: out = createHandle<float >(d); break;
96-
case c32: out = createHandle<cfloat >(d); break;
97-
case f64: out = createHandle<double >(d); break;
98-
case c64: out = createHandle<cdouble>(d); break;
99-
case b8: out = createHandle<char >(d); break;
100-
case s32: out = createHandle<int >(d); break;
101-
case u32: out = createHandle<uint >(d); break;
102-
case u8: out = createHandle<uchar >(d); break;
103-
case s64: out = createHandle<intl >(d); break;
104-
case u64: out = createHandle<uintl >(d); break;
105-
case s16: out = createHandle<short >(d); break;
106-
case u16: out = createHandle<ushort >(d); break;
107-
default: TYPE_ERROR(3, type);
108-
}
93+
af_array out = createHandle(d, type);
10994
std::swap(*result, out);
11095
}
11196
CATCHALL

0 commit comments

Comments
 (0)