当前位置: 首页>>代码示例>>C++>>正文


C++ dim4类代码示例

本文整理汇总了C++中dim4的典型用法代码示例。如果您正苦于以下问题:C++ dim4类的具体用法?C++ dim4怎么用?C++ dim4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了dim4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: constant

 array constant(cfloat val, const dim4 &dims)
 {
     af_array res;
     AF_THROW(af_constant_complex(&res, real(val), imag(val),
                                  dims.ndims(), dims.get(), c32));
     return array(res);
 }
开发者ID:maolingao,项目名称:arrayfire,代码行数:7,代码来源:data.cpp

示例2: convolve2

Array<T> convolve2(Array<T> const& signal, Array<accT> const& c_filter, Array<accT> const& r_filter)
{
    const dim4 cfDims   = c_filter.dims();
    const dim4 rfDims   = r_filter.dims();

    const dim_t cfLen= cfDims.elements();
    const dim_t rfLen= rfDims.elements();

    const dim4 sDims = signal.dims();
    dim4 tDims = sDims;
    dim4 oDims = sDims;

    if (expand) {
        tDims[0] += cfLen - 1;
        oDims[0] += cfLen - 1;
        oDims[1] += rfLen - 1;
    }

    Array<T> temp= createEmptyArray<T>(tDims);
    Array<T> out = createEmptyArray<T>(oDims);

    kernel::convolve2<T, accT, 0, expand>(temp, signal, c_filter);
    kernel::convolve2<T, accT, 1, expand>(out, temp, r_filter);

    return out;
}
开发者ID:AshwinRajendraprasad,项目名称:arrayfire,代码行数:26,代码来源:convolve.cpp

示例3: ArrayInfo

Array<T>::Array(dim4 dims, const T * const in_data):
    ArrayInfo(getActiveDeviceId(), dims, dim4(0,0,0,0), calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
    data(memAlloc<T>(dims.elements()), memFree<T>), data_dims(dims),
    node(), ready(true), offset(0), owner(true)
{
    std::copy(in_data, in_data + dims.elements(), data.get());
}
开发者ID:klemmster,项目名称:arrayfire,代码行数:7,代码来源:Array.cpp

示例4: assign

static
void assign(af_array &out, const unsigned &ndims, const af_seq *index, const af_array &in)
{
    ArrayInfo iInfo = getInfo(in);
    ArrayInfo oInfo = getInfo(out);
    af_dtype iType  = iInfo.getType();

    dim4 const outDs = oInfo.dims();
    dim4 const iDims = iInfo.dims();

    ARG_ASSERT(0, (outDs.ndims()>=iDims.ndims()));
    ARG_ASSERT(1, (outDs.ndims()>=(int)ndims));

    AF_CHECK(af_eval(out));

    vector<af_seq> index_(index, index+ndims);
    dim4 const oStrides = af::toStride(index_, outDs);

    dim4 oDims = af::toDims(index_, outDs);
    dim4 oOffsets = af::toOffset(index_, outDs);

    Array<T> *dst = createRefArray<T>(getArray<T>(out), oDims, oOffsets, oStrides);

    for (int i = 0; i < 4; i++) {
        if (oDims[i] != iDims[i])
            AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE);
    }

    bool noCaseExecuted = true;
    if (isComplex) {
        noCaseExecuted = false;
        switch(iType) {
            case c64: copy<cdouble, T>(*dst, getArray<cdouble>(in), scalar<T>(0), 1.0);  break;
            case c32: copy<cfloat , T>(*dst, getArray<cfloat >(in), scalar<T>(0), 1.0);  break;
            default : noCaseExecuted = true; break;
        }
    }

    static const T ZERO = scalar<T>(0);
    if(noCaseExecuted) {
        noCaseExecuted = false;
        switch(iType) {
            case f64: copy<double , T>(*dst, getArray<double>(in), ZERO, 1.0);  break;
            case f32: copy<float  , T>(*dst, getArray<float >(in), ZERO, 1.0);  break;
            case s32: copy<int    , T>(*dst, getArray<int   >(in), ZERO, 1.0);  break;
            case u32: copy<uint   , T>(*dst, getArray<uint  >(in), ZERO, 1.0);  break;
            case u8 : copy<uchar  , T>(*dst, getArray<uchar >(in), ZERO, 1.0);  break;
            case b8 : copy<char   , T>(*dst, getArray<char  >(in), ZERO, 1.0);  break;
            default : noCaseExecuted = true; break;
        }
    }

    if (noCaseExecuted)
        TYPE_ERROR(1, iType);

    delete dst;
}
开发者ID:pavanky,项目名称:arrayfire,代码行数:57,代码来源:assign.cpp

