本文整理汇总了C++中ndt::type::get_ndim方法的典型用法代码示例。如果您正苦于以下问题:C++ type::get_ndim方法的具体用法?C++ type::get_ndim怎么用?C++ type::get_ndim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndt::type
的用法示例。
在下文中一共展示了type::get_ndim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
groupby_type::groupby_type(const ndt::type& data_values_tp,
const ndt::type& by_values_tp)
: base_expr_type(groupby_type_id, expr_kind,
sizeof(groupby_type_data), sizeof(void *), type_flag_none,
0, 1 + data_values_tp.get_ndim())
{
m_groups_type = by_values_tp.at_single(0).value_type();
if (m_groups_type.get_type_id() != categorical_type_id) {
stringstream ss;
ss << "to construct a groupby type, the by type, " << by_values_tp.at_single(0);
ss << ", must have a categorical value type";
throw runtime_error(ss.str());
}
if (data_values_tp.get_ndim() < 1) {
throw runtime_error("to construct a groupby type, its values type must have at least one array dimension");
}
if (by_values_tp.get_ndim() < 1) {
throw runtime_error("to construct a groupby type, its values type must have at least one array dimension");
}
m_operand_type = ndt::make_cstruct(ndt::make_pointer(data_values_tp), "data",
ndt::make_pointer(by_values_tp), "by");
m_members.arrmeta_size = m_operand_type.get_arrmeta_size();
const categorical_type *cd = m_groups_type.extended<categorical_type>();
m_value_type = ndt::make_cfixed_dim(cd->get_category_count(),
ndt::make_var_dim(data_values_tp.at_single(0)));
m_members.flags = inherited_flags(m_value_type.get_flags(), m_operand_type.get_flags());
}
示例2: make_assignment_kernel
size_t cfixed_dim_type::make_assignment_kernel(
ckernel_builder *ckb, intptr_t ckb_offset, const ndt::type &dst_tp,
const char *dst_arrmeta, const ndt::type &src_tp, const char *src_arrmeta,
kernel_request_t kernreq, const eval::eval_context *ectx) const
{
if (this == dst_tp.extended()) {
intptr_t src_size, src_stride;
ndt::type src_el_tp;
const char *src_el_arrmeta;
if (src_tp.get_ndim() < dst_tp.get_ndim()) {
kernels::strided_assign_ck *self =
kernels::strided_assign_ck::create(ckb, kernreq, ckb_offset);
self->m_size = get_fixed_dim_size();
self->m_dst_stride = get_fixed_stride();
// If the src has fewer dimensions, broadcast it across this one
self->m_src_stride = 0;
return ::make_assignment_kernel(
ckb, ckb_offset, m_element_tp,
dst_arrmeta + sizeof(cfixed_dim_type_arrmeta), src_tp, src_arrmeta,
kernel_request_strided, ectx);
} else if (src_tp.get_as_strided(src_arrmeta, &src_size, &src_stride,
&src_el_tp, &src_el_arrmeta)) {
kernels::strided_assign_ck *self =
kernels::strided_assign_ck::create(ckb, kernreq, ckb_offset);
self->m_size = get_fixed_dim_size();
self->m_dst_stride = get_fixed_stride();
self->m_src_stride = src_stride;
// Check for a broadcasting error
if (src_size != 1 && get_fixed_dim_size() != src_size) {
throw broadcast_error(dst_tp, dst_arrmeta, src_tp, src_arrmeta);
}
return ::make_assignment_kernel(
ckb, ckb_offset, m_element_tp,
dst_arrmeta + sizeof(cfixed_dim_type_arrmeta), src_el_tp,
src_el_arrmeta, kernel_request_strided, ectx);
} else if (!src_tp.is_builtin()) {
// Give the src type a chance to make a kernel
return src_tp.extended()->make_assignment_kernel(
ckb, ckb_offset, dst_tp, dst_arrmeta, src_tp, src_arrmeta,
kernreq, ectx);
} else {
stringstream ss;
ss << "Cannot assign from " << src_tp << " to " << dst_tp;
throw dynd::type_error(ss.str());
}
} else if (dst_tp.get_kind() == string_kind) {
return make_any_to_string_assignment_kernel(ckb, ckb_offset, dst_tp,
dst_arrmeta, src_tp,
src_arrmeta, kernreq, ectx);
} else if (dst_tp.get_ndim() < src_tp.get_ndim()) {
throw broadcast_error(dst_tp, dst_arrmeta, src_tp, src_arrmeta);
} else {
stringstream ss;
ss << "Cannot assign from " << src_tp << " to " << dst_tp;
throw dynd::type_error(ss.str());
}
}
示例3: view
nd::array nd::view(const nd::array &arr, const ndt::type &tp)
{
if (arr.get_type() == tp) {
// If the types match exactly, simply return 'arr'
return arr;
} else if (tp.get_type_id() == bytes_type_id) {
// If it's a request to view the data as raw bytes
nd::array result = view_as_bytes(arr, tp);
if (!result.is_null()) {
return result;
}
} else if (arr.get_type().get_type_id() == bytes_type_id) {
// If it's a request to view raw bytes as something else
nd::array result = view_from_bytes(arr, tp);
if (!result.is_null()) {
return result;
}
} else if (arr.get_ndim() == tp.get_ndim()) {
// If the type is symbolic, e.g. has a "Fixed" symbolic dimension,
// first substitute in the shape from the array
if (tp.is_symbolic()) {
dimvector shape(arr.get_ndim());
arr.get_shape(shape.get());
return view_concrete(arr, substitute_shape(tp, arr.get_ndim(), shape.get()));
} else {
return view_concrete(arr, tp);
}
}
stringstream ss;
ss << "Unable to view nd::array of type " << arr.get_type();
ss << " as type " << tp;
throw type_error(ss.str());
}
示例4: view
nd::array nd::view(const nd::array& arr, const ndt::type& tp)
{
// If the types match exactly, simply return 'arr'
if (arr.get_type() == tp) {
return arr;
} else if (arr.get_ndim() == tp.get_ndim()) {
// Allocate a result array to attempt the view in it
array result(make_array_memory_block(tp.get_metadata_size()));
// Copy the fields
result.get_ndo()->m_data_pointer = arr.get_ndo()->m_data_pointer;
if (arr.get_ndo()->m_data_reference == NULL) {
// Embedded data, need reference to the array
result.get_ndo()->m_data_reference = arr.get_memblock().release();
} else {
// Use the same data reference, avoid producing a chain
result.get_ndo()->m_data_reference = arr.get_data_memblock().release();
}
result.get_ndo()->m_type = ndt::type(tp).release();
result.get_ndo()->m_flags = arr.get_ndo()->m_flags;
// Now try to copy the metadata as a view
if (try_view(arr.get_type(), arr.get_ndo_meta(), tp,
result.get_ndo_meta(), arr.get_memblock().get())) {
// If it succeeded, return it
return result;
}
// Otherwise fall through, let it get destructed, and raise an error
}
stringstream ss;
ss << "Unable to view nd::array of type " << arr.get_type();
ss << "as type " << tp;
throw type_error(ss.str());
}
示例5: runtime_error
expr_type::expr_type(const ndt::type& value_type, const ndt::type& operand_type,
const expr_kernel_generator *kgen)
: base_expression_type(expr_type_id, expression_kind,
operand_type.get_data_size(), operand_type.get_data_alignment(),
inherited_flags(value_type.get_flags(), operand_type.get_flags()),
operand_type.get_metadata_size(), value_type.get_ndim()),
m_value_type(value_type), m_operand_type(operand_type),
m_kgen(kgen)
{
if (operand_type.get_type_id() != cstruct_type_id) {
stringstream ss;
ss << "expr_type can only be constructed with a cstruct as its operand, given ";
ss << operand_type;
throw runtime_error(ss.str());
}
const cstruct_type *fsd = static_cast<const cstruct_type *>(operand_type.extended());
size_t field_count = fsd->get_field_count();
if (field_count == 1) {
throw runtime_error("expr_type is for 2 or more operands, use unary_expr_type for 1 operand");
}
const ndt::type *field_types = fsd->get_field_types();
for (size_t i = 0; i != field_count; ++i) {
if (field_types[i].get_type_id() != pointer_type_id) {
stringstream ss;
ss << "each field of the expr_type's operand must be a pointer, field " << i;
ss << " is " << field_types[i];
throw runtime_error(ss.str());
}
}
}
示例6:
ndt::adapt_type::adapt_type(const ndt::type &value_tp, const ndt::type &storage_tp, const nd::callable &forward,
const nd::callable &inverse)
: base_expr_type(adapt_id, storage_tp.get_data_size(), storage_tp.get_data_alignment(), type_flag_none,
storage_tp.get_arrmeta_size(), storage_tp.get_ndim()),
m_value_tp(value_tp), m_storage_tp(storage_tp), m_forward(forward), m_inverse(inverse)
{
}
示例7: init
inline void init(const ndt::type& tp0, const char *metadata0, char *data0)
{
m_array_tp = tp0;
m_iter_ndim = m_array_tp.get_ndim();
m_itersize = 1;
if (m_iter_ndim != 0) {
m_iterindex.init(m_iter_ndim);
memset(m_iterindex.get(), 0, sizeof(intptr_t) * m_iter_ndim);
m_itershape.init(m_iter_ndim);
m_array_tp.extended()->get_shape(m_iter_ndim, 0, m_itershape.get(), metadata0);
size_t iterdata_size = m_array_tp.extended()->get_iterdata_size(m_iter_ndim);
m_iterdata = reinterpret_cast<iterdata_common *>(malloc(iterdata_size));
if (!m_iterdata) {
throw std::bad_alloc();
}
m_metadata = metadata0;
m_array_tp.iterdata_construct(m_iterdata,
&m_metadata, m_iter_ndim, m_itershape.get(), m_uniform_tp);
m_data = m_iterdata->reset(m_iterdata, data0, m_iter_ndim);
for (size_t i = 0, i_end = m_iter_ndim; i != i_end; ++i) {
m_itersize *= m_itershape[i];
}
} else {
m_iterdata = NULL;
m_uniform_tp = m_array_tp;
m_data = data0;
m_metadata = metadata0;
}
}
示例8: base_uniform_dim_type
inline base_uniform_dim_type(type_id_t type_id, const ndt::type& element_tp, size_t data_size,
size_t alignment, size_t element_metadata_offset,
flags_type flags)
: base_type(type_id, uniform_dim_kind, data_size,
alignment, flags, element_metadata_offset + element_tp.get_metadata_size(),
1 + element_tp.get_ndim()),
m_element_tp(element_tp), m_element_metadata_offset(element_metadata_offset)
{
}
示例9:
unary_expr_type::unary_expr_type(const ndt::type& value_type, const ndt::type& operand_type,
const expr_kernel_generator *kgen)
: base_expression_type(unary_expr_type_id, expression_kind,
operand_type.get_data_size(), operand_type.get_data_alignment(),
inherited_flags(value_type.get_flags(), operand_type.get_flags()),
operand_type.get_metadata_size(), value_type.get_ndim()),
m_value_type(value_type), m_operand_type(operand_type),
m_kgen(kgen)
{
}
示例10: make_elwise_strided_or_var_to_var_dimension_expr_kernel_for_N
static size_t make_elwise_strided_or_var_to_var_dimension_expr_kernel_for_N(
void *ckb, intptr_t ckb_offset, const ndt::type &dst_tp, const char *dst_arrmeta, size_t DYND_UNUSED(src_count),
const ndt::type *src_tp, const char *const *src_arrmeta, kernel_request_t kernreq, const eval::eval_context *ectx,
const expr_kernel_generator *elwise_handler)
{
intptr_t undim = dst_tp.get_ndim();
const char *dst_child_arrmeta;
const char *src_child_arrmeta[N];
ndt::type dst_child_dt;
ndt::type src_child_dt[N];
strided_or_var_to_var_expr_kernel_extra<N> *e =
strided_or_var_to_var_expr_kernel_extra<N>::make(ckb, kernreq, ckb_offset);
// The dst var parameters
const ndt::var_dim_type *dst_vdd = dst_tp.extended<ndt::var_dim_type>();
const var_dim_type_arrmeta *dst_md = reinterpret_cast<const var_dim_type_arrmeta *>(dst_arrmeta);
e->dst_memblock = dst_md->blockref.get();
e->dst_stride = dst_md->stride;
e->dst_offset = dst_md->offset;
e->dst_target_alignment = dst_vdd->get_target_alignment();
dst_child_arrmeta = dst_arrmeta + sizeof(var_dim_type_arrmeta);
dst_child_dt = dst_vdd->get_element_type();
for (int i = 0; i < N; ++i) {
intptr_t src_size;
// The src[i] strided parameters
if (src_tp[i].get_ndim() < undim) {
// This src value is getting broadcasted
e->src_stride[i] = 0;
e->src_offset[i] = 0;
e->is_src_var[i] = false;
src_child_arrmeta[i] = src_arrmeta[i];
src_child_dt[i] = src_tp[i];
} else if (src_tp[i].get_as_strided(src_arrmeta[i], &src_size, &e->src_stride[i], &src_child_dt[i],
&src_child_arrmeta[i])) {
// Check for a broadcasting error (the strided dimension size must be 1,
// otherwise the destination should be strided, not var)
if (src_size != 1) {
throw broadcast_error(dst_tp, dst_arrmeta, src_tp[i], src_arrmeta[i]);
}
e->src_offset[i] = 0;
e->is_src_var[i] = false;
} else {
const ndt::var_dim_type *vdd = static_cast<const ndt::var_dim_type *>(src_tp[i].extended());
const var_dim_type_arrmeta *src_md = reinterpret_cast<const var_dim_type_arrmeta *>(src_arrmeta[i]);
e->src_stride[i] = src_md->stride;
e->src_offset[i] = src_md->offset;
e->is_src_var[i] = true;
src_child_arrmeta[i] = src_arrmeta[i] + sizeof(var_dim_type_arrmeta);
src_child_dt[i] = vdd->get_element_type();
}
}
return elwise_handler->make_expr_kernel(ckb, ckb_offset, dst_child_dt, dst_child_arrmeta, N, src_child_dt,
src_child_arrmeta, kernel_request_strided, ectx);
}
示例11: make_elwise_strided_or_var_to_strided_dimension_expr_kernel_for_N
static size_t make_elwise_strided_or_var_to_strided_dimension_expr_kernel_for_N(
void *ckb, intptr_t ckb_offset, const ndt::type &dst_tp, const char *dst_arrmeta, size_t DYND_UNUSED(src_count),
const ndt::type *src_tp, const char *const *src_arrmeta, kernel_request_t kernreq, const eval::eval_context *ectx,
const expr_kernel_generator *elwise_handler)
{
intptr_t undim = dst_tp.get_ndim();
const char *dst_child_arrmeta;
const char *src_child_arrmeta[N];
ndt::type dst_child_dt;
ndt::type src_child_dt[N];
strided_or_var_to_strided_expr_kernel_extra<N> *e = reinterpret_cast<ckernel_builder<kernel_request_host> *>(
ckb)->alloc_ck<strided_or_var_to_strided_expr_kernel_extra<N>>(ckb_offset);
strided_or_var_to_strided_expr_kernel_extra<N>::make(ckb, kernreq, ckb_offset);
// The dst strided parameters
if (!dst_tp.get_as_strided(dst_arrmeta, &e->size, &e->dst_stride, &dst_child_dt, &dst_child_arrmeta)) {
throw type_error("make_elwise_strided_dimension_expr_kernel: dst was not "
"strided as expected");
}
for (int i = 0; i < N; ++i) {
intptr_t src_size;
// The src[i] strided parameters
if (src_tp[i].get_ndim() < undim) {
// This src value is getting broadcasted
e->src_stride[i] = 0;
e->src_offset[i] = 0;
e->is_src_var[i] = false;
src_child_arrmeta[i] = src_arrmeta[i];
src_child_dt[i] = src_tp[i];
} else if (src_tp[i].get_as_strided(src_arrmeta[i], &src_size, &e->src_stride[i], &src_child_dt[i],
&src_child_arrmeta[i])) {
// Check for a broadcasting error
if (src_size != 1 && e->size != src_size) {
throw broadcast_error(dst_tp, dst_arrmeta, src_tp[i], src_arrmeta[i]);
}
e->src_offset[i] = 0;
e->is_src_var[i] = false;
} else {
const ndt::var_dim_type *vdd = static_cast<const ndt::var_dim_type *>(src_tp[i].extended());
const var_dim_type_arrmeta *src_md = reinterpret_cast<const var_dim_type_arrmeta *>(src_arrmeta[i]);
e->src_stride[i] = src_md->stride;
e->src_offset[i] = src_md->offset;
e->is_src_var[i] = true;
src_child_arrmeta[i] = src_arrmeta[i] + sizeof(var_dim_type_arrmeta);
src_child_dt[i] = vdd->get_element_type();
}
}
return elwise_handler->make_expr_kernel(ckb, ckb_offset, dst_child_dt, dst_child_arrmeta, N, src_child_dt,
src_child_arrmeta, kernel_request_strided, ectx);
}
示例12: substitute_shape
ndt::type ndt::substitute_shape(const ndt::type &pattern, intptr_t ndim,
const intptr_t *shape)
{
substitute_shape_data ssd;
ssd.ndim = ndim;
ssd.i = 0;
ssd.shape = shape;
ssd.fulltype = &pattern;
ndt::type transformed_tp;
bool was_transformed = false;
if (ndim > pattern.get_ndim()) {
ssd.throw_error();
}
substitute_shape_visitor(pattern, 0, &ssd, transformed_tp, was_transformed);
return transformed_tp;
}
示例13: runtime_error
base_memory_type(type_id_t type_id, const ndt::type &element_tp,
size_t data_size, size_t alignment,
size_t storage_arrmeta_offset, flags_type flags)
: base_type(type_id, memory_kind, data_size, alignment, flags,
storage_arrmeta_offset + element_tp.get_arrmeta_size(),
element_tp.get_ndim(), 0),
m_element_tp(element_tp),
m_storage_arrmeta_offset(storage_arrmeta_offset)
{
if (element_tp.get_kind() == memory_kind ||
element_tp.get_kind() == symbolic_kind) {
stringstream ss;
ss << "a memory space cannot be specified for type " << element_tp;
throw runtime_error(ss.str());
}
}
示例14: type_error
convert_type::convert_type(const ndt::type &value_type,
const ndt::type &operand_type)
: base_expr_type(
convert_type_id, expr_kind, operand_type.get_data_size(),
operand_type.get_data_alignment(),
inherited_flags(value_type.get_flags(), operand_type.get_flags()),
operand_type.get_arrmeta_size(), value_type.get_ndim()),
m_value_type(value_type), m_operand_type(operand_type)
{
// An alternative to this error would be to use value_type.value_type(), cutting
// away the expression part of the given value_type.
if (m_value_type.get_kind() == expr_kind) {
std::stringstream ss;
ss << "convert_type: The destination type " << m_value_type;
ss << " should not be an expr_kind";
throw dynd::type_error(ss.str());
}
}
示例15: make_elwise_strided_dimension_expr_kernel_for_N
static size_t make_elwise_strided_dimension_expr_kernel_for_N(void *ckb, intptr_t ckb_offset, const ndt::type &dst_tp,
const char *dst_arrmeta, size_t DYND_UNUSED(src_count),
const ndt::type *src_tp, const char *const *src_arrmeta,
kernel_request_t kernreq, const eval::eval_context *ectx,
const expr_kernel_generator *elwise_handler)
{
intptr_t undim = dst_tp.get_ndim();
const char *dst_child_arrmeta;
const char *src_child_arrmeta[N];
ndt::type dst_child_dt;
ndt::type src_child_dt[N];
strided_expr_kernel_extra<N> *e = strided_expr_kernel_extra<N>::make(ckb, kernreq, ckb_offset);
// The dst strided parameters
if (!dst_tp.get_as_strided(dst_arrmeta, &e->size, &e->dst_stride, &dst_child_dt, &dst_child_arrmeta)) {
throw type_error("make_elwise_strided_dimension_expr_kernel: dst was not "
"strided as expected");
}
for (int i = 0; i < N; ++i) {
intptr_t src_size;
// The src[i] strided parameters
if (src_tp[i].get_ndim() < undim) {
// This src value is getting broadcasted
e->src_stride[i] = 0;
src_child_arrmeta[i] = src_arrmeta[i];
src_child_dt[i] = src_tp[i];
} else if (src_tp[i].get_as_strided(src_arrmeta[i], &src_size, &e->src_stride[i], &src_child_dt[i],
&src_child_arrmeta[i])) {
// Check for a broadcasting error
if (src_size != 1 && e->size != src_size) {
throw broadcast_error(dst_tp, dst_arrmeta, src_tp[i], src_arrmeta[i]);
}
} else {
throw type_error("make_elwise_strided_dimension_expr_kernel: src was "
"not strided as expected");
}
}
return elwise_handler->make_expr_kernel(ckb, ckb_offset, dst_child_dt, dst_child_arrmeta, N, src_child_dt,
src_child_arrmeta, kernel_request_strided, ectx);
}