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


C++ type::get_dtype方法代码示例

本文整理汇总了C++中ndt::type::get_dtype方法的典型用法代码示例。如果您正苦于以下问题:C++ type::get_dtype方法的具体用法?C++ type::get_dtype怎么用?C++ type::get_dtype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ndt::type的用法示例。


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

示例1: typed_data_assign

void dynd::typed_data_assign(const ndt::type& dst_tp, const char *dst_metadata, char *dst_data,
                const ndt::type& src_tp, const char *src_metadata, const char *src_data,
                assign_error_mode errmode, const eval::eval_context *ectx)
{
    DYND_ASSERT_ALIGNED(dst, 0, dst_tp.get_data_alignment(), "dst type: " << dst_tp << ", src type: " << src_tp);
    DYND_ASSERT_ALIGNED(src, 0, src_dt.get_data_alignment(), "src type: " << src_tp << ", dst type: " << dst_tp);

    if (errmode == assign_error_default) {
        if (ectx != NULL) {
            if (dst_tp.get_dtype().get_type_id() == cuda_device_type_id && src_tp.get_dtype().get_type_id() == cuda_device_type_id) {
                errmode = ectx->default_cuda_device_errmode;
            } else {
                errmode = ectx->default_errmode;
            }
        } else if (dst_tp == src_tp) {
            errmode = assign_error_none;
        } else {
            stringstream ss;
            ss << "assignment from " << src_tp << " to " << dst_tp << " with default error mode requires an eval_context";
            throw dynd::type_error(ss.str());
        }
    }

    assignment_ckernel_builder k;
    make_assignment_kernel(&k, 0, dst_tp, dst_metadata,
                    src_tp, src_metadata,
                    kernel_request_single,
                    errmode, ectx);
    k(dst_data, src_data);
}
开发者ID:talumbau,项目名称:libdynd,代码行数:30,代码来源:typed_data_assign.cpp

示例2: typed_rand

nd::array nd::typed_rand(intptr_t ndim, const intptr_t *shape, const ndt::type &tp) {
    type_id_t dtp_id = tp.get_dtype().get_type_id();

    nd::array res = nd::typed_empty(ndim, shape, tp);

    try {
        array_iter<1, 0> iter(res);
        do {
            switch (dtp_id) {
                case float32_type_id:
                    *reinterpret_cast<float *>(iter.data())
                        = rand() / ((float) RAND_MAX);
                    break;
                case float64_type_id:
                    *reinterpret_cast<double *>(iter.data())
                        = rand() / ((double) RAND_MAX);
                    break;
                case complex_float32_type_id:
                    *reinterpret_cast<dynd_complex<float> *>(iter.data())
                        = dynd_complex<float>(rand() / ((float) RAND_MAX), rand() / ((float) RAND_MAX));
                    break;
                case complex_float64_type_id:
                    *reinterpret_cast<dynd_complex<double> *>(iter.data())
                        = dynd_complex<double>(rand() / ((double) RAND_MAX), rand() / ((double) RAND_MAX));
                    break;
                default:
                    throw std::runtime_error("rand: unsupported dtype");
            }
        } while (iter.next());
    } catch (...) {
        ndt::type strided_tp = tp.get_dtype();
        for (intptr_t i = 0; i < ndim; ++i) {
            strided_tp = ndt::make_strided_dim(strided_tp);
        }

        res.vals() = nd::typed_rand(ndim, shape, strided_tp);
    }

    return res.ucast(tp.get_dtype()).eval();
}
开发者ID:nevermindewe,项目名称:libdynd,代码行数:40,代码来源:random.cpp

示例3: type_error

intptr_t kernels::fixed_dim_assign_na_ck::instantiate(
    const arrfunc_type_data *DYND_UNUSED(self),
    const arrfunc_type *DYND_UNUSED(af_tp), void *ckb,
    intptr_t ckb_offset, const ndt::type &dst_tp,
    const char *DYND_UNUSED(dst_arrmeta), const ndt::type *DYND_UNUSED(src_tp),
    const char *const *DYND_UNUSED(src_arrmeta), kernel_request_t kernreq,
    const eval::eval_context *DYND_UNUSED(ectx),
    const nd::array &DYND_UNUSED(kwds))
{
  ckernel_prefix *ckp = reinterpret_cast<ckernel_builder<kernel_request_host> *>(ckb)->alloc_ck_leaf<ckernel_prefix>(ckb_offset);
  switch (dst_tp.get_dtype().get_type_id()) {
  case bool_type_id:
    ckp->set_expr_function<assign_na<dynd_bool> >(kernreq);
    break;
  case int8_type_id:
    ckp->set_expr_function<assign_na<int8_t> >(kernreq);
    break;
  case int16_type_id:
    ckp->set_expr_function<assign_na<int16_t> >(kernreq);
    break;
  case int32_type_id:
    ckp->set_expr_function<assign_na<int32_t> >(kernreq);
    break;
  case int64_type_id:
    ckp->set_expr_function<assign_na<int64_t> >(kernreq);
    break;
  case int128_type_id:
    ckp->set_expr_function<assign_na<dynd_int128> >(kernreq);
    break;
  case float32_type_id:
    ckp->set_expr_function<assign_na<float> >(kernreq);
    break;
  case float64_type_id:
    ckp->set_expr_function<assign_na<double> >(kernreq);
    break;
  case complex_float32_type_id:
    ckp->set_expr_function<assign_na<dynd_complex<float> > >(kernreq);
    break;
  case complex_float64_type_id:
    ckp->set_expr_function<assign_na<dynd_complex<double> > >(kernreq);
    break;
  default:
    throw type_error("fixed_dim_assign_na: expected built-in type");
    break;
  }
  return ckb_offset;
}
开发者ID:aterrel,项目名称:libdynd,代码行数:47,代码来源:option_kernels.cpp