示例5: constant

 AFAPI array constant(cdouble val, const dim4 &dims, const af::dtype type)
 {
     if (type != c32 && type != c64) {
         return constant(real(val), dims, type);
     }
     af_array res;
     AF_THROW(af_constant_complex(&res,
                                  real(val),
                                  imag(val),
                                  dims.ndims(),
                                  dims.get(), type));
     return array(res);
 }
开发者ID:PierreBizouard,项目名称:arrayfire,代码行数:13,代码来源:data.cpp

示例6: info

Array<T>::Array(dim4 dims, const T * const in_data, bool is_device, bool copy_device):
    info(getActiveDeviceId(), dims, 0, calcStrides(dims), (af_dtype)dtype_traits<T>::af_type),
    data((is_device & !copy_device) ? (T*)in_data : memAlloc<T>(dims.elements()).release(), memFree<T>), data_dims(dims),
    node(bufferNodePtr<T>()), ready(true), owner(true)
{
    static_assert(is_standard_layout<Array<T>>::value, "Array<T> must be a standard layout type");
    static_assert(offsetof(Array<T>, info) == 0, "Array<T>::info must be the first member variable of Array<T>");
    if (!is_device || copy_device) {
        // Ensure the memory being written to isnt used anywhere else.
        getQueue().sync();
        copy(in_data, in_data + dims.elements(), data.get());
    }
}
开发者ID:FilipeMaia,项目名称:arrayfire,代码行数:13,代码来源:Array.cpp

示例7: assign

static
void assign(Array<Tout> &out, const unsigned &ndims, const af_seq *index, const Array<Tin> &in_)
{
    dim4 const outDs = out.dims();
    dim4 const iDims = in_.dims();

    DIM_ASSERT(0, (outDs.ndims()>=iDims.ndims()));
    DIM_ASSERT(0, (outDs.ndims()>=(dim_t)ndims));

    out.eval();

    vector<af_seq> index_(index, index+ndims);

    dim4 oDims = toDims(index_, outDs);

    bool is_vector = true;
    for (int i = 0; is_vector && i < (int)oDims.ndims() - 1; i++) {
        is_vector &= oDims[i] == 1;
    }

    is_vector &= in_.isVector() || in_.isScalar();

    for (dim_t i = ndims; i < (int)in_.ndims(); i++) {
        oDims[i] = 1;
    }


    if (is_vector) {
        if (oDims.elements() != (dim_t)in_.elements() &&
            in_.elements() != 1) {
            AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE);
        }

        // If both out and in are vectors of equal elements, reshape in to out dims
        Array<Tin> in = in_.elements() == 1 ? tile(in_, oDims) : modDims(in_, oDims);
        Array<Tout> dst = createSubArray<Tout>(out, index_, false);

        copyArray<Tin , Tout>(dst, in);
    } else {
        for (int i = 0; i < 4; i++) {
            if (oDims[i] != iDims[i]) {
                AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE);
            }
        }
        Array<Tout> dst = createSubArray<Tout>(out, index_, false);

        copyArray<Tin , Tout>(dst, in_);
    }
}
开发者ID:shehzan10,项目名称:arrayfire,代码行数:49,代码来源:assign.cpp

示例8: info

Array<T>::Array(dim4 dims)
    : info(getActiveDeviceId(), dims, 0, calcStrides(dims),
           (af_dtype)dtype_traits<T>::af_type)
    , data(memAlloc<T>(dims.elements()).release(), memFree<T>)
    , data_dims(dims)
    , node(bufferNodePtr<T>())
    , ready(true)
    , owner(true) {}
开发者ID:umar456,项目名称:arrayfire,代码行数:8,代码来源:Array.cpp

示例9: calcStrides

dim4 calcStrides(const dim4 &parentDim)
{
    dim4 out(1, 1, 1, 1);
    dim_t *out_dims = out.get();
    const dim_t *parent_dims =  parentDim.get();

    for (dim_t i=1; i < 4; i++) {
        out_dims[i] = out_dims[i - 1] * parent_dims[i-1];
    }

    return out;
}
开发者ID:PierreBizouard,项目名称:arrayfire,代码行数:12,代码来源:ArrayInfo.cpp

