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


C++ nd::array类代码示例

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


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

示例1: function_type_construct

static nd::array function_type_construct(const ndt::type& DYND_UNUSED(dt),
        const nd::array& year, const nd::array& month, const nd::array& day)
{
    // TODO proper buffering
    nd::array year_as_int = year.ucast(ndt::make_type<int32_t>()).eval();
    nd::array month_as_int = month.ucast(ndt::make_type<int32_t>()).eval();
    nd::array day_as_int = day.ucast(ndt::make_type<int32_t>()).eval();
    nd::array result;

    array_iter<1,3> iter(ndt::make_date(), result, year_as_int, month_as_int, day_as_int);
    if (!iter.empty()) {
        datetime::date_ymd ymd;
        do {
            ymd.year = *reinterpret_cast<const int32_t *>(iter.data<1>());
            ymd.month = *reinterpret_cast<const int32_t *>(iter.data<2>());
            ymd.day = *reinterpret_cast<const int32_t *>(iter.data<3>());
            if (!datetime::is_valid_ymd(ymd)) {
                stringstream ss;
                ss << "invalid year/month/day " << ymd.year << "/" << ymd.month << "/" << ymd.day;
                throw runtime_error(ss.str());
            }
            *reinterpret_cast<int32_t *>(iter.data<0>()) = datetime::ymd_to_days(ymd);
        } while (iter.next());
    }

    return result;
}
开发者ID:pombredanne,项目名称:libdynd,代码行数:27,代码来源:date_type.cpp

示例2: get_memory_block_pod_allocator_api

nd::array dynd::format_json(const nd::array& n)
{
    // Create a UTF-8 string
    nd::array result = nd::empty(ndt::make_string());

    // Initialize the output with some memory
    output_data out;
    out.blockref = reinterpret_cast<const string_type_metadata *>(result.get_ndo_meta())->blockref;
    out.api = get_memory_block_pod_allocator_api(out.blockref);
    out.api->allocate(out.blockref, 1024, 1, &out.out_begin, &out.out_capacity_end);
    out.out_end = out.out_begin;

    if (!n.get_type().is_expression()) {
        ::format_json(out, n.get_type(), n.get_ndo_meta(), n.get_readonly_originptr());
    } else {
        nd::array tmp = n.eval();
        ::format_json(out, tmp.get_type(), tmp.get_ndo_meta(), tmp.get_readonly_originptr());
    }

    // Shrink the memory to fit, and set the pointers in the output
    string_type_data *d = reinterpret_cast<string_type_data *>(result.get_readwrite_originptr());
    d->begin = out.out_begin;
    d->end = out.out_capacity_end;
    out.api->resize(out.blockref, out.out_end - out.out_begin, &d->begin, &d->end);

    // Finalize processing and mark the result as immutable
    result.get_type().extended()->metadata_finalize_buffers(result.get_ndo_meta());
    result.flag_as_immutable();

    return result;
}
开发者ID:garaud,项目名称:libdynd,代码行数:31,代码来源:json_formatter.cpp

示例3: promote_nd_arr_dim

/**
 * This function promotes the requested `axis` from
 * a strided dim to a var dim. It modifies `shape`, `coord`,
 * `elem`, and `arr` to point to a new array, and
 * copies the data over.
 */