示例4: instantiate

 static intptr_t instantiate(char *DYND_UNUSED(static_data), char *DYND_UNUSED(data), void *ckb,
                             intptr_t ckb_offset, const ndt::type &dst_tp, const char *DYND_UNUSED(dst_arrmeta),
                             intptr_t DYND_UNUSED(nsrc), const ndt::type *DYND_UNUSED(src_tp),
                             const char *const *DYND_UNUSED(src_arrmeta), kernel_request_t kernreq,
                             const eval::eval_context *DYND_UNUSED(ectx), intptr_t DYND_UNUSED(nkwd),
                             const nd::array *DYND_UNUSED(kwds),
                             const std::map<std::string, ndt::type> &DYND_UNUSED(tp_vars))
 {
   switch (dst_tp.get_dtype().get_type_id()) {
   case bool_type_id:
     assign_na_kernel<bool_type_id, bool_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case int8_type_id:
     assign_na_kernel<int8_type_id, sint_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case int16_type_id:
     assign_na_kernel<int16_type_id, sint_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case int32_type_id:
     assign_na_kernel<int32_type_id, sint_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case int64_type_id:
     assign_na_kernel<int64_type_id, sint_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case int128_type_id:
     assign_na_kernel<int128_type_id, sint_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case float32_type_id:
     assign_na_kernel<float32_type_id, real_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case float64_type_id:
     assign_na_kernel<float64_type_id, real_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case complex_float32_type_id:
     assign_na_kernel<complex_float32_type_id, complex_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   case complex_float64_type_id:
     assign_na_kernel<complex_float64_type_id, complex_kind>::make(ckb, kernreq, ckb_offset);
     return ckb_offset;
   default:
     throw type_error("fixed_dim_assign_na: expected built-in type");
   }
 }
开发者ID:Vasyka,项目名称:hat,代码行数:43,代码来源:assign_na_kernel.hpp

示例5: instantiate

 static void instantiate(char *DYND_UNUSED(static_data), char *DYND_UNUSED(data), kernel_builder *ckb,
                         const ndt::type &dst_tp, const char *DYND_UNUSED(dst_arrmeta), intptr_t DYND_UNUSED(nsrc),
                         const ndt::type *DYND_UNUSED(src_tp), const char *const *DYND_UNUSED(src_arrmeta),
                         kernel_request_t kernreq, intptr_t DYND_UNUSED(nkwd), const nd::array *DYND_UNUSED(kwds),
                         const std::map<std::string, ndt::type> &DYND_UNUSED(tp_vars))
 {
   switch (dst_tp.get_dtype().get_id()) {
   case bool_id:
     ckb->emplace_back<assign_na_kernel<bool_id, bool_kind_id>>(kernreq);
     break;
   case int8_id:
     ckb->emplace_back<assign_na_kernel<int8_id, int_kind_id>>(kernreq);
     break;
   case int16_id:
     ckb->emplace_back<assign_na_kernel<int16_id, int_kind_id>>(kernreq);
     break;
   case int32_id:
     ckb->emplace_back<assign_na_kernel<int32_id, int_kind_id>>(kernreq);
     break;
   case int64_id:
     ckb->emplace_back<assign_na_kernel<int64_id, int_kind_id>>(kernreq);
     break;
   case int128_id:
     ckb->emplace_back<assign_na_kernel<int128_id, int_kind_id>>(kernreq);
     break;
   case float32_id:
     ckb->emplace_back<assign_na_kernel<float32_id, float_kind_id>>(kernreq);
     break;
   case float64_id:
     ckb->emplace_back<assign_na_kernel<float64_id, float_kind_id>>(kernreq);
     break;
   case complex_float32_id:
     ckb->emplace_back<assign_na_kernel<complex_float32_id, complex_kind_id>>(kernreq);
     break;
   case complex_float64_id:
     ckb->emplace_back<assign_na_kernel<complex_float64_id, complex_kind_id>>(kernreq);
     break;
   default:
     throw type_error("fixed_dim_assign_na: expected built-in type");
   }
 }
开发者ID:nyue,项目名称:libdynd,代码行数:41,代码来源:assign_na_kernel.hpp


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