示例10: lookup

Array<in_t> lookup(const Array<in_t> &input,
                   const Array<idx_t> &indices, const unsigned dim)
{
    const dim4 iDims = input.dims();

    dim4 oDims(1);
    for (int d=0; d<4; ++d)
        oDims[d] = (d==int(dim) ? indices.elements() : iDims[d]);

    Array<in_t> out = createEmptyArray<in_t>(oDims);

    dim_t nDims = iDims.ndims();

    switch(dim) {
        case 0: kernel::lookup<in_t, idx_t, 0>(out, input, indices, nDims); break;
        case 1: kernel::lookup<in_t, idx_t, 1>(out, input, indices, nDims); break;
        case 2: kernel::lookup<in_t, idx_t, 2>(out, input, indices, nDims); break;
        case 3: kernel::lookup<in_t, idx_t, 3>(out, input, indices, nDims); break;
    }

    return out;
}
开发者ID:AshwinRajendraprasad,项目名称:arrayfire,代码行数:22,代码来源:lookup.cpp

示例11: identifyBatchKind

AF_BATCH_KIND identifyBatchKind(const dim4 &sDims, const dim4 &fDims) {
    dim_t sn = sDims.ndims();
    dim_t fn = fDims.ndims();

    if (sn == baseDim && fn == baseDim)
        return AF_BATCH_NONE;
    else if (sn == baseDim && (fn > baseDim && fn <= 4))
        return AF_BATCH_RHS;
    else if ((sn > baseDim && sn <= 4) && fn == baseDim)
        return AF_BATCH_LHS;
    else if ((sn > baseDim && sn <= 4) && (fn > baseDim && fn <= 4)) {
        bool doesDimensionsMatch = true;
        bool isInterleaved       = true;
        for (dim_t i = baseDim; i < 4; i++) {
            doesDimensionsMatch &= (sDims[i] == fDims[i]);
            isInterleaved &=
                (sDims[i] == 1 || fDims[i] == 1 || sDims[i] == fDims[i]);
        }
        if (doesDimensionsMatch) return AF_BATCH_SAME;
        return (isInterleaved ? AF_BATCH_DIFF : AF_BATCH_UNSUPPORTED);
    } else
        return AF_BATCH_UNSUPPORTED;
}
开发者ID:9prady9,项目名称:arrayfire,代码行数:23,代码来源:fftconvolve.cpp

示例12: identifyBatchKind

ConvolveBatchKind identifyBatchKind(const dim4 &sDims, const dim4 &fDims)
{
    dim_t sn = sDims.ndims();
    dim_t fn = fDims.ndims();

    if (sn==baseDim && fn==baseDim)
        return ONE2ONE;
    else if (sn==baseDim && (fn>baseDim && fn<=4))
        return ONE2MANY;
    else if ((sn>baseDim && sn<=4) && fn==baseDim)
        return MANY2ONE;
    else if ((sn>baseDim && sn<=4) && (fn>baseDim && fn<=4)) {
        bool doesDimensionsMatch = true;
        for (dim_t i=baseDim; i<4; i++) {
            if (sDims[i]!=fDims[i]) {
                doesDimensionsMatch = false;
                break;
            }
        }
        return (doesDimensionsMatch ? MANY2MANY : CONVOLVE_UNSUPPORTED_BATCH_MODE);
    }
    else
        return CONVOLVE_UNSUPPORTED_BATCH_MODE;
}
开发者ID:PierreBizouard,项目名称:arrayfire,代码行数:24,代码来源:convolve.cpp

示例13: identity

 array identity(const dim4 &dims, const af::dtype type)
 {
     af_array res;
     AF_THROW(af_identity(&res, dims.ndims(), dims.get(), type));
     return array(res);
 }
开发者ID:PierreBizouard,项目名称:arrayfire,代码行数:6,代码来源:data.cpp

示例14: fast_pyramid