static void promote_nd_arr_dim(std::vector<intptr_t> &shape,
                               std::vector<afpd_coordentry> &coord,
                               afpd_dtype &elem, nd::array &arr, intptr_t axis,
                               bool copy_final_coord)
{
  vector<afpd_coordentry> newcoord;
  afpd_dtype newelem;
  newelem.dtp = elem.dtp;
  // Convert the axis into a var dim
  shape[axis] = -1;
  // Create the new array
  nd::array newarr = allocate_nd_arr(shape, newcoord, newelem, axis);
  // Copy the data up to, but not including, the current `coord`
  // from the old `arr` to the new one. The recursion stops
  // at `axis`, where all subsequent dimensions are handled by the
  // created kernel.
  ckernel_builder<kernel_request_host> k;
  if (elem.dtp.get_type_id() != uninitialized_type_id) {
    make_assignment_kernel(&k, 0, newcoord[axis].tp, newcoord[axis].arrmeta_ptr,
                           coord[axis].tp, coord[axis].arrmeta_ptr,
                           kernel_request_strided, &eval::default_eval_context);
  }
  copy_to_promoted_nd_arr(shape, newarr.get_readwrite_originptr(), newcoord,
                          newelem, arr.get_readonly_originptr(), coord, elem, k,
                          0, axis, copy_final_coord, true);
  arr.swap(newarr);
  coord.swap(newcoord);
  elem.swap(newelem);
}
开发者ID:cpcloud,项目名称:dynd-python,代码行数:35,代码来源:array_from_py_dynamic.cpp

示例4: parse_json

void dynd::parse_json(nd::array &out, const char *json_begin,
                      const char *json_end, const eval::eval_context *ectx)
{
    try {
        const char *begin = json_begin, *end = json_end;
        ndt::type tp = out.get_type();
        ::parse_json(tp, out.get_ndo_meta(), out.get_readwrite_originptr(), begin, end, ectx);
        begin = skip_whitespace(begin, end);
        if (begin != end) {
            throw json_parse_error(begin, "unexpected trailing JSON text", tp);
        }
    } catch (const json_parse_error& e) {
        stringstream ss;
        string line_prev, line_cur;
        int line, column;
        get_error_line_column(json_begin, json_end, e.get_position(),
                        line_prev, line_cur, line, column);
        ss << "Error parsing JSON at line " << line << ", column " << column << "\n";
        if (e.get_type().get_type_id() != uninitialized_type_id) {
            ss << "DType: " << e.get_type() << "\n";
        }
        ss << "Message: " << e.get_message() << "\n";
        print_json_parse_error_marker(ss, line_prev, line_cur, line, column);
        throw runtime_error(ss.str());
    }
}
开发者ID:talumbau,项目名称:libdynd,代码行数:26,代码来源:json_parser.cpp

示例5: format_json

nd::array dynd::format_json(const nd::array &n, bool struct_as_list)
{
  // Create a UTF-8 string
  nd::array result = nd::empty(ndt::string_type::make());

  // Initialize the output with some memory
  output_data out;
  out.out_string.resize(1024);
  out.out_begin = out.out_string.begin();
  out.out_capacity_end = out.out_string.end();
  out.out_end = out.out_begin;
  out.struct_as_list = struct_as_list;

  if (!n.get_type().is_expression()) {
    ::format_json(out, n.get_type(), n.get_arrmeta(), n.get_readonly_originptr());
  } else {
    nd::array tmp = n.eval();
    ::format_json(out, tmp.get_type(), tmp.get_arrmeta(), tmp.get_readonly_originptr());
  }

  // Shrink the memory to fit, and set the pointers in the output
  string *d = reinterpret_cast<string *>(result.get_readwrite_originptr());
  d->assign(out.out_string.data(), out.out_end - out.out_begin);

  // Finalize processing and mark the result as immutable
  result.get_type().extended()->arrmeta_finalize_buffers(result.get_arrmeta());
  result.flag_as_immutable();

  return result;
}
开发者ID:melodylail,项目名称:libdynd,代码行数:30,代码来源:json_formatter.cpp

