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

Function af_create_strided_array

src/api/c/internal.cpp:34–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32using detail::ushort;
33
34af_err af_create_strided_array(af_array *arr, const void *data,
35 const dim_t offset, const unsigned ndims,
36 const dim_t *const dims_,
37 const dim_t *const strides_, const af_dtype ty,
38 const af_source location) {
39 try {
40 ARG_ASSERT(2, offset >= 0);
41 ARG_ASSERT(3, ndims >= 1 && ndims <= 4);
42 ARG_ASSERT(4, dims_ != NULL);
43 ARG_ASSERT(5, strides_ != NULL);
44 ARG_ASSERT(5, strides_[0] == 1);
45
46 for (int i = 1; i < static_cast<int>(ndims); i++) {
47 ARG_ASSERT(5, strides_[i] > 0);
48 }
49
50 dim4 dims(ndims, dims_);
51 dim4 strides(ndims, strides_);
52
53 for (int i = static_cast<int>(ndims); i < 4; i++) {
54 strides[i] = strides[i - 1] * dims[i - 1];
55 }
56
57 bool isdev = location == afDevice;
58
59 af_array res;
60 AF_CHECK(af_init());
61
62 void *in_data = const_cast<void *>(
63 data); // const cast because the api cannot change
64 switch (ty) {
65 case f32:
66 res = getHandle(createStridedArray<float>(
67 dims, strides, offset, static_cast<float *>(in_data),
68 isdev));
69 break;
70 case f64:
71 res = getHandle(createStridedArray<double>(
72 dims, strides, offset, static_cast<double *>(in_data),
73 isdev));
74 break;
75 case c32:
76 res = getHandle(createStridedArray<cfloat>(
77 dims, strides, offset, static_cast<cfloat *>(in_data),
78 isdev));
79 break;
80 case c64:
81 res = getHandle(createStridedArray<cdouble>(
82 dims, strides, offset, static_cast<cdouble *>(in_data),
83 isdev));
84 break;
85 case u32:
86 res = getHandle(createStridedArray<uint>(
87 dims, strides, offset, static_cast<uint *>(in_data),
88 isdev));
89 break;
90 case s32:
91 res = getHandle(createStridedArray<int>(

Callers 1

createStridedArrayFunction · 0.50

Calls 3

swapFunction · 0.85
af_initFunction · 0.70
getHandleFunction · 0.70

Tested by

no test coverage detected