本文整理汇总了C++中ArrayInfo类的典型用法代码示例。如果您正苦于以下问题:C++ ArrayInfo类的具体用法?C++ ArrayInfo怎么用?C++ ArrayInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: af_medfilt
af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
{
try {
ARG_ASSERT(2, (wind_length==wind_width));
ARG_ASSERT(2, (wind_length>0));
ARG_ASSERT(3, (wind_width>0));
ARG_ASSERT(4, (edge_pad>=AF_PAD_ZERO && edge_pad<=AF_PAD_SYM));
ArrayInfo info = getInfo(in);
af::dim4 dims = info.dims();
dim_t input_ndims = dims.ndims();
DIM_ASSERT(1, (input_ndims >= 2));
if (wind_length==1) {
*out = retain(in);
} else {
af_array output;
af_dtype type = info.getType();
switch(type) {
case f32:
output = medfilt<float >(in, wind_length, wind_width, edge_pad);
break;
case f64:
output = medfilt<double>(in, wind_length, wind_width, edge_pad);
break;
case b8 :
output = medfilt<char >(in, wind_length, wind_width, edge_pad);
break;
case s32:
output = medfilt<int >(in, wind_length, wind_width, edge_pad);
break;
case u32:
output = medfilt<uint >(in, wind_length, wind_width, edge_pad);
break;
case u8 :
output = medfilt<uchar >(in, wind_length, wind_width, edge_pad);
break;
default :
TYPE_ERROR(1, type);
}
std::swap(*out, output);
}
}
CATCHALL;
return AF_SUCCESS;
}
示例2: af_assign
af_err af_assign(af_array *out,
const af_array lhs, const unsigned ndims,
const af_seq *index, const af_array rhs)
{
try {
ARG_ASSERT(0, (lhs!=0));
ARG_ASSERT(1, (ndims>0));
ARG_ASSERT(3, (rhs!=0));
for(dim_type i=0; i<(dim_type)ndims; ++i) {
ARG_ASSERT(2, (index[i].step>=0));
}
af_array res;
if (*out != lhs) AF_CHECK(af_copy_array(&res, lhs));
else res = weakCopy(lhs);
try {
if (lhs != rhs) {
ArrayInfo oInfo = getInfo(lhs);
af_dtype oType = oInfo.getType();
switch(oType) {
case c64: assign<cdouble, true >(res, ndims, index, rhs); break;
case c32: assign<cfloat , true >(res, ndims, index, rhs); break;
case f64: assign<double , false>(res, ndims, index, rhs); break;
case f32: assign<float , false>(res, ndims, index, rhs); break;
case s32: assign<int , false>(res, ndims, index, rhs); break;
case u32: assign<uint , false>(res, ndims, index, rhs); break;
case u8 : assign<uchar , false>(res, ndims, index, rhs); break;
case b8 : assign<char , false>(res, ndims, index, rhs); break;
default : TYPE_ERROR(1, oType); break;
}
}
} catch(...) {
if (*out != lhs) {
AF_CHECK(af_destroy_array(res));
}
throw;
}
std::swap(*out, res);
}
CATCHALL;
return AF_SUCCESS;
}
示例3: af_rotate
af_err af_rotate(af_array *out, const af_array in, const float theta,
const bool crop,
const af_interp_type method)
{
try {
unsigned odims0 = 0, odims1 = 0;
ArrayInfo info = getInfo(in);
af::dim4 idims = info.dims();
if(!crop) {
odims0 = idims[0] * fabs(std::cos(theta)) + idims[1] * fabs(std::sin(theta));
odims1 = idims[1] * fabs(std::cos(theta)) + idims[0] * fabs(std::sin(theta));
} else {
odims0 = idims[0];
odims1 = idims[1];
}
af_dtype itype = info.getType();
ARG_ASSERT(3, method == AF_INTERP_NEAREST ||
method == AF_INTERP_BILINEAR ||
method == AF_INTERP_LOWER);
DIM_ASSERT(1, idims.elements() > 0);
af::dim4 odims(odims0, odims1, idims[2], idims[3]);
af_array output = 0;
switch(itype) {
case f32: output = rotate<float >(in, theta, odims, method); break;
case f64: output = rotate<double >(in, theta, odims, method); break;
case c32: output = rotate<cfloat >(in, theta, odims, method); break;
case c64: output = rotate<cdouble>(in, theta, odims, method); break;
case s32: output = rotate<int >(in, theta, odims, method); break;
case u32: output = rotate<uint >(in, theta, odims, method); break;
case s64: output = rotate<intl >(in, theta, odims, method); break;
case u64: output = rotate<uintl >(in, theta, odims, method); break;
case u8: output = rotate<uchar >(in, theta, odims, method); break;
case b8: output = rotate<uchar >(in, theta, odims, method); break;
default: TYPE_ERROR(1, itype);
}
std::swap(*out,output);
} CATCHALL
return AF_SUCCESS;
}
示例4: af_assign_seq
af_err af_assign_seq(af_array *out,
const af_array lhs, const unsigned ndims,
const af_seq *index, const af_array rhs)
{
try {
ARG_ASSERT(0, (lhs!=0));
ARG_ASSERT(1, (ndims>0));
ARG_ASSERT(3, (rhs!=0));
for(dim_t i=0; i<(dim_t)ndims; ++i) {
ARG_ASSERT(2, (index[i].step>=0));
}
af_array res;
if (*out != lhs) AF_CHECK(af_copy_array(&res, lhs));
else res = retain(lhs);
try {
if (lhs != rhs) {
ArrayInfo oInfo = getInfo(lhs);
af_dtype oType = oInfo.getType();
switch(oType) {
case c64: assign_helper<cdouble>(getWritableArray<cdouble>(res), ndims, index, rhs); break;
case c32: assign_helper<cfloat >(getWritableArray<cfloat >(res), ndims, index, rhs); break;
case f64: assign_helper<double >(getWritableArray<double >(res), ndims, index, rhs); break;
case f32: assign_helper<float >(getWritableArray<float >(res), ndims, index, rhs); break;
case s32: assign_helper<int >(getWritableArray<int >(res), ndims, index, rhs); break;
case u32: assign_helper<uint >(getWritableArray<uint >(res), ndims, index, rhs); break;
case s64: assign_helper<intl >(getWritableArray<intl >(res), ndims, index, rhs); break;
case u64: assign_helper<uintl >(getWritableArray<uintl >(res), ndims, index, rhs); break;
case u8 : assign_helper<uchar >(getWritableArray<uchar >(res), ndims, index, rhs); break;
case b8 : assign_helper<char >(getWritableArray<char >(res), ndims, index, rhs); break;
default : TYPE_ERROR(1, oType); break;
}
}
} catch(...) {
af_release_array(res);
throw;
}
std::swap(*out, res);
}
CATCHALL;
return AF_SUCCESS;
}
示例5: af_histogram
af_err af_histogram(af_array *out, const af_array in,
const unsigned nbins, const double minval, const double maxval)
{
try {
ArrayInfo info = getInfo(in);
af_dtype type = info.getType();
af_array output;
switch(type) {
case f32: output = histogram<float , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case f64: output = histogram<double, uint>(in, nbins, minval, maxval, info.isLinear()); break;
case b8 : output = histogram<char , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case s32: output = histogram<int , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case u32: output = histogram<uint , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case s16: output = histogram<short , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case u16: output = histogram<ushort, uint>(in, nbins, minval, maxval, info.isLinear()); break;
case s64: output = histogram<intl , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case u64: output = histogram<uintl , uint>(in, nbins, minval, maxval, info.isLinear()); break;
case u8 : output = histogram<uchar , uint>(in, nbins, minval, maxval, info.isLinear()); break;
default : TYPE_ERROR(1, type);
}
std::swap(*out,output);
}
CATCHALL;
return AF_SUCCESS;
}
示例6: print
static void print(af_array arr)
{
const ArrayInfo info = getInfo(arr);
T *data = new T[info.elements()];
af_array arrT;
AF_CHECK(af_reorder(&arrT, arr, 1, 0, 2, 3));
//FIXME: Use alternative function to avoid copies if possible
AF_CHECK(af_get_data_ptr(data, arrT));
const ArrayInfo infoT = getInfo(arrT);
AF_CHECK(af_destroy_array(arrT));
std::ios_base::fmtflags backup = std::cout.flags();
std::cout << "[" << info.dims() << "]\n";
#ifndef NDEBUG
std::cout <<" Offsets: ["<<info.offsets()<<"]"<<std::endl;
std::cout <<" Strides: ["<<info.strides()<<"]"<<std::endl;
#endif
printer(std::cout, data, infoT, infoT.ndims() - 1);
delete[] data;
std::cout.flags(backup);
}
示例7: sort_by_key_tmplt
void sort_by_key_tmplt(af_array *okey, af_array *oval, const af_array ikey, const af_array ival,
const unsigned dim, const bool isAscending)
{
ArrayInfo info = getInfo(ival);
af_dtype vtype = info.getType();
switch(vtype) {
case f32: sort_by_key<Tk, float >(okey, oval, ikey, ival, dim, isAscending); break;
case f64: sort_by_key<Tk, double >(okey, oval, ikey, ival, dim, isAscending); break;
case s32: sort_by_key<Tk, int >(okey, oval, ikey, ival, dim, isAscending); break;
case u32: sort_by_key<Tk, uint >(okey, oval, ikey, ival, dim, isAscending); break;
case u8: sort_by_key<Tk, uchar >(okey, oval, ikey, ival, dim, isAscending); break;
case b8: sort_by_key<Tk, char >(okey, oval, ikey, ival, dim, isAscending); break;
default: TYPE_ERROR(1, vtype);
}
return;
}
示例8: lookup
static af_array lookup(const af_array &in, const af_array &idx, const unsigned dim)
{
ArrayInfo inInfo = getInfo(in);
af_dtype inType = inInfo.getType();
switch(inType) {
case f32: return getHandle(lookup<float , idx_t > (getArray<float >(in), getArray<idx_t>(idx), dim));
case c32: return getHandle(lookup<cfloat , idx_t > (getArray<cfloat >(in), getArray<idx_t>(idx), dim));
case f64: return getHandle(lookup<double , idx_t > (getArray<double >(in), getArray<idx_t>(idx), dim));
case c64: return getHandle(lookup<cdouble , idx_t > (getArray<cdouble >(in), getArray<idx_t>(idx), dim));
case s32: return getHandle(lookup<int , idx_t > (getArray<int >(in), getArray<idx_t>(idx), dim));
case u32: return getHandle(lookup<unsigned, idx_t > (getArray<unsigned>(in), getArray<idx_t>(idx), dim));
case u8: return getHandle(lookup<uchar , idx_t > (getArray<uchar >(in), getArray<idx_t>(idx), dim));
case b8: return getHandle(lookup<char , idx_t > (getArray<char >(in), getArray<idx_t>(idx), dim));
default : TYPE_ERROR(1, inType);
}
}
示例9: af_print_array
af_err af_print_array(af_array arr)
{
try {
ArrayInfo info = getInfo(arr);
af_dtype type = info.getType();
switch(type)
{
case f32:
print<float>(arr);
break;
case c32:
print<cfloat>(arr);
break;
case f64:
print<double>(arr);
break;
case c64:
print<cdouble>(arr);
break;
case b8:
print<char>(arr);
break;
case s32:
print<int>(arr);
break;
case u32:
print<unsigned>(arr);
break;
case u8:
print<uchar>(arr);
break;
case s64:
print<intl>(arr);
break;
case u64:
print<uintl>(arr);
break;
default:
TYPE_ERROR(1, type);
}
}
CATCHALL;
return AF_SUCCESS;
}
示例10: af_release_array
af_err af_release_array(af_array arr)
{
try {
int dev = getActiveDeviceId();
ArrayInfo info = getInfo(arr, false, false);
af_dtype type = info.getType();
if(info.isSparse()) {
switch(type) {
case f32: releaseSparseHandle<float >(arr); break;
case f64: releaseSparseHandle<double >(arr); break;
case c32: releaseSparseHandle<cfloat >(arr); break;
case c64: releaseSparseHandle<cdouble>(arr); break;
default : TYPE_ERROR(0, type);
}
} else {
setDevice(info.getDevId());
switch(type) {
case f32: releaseHandle<float >(arr); break;
case c32: releaseHandle<cfloat >(arr); break;
case f64: releaseHandle<double >(arr); break;
case c64: releaseHandle<cdouble >(arr); break;
case b8: releaseHandle<char >(arr); break;
case s32: releaseHandle<int >(arr); break;
case u32: releaseHandle<uint >(arr); break;
case u8: releaseHandle<uchar >(arr); break;
case s64: releaseHandle<intl >(arr); break;
case u64: releaseHandle<uintl >(arr); break;
case s16: releaseHandle<short >(arr); break;
case u16: releaseHandle<ushort >(arr); break;
default: TYPE_ERROR(0, type);
}
setDevice(dev);
}
}
CATCHALL
return AF_SUCCESS;
}
示例11: af_reorder
af_err af_reorder(af_array *out, const af_array in, const af::dim4 &rdims)
{
try {
ArrayInfo info = getInfo(in);
af_dtype type = info.getType();
DIM_ASSERT(1, info.elements() > 0);
// Check that dimensions are not repeated
int allDims[] = {0, 1, 2, 3};
for(int i = 0; i < 3; i++) {
DIM_ASSERT(i + 2, rdims[i] == allDims[rdims[i]]);
allDims[rdims[i]] = -1;
}
// If reorder is a (batched) transpose, then call transpose
if(info.dims()[3] == 1) {
if(rdims[0] == 1 && rdims[1] == 0 &&
rdims[2] == 2 && rdims[3] == 3) {
return af_transpose(out, in);
}
}
af_array output;
switch(type) {
case f32: output = reorder<float >(in, rdims); break;
case c32: output = reorder<cfloat >(in, rdims); break;
case f64: output = reorder<double >(in, rdims); break;
case c64: output = reorder<cdouble>(in, rdims); break;
case b8: output = reorder<char >(in, rdims); break;
case s32: output = reorder<int >(in, rdims); break;
case u32: output = reorder<uint >(in, rdims); break;
case u8: output = reorder<uchar >(in, rdims); break;
case s8: output = reorder<char >(in, rdims); break;
default: TYPE_ERROR(1, type);
}
std::swap(*out,output);
}
CATCHALL;
return AF_SUCCESS;
}
示例12: af_dot
af_err af_dot( af_array *out,
const af_array lhs, const af_array rhs,
const af_mat_prop optLhs, const af_mat_prop optRhs)
{
using namespace detail;
try {
ArrayInfo lhsInfo = getInfo(lhs);
ArrayInfo rhsInfo = getInfo(rhs);
if (optLhs != AF_MAT_NONE && optLhs != AF_MAT_CONJ) {
AF_ERROR("Using this property is not yet supported in dot", AF_ERR_NOT_SUPPORTED);
}
if (optRhs != AF_MAT_NONE && optRhs != AF_MAT_CONJ) {
AF_ERROR("Using this property is not yet supported in dot", AF_ERR_NOT_SUPPORTED);
}
DIM_ASSERT(1, lhsInfo.dims()[0] == rhsInfo.dims()[0]);
af_dtype lhs_type = lhsInfo.getType();
af_dtype rhs_type = rhsInfo.getType();
if(lhsInfo.ndims() == 0) {
return af_retain_array(out, lhs);
}
if (lhsInfo.ndims() > 1 ||
rhsInfo.ndims() > 1) {
AF_ERROR("dot can not be used in batch mode", AF_ERR_BATCH);
}
TYPE_ASSERT(lhs_type == rhs_type);
af_array output = 0;
switch(lhs_type) {
case f32: output = dot<float >(lhs, rhs, optLhs, optRhs); break;
case c32: output = dot<cfloat >(lhs, rhs, optLhs, optRhs); break;
case f64: output = dot<double >(lhs, rhs, optLhs, optRhs); break;
case c64: output = dot<cdouble>(lhs, rhs, optLhs, optRhs); break;
default: TYPE_ERROR(1, lhs_type);
}
std::swap(*out, output);
}
CATCHALL
return AF_SUCCESS;
}
示例13: af_matmul
af_err af_matmul( af_array *out,
const af_array lhs, const af_array rhs,
const af_mat_prop optLhs, const af_mat_prop optRhs)
{
using namespace detail;
try {
ArrayInfo lhsInfo = getInfo(lhs);
ArrayInfo rhsInfo = getInfo(rhs);
af_dtype lhs_type = lhsInfo.getType();
af_dtype rhs_type = rhsInfo.getType();
if (!(optLhs == AF_MAT_NONE ||
optLhs == AF_MAT_TRANS ||
optLhs == AF_MAT_CTRANS)) {
AF_ERROR("Using this property is not yet supported in matmul", AF_ERR_NOT_SUPPORTED);
}
if (!(optRhs == AF_MAT_NONE ||
optRhs == AF_MAT_TRANS ||
optRhs == AF_MAT_CTRANS)) {
AF_ERROR("Using this property is not yet supported in matmul", AF_ERR_NOT_SUPPORTED);
}
if (lhsInfo.ndims() > 2 ||
rhsInfo.ndims() > 2) {
AF_ERROR("matmul can not be used in batch mode", AF_ERR_BATCH);
}
TYPE_ASSERT(lhs_type == rhs_type);
af_array output = 0;
int aColDim = (optLhs == AF_MAT_NONE) ? 1 : 0;
int bRowDim = (optRhs == AF_MAT_NONE) ? 0 : 1;
DIM_ASSERT(1, lhsInfo.dims()[aColDim] == rhsInfo.dims()[bRowDim]);
switch(lhs_type) {
case f32: output = matmul<float >(lhs, rhs, optLhs, optRhs); break;
case c32: output = matmul<cfloat >(lhs, rhs, optLhs, optRhs); break;
case f64: output = matmul<double >(lhs, rhs, optLhs, optRhs); break;
case c64: output = matmul<cdouble>(lhs, rhs, optLhs, optRhs); break;
default: TYPE_ERROR(1, lhs_type);
}
std::swap(*out, output);
}
CATCHALL
return AF_SUCCESS;
}
示例14: sort_by_key_tmplt
af_err sort_by_key_tmplt(af_array *okey, af_array *oval, const af_array ikey, const af_array ival,
const unsigned dim, const bool dir)
{
try {
ArrayInfo info = getInfo(ival);
af_dtype vtype = info.getType();
switch(vtype) {
case f32: sort_by_key<Tk, float >(okey, oval, ikey, ival, dim, dir); break;
case f64: sort_by_key<Tk, double >(okey, oval, ikey, ival, dim, dir); break;
case s32: sort_by_key<Tk, int >(okey, oval, ikey, ival, dim, dir); break;
case u32: sort_by_key<Tk, uint >(okey, oval, ikey, ival, dim, dir); break;
case u8: sort_by_key<Tk, uchar >(okey, oval, ikey, ival, dim, dir); break;
// case s8: sort_by_key<Tk, char >(okey, oval, ikey, ival, dim, dir); break;
default: TYPE_ERROR(1, vtype);
}
}
CATCHALL;
return AF_SUCCESS;
}
示例15: af_sort_by_key
af_err af_sort_by_key(af_array *out_keys, af_array *out_values,
const af_array keys, const af_array values,
const unsigned dim, const bool isAscending)
{
try {
ArrayInfo info = getInfo(keys);
af_dtype type = info.getType();
ArrayInfo vinfo = getInfo(values);
DIM_ASSERT(3, info.elements() > 0);
DIM_ASSERT(4, info.dims() == vinfo.dims());
// Only Dim 0 supported
ARG_ASSERT(5, dim == 0);
af_array oKey;
af_array oVal;
switch(type) {
case f32: sort_by_key_tmplt<float >(&oKey, &oVal, keys, values, dim, isAscending); break;
case f64: sort_by_key_tmplt<double >(&oKey, &oVal, keys, values, dim, isAscending); break;
case s32: sort_by_key_tmplt<int >(&oKey, &oVal, keys, values, dim, isAscending); break;
case u32: sort_by_key_tmplt<uint >(&oKey, &oVal, keys, values, dim, isAscending); break;
case u8: sort_by_key_tmplt<uchar >(&oKey, &oVal, keys, values, dim, isAscending); break;
case b8: sort_by_key_tmplt<char >(&oKey, &oVal, keys, values, dim, isAscending); break;
default: TYPE_ERROR(1, type);
}
std::swap(*out_keys , oKey);
std::swap(*out_values , oVal);
}
CATCHALL;
return AF_SUCCESS;
}