示例6: instantiate

    static void instantiate(const callable_type_data *DYND_UNUSED(self), const callable_type *DYND_UNUSED(self_tp),
                            kernel_builder *ckb, intptr_t ckb_offset, const ndt::type &DYND_UNUSED(dst_tp),
                            const char *dst_arrmeta, intptr_t DYND_UNUSED(nsrc), const ndt::type *src_tp,
                            const char *const *src_arrmeta, kernel_request_t kernreq,
                            const eval::eval_context *DYND_UNUSED(ectx), const nd::array &kwds,
                            const std::map<std::string, ndt::type> &DYND_UNUSED(tp_vars))
    {
      const size_stride_t *dst_size_stride = reinterpret_cast<const size_stride_t *>(dst_arrmeta);
      const size_stride_t *src_size_stride = reinterpret_cast<const size_stride_t *>(src_arrmeta[0]);

      array axes = kwds.p("axes");
      array shape = kwds.p("shape");

      int ndim = static_cast<int>(src_tp[0].get_ndim());

      int rank = static_cast<int>(axes.is_missing() ? ndim : (ndim - 1));
      int istride = static_cast<int>(src_size_stride[ndim - 1].stride / sizeof(src_type));
      int idist = static_cast<int>(src_size_stride[0].stride / sizeof(src_type));
      int ostride = static_cast<int>(dst_size_stride[ndim - 1].stride / sizeof(dst_type));
      int odist = static_cast<int>(dst_size_stride[0].stride / sizeof(dst_type));

      std::vector<int> n(rank), inembed(rank), onembed(rank);
      for (int i = 0, j = axes.is_missing() ? 0 : 1; j < ndim; ++i, ++j) {
        n[i] = static_cast<int>(src_size_stride[j].dim_size);
        inembed[i] = static_cast<int>(src_size_stride[j].dim_size);
        onembed[i] = static_cast<int>(dst_size_stride[j].dim_size);
      }

      int batch = static_cast<int>(axes.is_missing() ? 1 : src_size_stride[0].dim_size);

      self_type *self = self_type::create(ckb, kernreq, ckb_offset);
      cufftPlanMany(&self->plan, rank, n.data(), inembed.data(), istride, idist, onembed.data(), ostride, odist,
                    CUFFT_Z2Z, batch);
    }
开发者ID:mindis,项目名称:libdynd,代码行数:34,代码来源:old_fft.hpp

示例7: set

 static void set(const ndt::type& paramtype, char *metadata, char *data, const nd::array& value) {
     if (paramtype.get_type_id() == void_pointer_type_id) {
         // TODO: switch to a better mechanism for passing nd::array references
         *reinterpret_cast<const array_preamble **>(data) = value.get_ndo();
     } else {
         typed_data_assign(paramtype, metadata, data, value.get_type(), value.get_ndo_meta(), value.get_ndo()->m_data_pointer);
     }
 }
开发者ID:garaud,项目名称:libdynd,代码行数:8,代码来源:call_callable.hpp

示例8: function_ndo_strftime

static nd::array function_ndo_strftime(const nd::array& n, const std::string& format) {
    // TODO: Allow 'format' itself to be an array, with broadcasting, etc.
    if (format.empty()) {
        throw runtime_error("format string for strftime should not be empty");
    }
    return n.replace_dtype(ndt::make_unary_expr(ndt::make_string(), n.get_dtype(),
                    make_strftime_kernelgen(format)));
}
开发者ID:pombredanne,项目名称:libdynd,代码行数:8,代码来源:datetime_type.cpp

示例9: typed_data_assign

void dynd::typed_data_assign(const ndt::type &dst_tp, const char *dst_arrmeta,
                             char *dst_data, const nd::array &src_arr,
                             const eval::eval_context *ectx)
{
  typed_data_assign(dst_tp, dst_arrmeta, dst_data, src_arr.get_type(),
                    src_arr.get_arrmeta(), src_arr.get_readonly_originptr(),
                    ectx);
}
开发者ID:Laeeth,项目名称:libdynd,代码行数:8,代码来源:typed_data_assign.cpp

示例10: linspace_specialization