void fast_pyramid(std::vector<unsigned>& feat_pyr,
                  std::vector<float*>& d_x_pyr,
                  std::vector<float*>& d_y_pyr,
                  std::vector<unsigned>& lvl_best,
                  std::vector<float>& lvl_scl,
                  std::vector<CParam<T> >& img_pyr,
                  CParam<T> in,
                  const float fast_thr,
                  const unsigned max_feat,
                  const float scl_fctr,
                  const unsigned levels,
                  const unsigned patch_size)
{
    unsigned min_side = std::min(in.dims[0], in.dims[1]);
    unsigned max_levels = 0;
    float scl_sum = 0.f;

    for (unsigned i = 0; i < levels; i++) {
        min_side /= scl_fctr;

        // Minimum image side for a descriptor to be computed
        if (min_side < patch_size || max_levels == levels) break;

        max_levels++;
        scl_sum += 1.f / (float)std::pow(scl_fctr,(float)i);
    }

    // Compute number of features to keep for each level
    lvl_best.resize(max_levels);
    lvl_scl.resize(max_levels);
    unsigned feat_sum = 0;
    for (unsigned i = 0; i < max_levels-1; i++) {
        float scl = (float)std::pow(scl_fctr,(float)i);
        lvl_scl[i] = scl;

        lvl_best[i] = ceil((max_feat / scl_sum) / lvl_scl[i]);
        feat_sum += lvl_best[i];
    }
    lvl_scl[max_levels-1] = (float)std::pow(scl_fctr,(float)max_levels-1);
    lvl_best[max_levels-1] = max_feat - feat_sum;

    // Hold multi-scale image pyramids
    static const dim4 dims0;
    static const CParam<T> emptyCParam(NULL, dims0.get(), dims0.get());
    // Need to do this as CParam does not have a default constructor
    // And resize needs a default constructor or default value prior to C++11
    img_pyr.resize(max_levels, emptyCParam);

    // Create multi-scale image pyramid
    for (unsigned i = 0; i < max_levels; i++) {
        if (i == 0) {
            // First level is used in its original size
            img_pyr[i].ptr = in.ptr;
            for (int k = 0; k < 4; k++) {
                img_pyr[i].dims[k] = in.dims[k];
                img_pyr[i].strides[k] = in.strides[k];
            }
        }
        else {
            // Resize previous level image to current level dimensions
            Param<T> lvl_img;
            lvl_img.dims[0] = round(in.dims[0] / lvl_scl[i]);
            lvl_img.dims[1] = round(in.dims[1] / lvl_scl[i]);
            lvl_img.strides[0] = 1;
            lvl_img.strides[1] = lvl_img.dims[0] * lvl_img.strides[0];

            for (int k = 2; k < 4; k++) {
                lvl_img.dims[k] = 1;
                lvl_img.strides[k] = lvl_img.dims[k - 1] * lvl_img.strides[k - 1];
            }

            int lvl_elem = lvl_img.strides[3] * lvl_img.dims[3];
            lvl_img.ptr = memAlloc<T>(lvl_elem);

            resize<T, AF_INTERP_BILINEAR>(lvl_img, img_pyr[i-1]);

            img_pyr[i].ptr = lvl_img.ptr;
            for (int k = 0; k < 4; k++) {
                img_pyr[i].dims[k] = lvl_img.dims[k];
                img_pyr[i].strides[k] = lvl_img.strides[k];
            }
        }
    }

    feat_pyr.resize(max_levels);
    d_x_pyr.resize(max_levels);
    d_y_pyr.resize(max_levels);

    for (unsigned i = 0; i < max_levels; i++) {
        unsigned lvl_feat = 0;
        float* d_x_feat = NULL;
        float* d_y_feat = NULL;
        float* d_score_feat = NULL;

        // Round feature size to nearest odd integer
        float size = 2.f * floor(patch_size / 2.f) + 1.f;

        // Avoid keeping features that are too wide and might not fit the image,
        // sqrt(2.f) is the radius when angle is 45 degrees and represents
        // widest case possible
//.........这里部分代码省略.........
开发者ID:shehzan10,项目名称:arrayfire,代码行数:101,代码来源:fast_pyramid.hpp

示例15: randn

 array randn(const dim4 &dims, const dtype ty, randomEngine &r)
 {
     af_array out;
     AF_THROW(af_random_normal(&out, dims.ndims(), dims.get(), ty, r.get()));
     return array(out);
 }
开发者ID:munnybearz,项目名称:arrayfire,代码行数:6,代码来源:random.cpp


注:本文中的dim4类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。