static void linspace_specialization(float start, float stop, intptr_t count, nd::array& result)
{
    intptr_t stride = result.get_strides()[0];
    char *dst = result.get_readwrite_originptr();
    for (intptr_t i = 0; i < count; ++i, dst += stride) {
        double val = ((count - i - 1) * double(start) + i * double(stop)) / double(count - 1);
        *reinterpret_cast<float *>(dst) = static_cast<float>(val);
    }
}
开发者ID:garaud,项目名称:libdynd,代码行数:9,代码来源:array_range.cpp

示例11: function_ndo_replace

static nd::array function_ndo_replace(const nd::array& n, int32_t year, int32_t month, int32_t day) {
    // TODO: Allow 'year', 'month', and 'day' to be arrays, with broadcasting, etc.
    if (year == numeric_limits<int32_t>::max() && month == numeric_limits<int32_t>::max() &&
            day == numeric_limits<int32_t>::max()) {
        throw std::runtime_error("no parameters provided to date.replace, should provide at least one");
    }
    return n.replace_dtype(ndt::make_unary_expr(ndt::make_date(), n.get_dtype(),
                           make_replace_kernelgen(year, month, day)));
}
开发者ID:pombredanne,项目名称:libdynd,代码行数:9,代码来源:date_type.cpp

示例12: linspace

nd::array dynd::nd::linspace(const nd::array& start, const nd::array& stop, intptr_t count)
{
    ndt::type dt = promote_types_arithmetic(start.get_dtype(), stop.get_dtype());
    // Make sure it's at least floating point
    if (dt.get_kind() == bool_kind || dt.get_kind() == int_kind || dt.get_kind() == uint_kind) {
        dt = ndt::make_type<double>();
    }
    return linspace(start, stop, count, dt);
}
开发者ID:garaud,项目名称:libdynd,代码行数:9,代码来源:array_range.cpp

示例13: substitute_type_array

/**
 * Substitutes the field types for contiguous array of types
 */
static std::vector<ndt::type> substitute_type_array(const nd::array &type_array,
                                                    const std::map<std::string, ndt::type> &typevars, bool concrete) {
  intptr_t field_count = type_array.get_dim_size();
  const ndt::type *field_types = reinterpret_cast<const ndt::type *>(type_array.cdata());
  std::vector<ndt::type> tmp_field_types(field_count);

  for (intptr_t i = 0; i < field_count; ++i) {
    tmp_field_types[i] = ndt::substitute(field_types[i], typevars, concrete);
  }
  return tmp_field_types;
}
开发者ID:mindis,项目名称:libdynd,代码行数:14,代码来源:substitute_typevars.cpp

示例14: get_value_from_category

uint32_t categorical_type::get_value_from_category(const nd::array& category) const
{
    if (category.get_type() == m_category_tp) {
        // If the type is right, get the category value directly
        return get_value_from_category(category.get_arrmeta(), category.get_readonly_originptr());
    } else {
        // Otherwise convert to the correct type, then get the category value
        nd::array c = nd::empty(m_category_tp);
        c.val_assign(category);
        return get_value_from_category(c.get_arrmeta(), c.get_readonly_originptr());
    }
}
开发者ID:nevermindewe,项目名称:libdynd,代码行数:12,代码来源:categorical_type.cpp

示例15: substitute_type_array

/**
 * Substitutes the field types for contiguous array of types
 */
static nd::array substitute_type_array(const nd::array &type_array, const std::map<std::string, ndt::type> &typevars,
                                       bool concrete)
{
  intptr_t field_count = type_array.get_dim_size();
  const ndt::type *field_types = reinterpret_cast<const ndt::type *>(type_array.cdata());
  nd::array tmp_field_types(nd::empty(field_count, ndt::make_type()));
  ndt::type *ftraw = reinterpret_cast<ndt::type *>(tmp_field_types.data());
  for (intptr_t i = 0; i < field_count; ++i) {
    ftraw[i] = ndt::substitute(field_types[i], typevars, concrete);
  }
  return tmp_field_types;
}
开发者ID:jonathandedwards,项目名称:libdynd,代码行数:15,代码来源:substitute_typevars.cpp


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