本文整理汇总了C++中ndt::type::extended方法的典型用法代码示例。如果您正苦于以下问题:C++ type::extended方法的具体用法?C++ type::extended怎么用?C++ type::extended使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndt::type
的用法示例。
在下文中一共展示了type::extended方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: make_assignment_kernel
size_t fixedbytes_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()) {
switch (src_tp.get_type_id()) {
case fixedbytes_type_id: {
const fixedbytes_type *src_fs = src_tp.tcast<fixedbytes_type>();
if (get_data_size() != src_fs->get_data_size()) {
throw runtime_error("cannot assign to a fixedbytes type of a different size");
}
return ::make_pod_typed_data_assignment_kernel(ckb, ckb_offset,
get_data_size(), std::min(get_data_alignment(), src_fs->get_data_alignment()),
kernreq);
}
default: {
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());
}
}
示例3: make_assignment_kernel
size_t cstruct_type::make_assignment_kernel(
ckernel_builder *out, size_t offset_out,
const ndt::type& dst_tp, const char *dst_metadata,
const ndt::type& src_tp, const char *src_metadata,
kernel_request_t kernreq, assign_error_mode errmode,
const eval::eval_context *ectx) const
{
if (this == dst_tp.extended()) {
if (this == src_tp.extended()) {
return make_struct_identical_assignment_kernel(out, offset_out,
dst_tp,
dst_metadata, src_metadata,
kernreq, errmode, ectx);
} else if (src_tp.get_kind() == struct_kind) {
return make_struct_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
} else if (!src_tp.is_builtin()) {
return src_tp.extended()->make_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
}
}
stringstream ss;
ss << "Cannot assign from " << src_tp << " to " << dst_tp;
throw runtime_error(ss.str());
}
示例4: make_comparison_kernel
size_t string_type::make_comparison_kernel(
ckernel_builder *out, size_t offset_out,
const ndt::type& src0_dt, const char *src0_metadata,
const ndt::type& src1_dt, const char *src1_metadata,
comparison_type_t comptype,
const eval::eval_context *ectx) const
{
if (this == src0_dt.extended()) {
if (*this == *src1_dt.extended()) {
return make_string_comparison_kernel(out, offset_out,
m_encoding,
comptype, ectx);
} else if (src1_dt.get_kind() == string_kind) {
return make_general_string_comparison_kernel(out, offset_out,
src0_dt, src0_metadata,
src1_dt, src1_metadata,
comptype, ectx);
} else if (!src1_dt.is_builtin()) {
return src1_dt.extended()->make_comparison_kernel(out, offset_out,
src0_dt, src0_metadata,
src1_dt, src1_metadata,
comptype, ectx);
}
}
throw not_comparable_error(src0_dt, src1_dt, comptype);
}
示例5: 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());
}
}
示例6: format_json_uniform_dim
static void format_json_uniform_dim(output_data& out, const ndt::type& dt, const char *metadata, const char *data)
{
out.write('[');
switch (dt.get_type_id()) {
case strided_dim_type_id: {
const strided_dim_type *sad = static_cast<const strided_dim_type *>(dt.extended());
const strided_dim_type_metadata *md = reinterpret_cast<const strided_dim_type_metadata *>(metadata);
ndt::type element_tp = sad->get_element_type();
intptr_t size = md->size, stride = md->stride;
metadata += sizeof(strided_dim_type_metadata);
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, data + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
case fixed_dim_type_id: {
const fixed_dim_type *fad = static_cast<const fixed_dim_type *>(dt.extended());
ndt::type element_tp = fad->get_element_type();
intptr_t size = (intptr_t)fad->get_fixed_dim_size(), stride = fad->get_fixed_stride();
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, data + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
case var_dim_type_id: {
const var_dim_type *vad = static_cast<const var_dim_type *>(dt.extended());
const var_dim_type_metadata *md = reinterpret_cast<const var_dim_type_metadata *>(metadata);
const var_dim_type_data *d = reinterpret_cast<const var_dim_type_data *>(data);
ndt::type element_tp = vad->get_element_type();
intptr_t size = d->size, stride = md->stride;
const char *begin = d->begin + md->offset;
metadata += sizeof(var_dim_type_metadata);
for (intptr_t i = 0; i < size; ++i) {
::format_json(out, element_tp, metadata, begin + i * stride);
if (i != size - 1) {
out.write(',');
}
}
break;
}
default: {
stringstream ss;
ss << "Formatting dynd type " << dt << " as JSON is not implemented yet";
throw runtime_error(ss.str());
}
}
out.write(']');
}
示例7:
~buffer_storage()
{
if (m_storage && m_type.get_flags()&type_flag_destructor) {
m_type.extended()->data_destruct_strided(m_arrmeta, m_storage, m_stride,
DYND_BUFFER_CHUNK_SIZE);
}
delete[] m_storage;
if (m_arrmeta) {
m_type.extended()->arrmeta_destruct(m_arrmeta);
delete[] m_arrmeta;
}
}
示例8: is_lossless_assignment
bool typevar_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
if (dst_tp.extended() == this) {
if (src_tp.extended() == this) {
return true;
} else if (src_tp.get_type_id() == typevar_type_id) {
return *dst_tp.extended() == *src_tp.extended();
}
}
return false;
}
示例9: make_assignment_kernel
size_t datetime_type::make_assignment_kernel(
ckernel_builder *out, size_t offset_out,
const ndt::type& dst_tp, const char *dst_metadata,
const ndt::type& src_tp, const char *src_metadata,
kernel_request_t kernreq, assign_error_mode errmode,
const eval::eval_context *ectx) const
{
if (this == dst_tp.extended()) {
if (src_tp == dst_tp) {
return make_pod_typed_data_assignment_kernel(out, offset_out,
get_data_size(), get_data_alignment(), kernreq);
} else if (src_tp.get_kind() == string_kind) {
// Assignment from strings
return make_string_to_datetime_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
} else if (src_tp.get_kind() == struct_kind) {
// Convert to struct using the "struct" property
return ::make_assignment_kernel(out, offset_out,
ndt::make_property(dst_tp, "struct"), dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
} else if (!src_tp.is_builtin()) {
return src_tp.extended()->make_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
}
} else {
if (dst_tp.get_kind() == string_kind) {
// Assignment to strings
return make_datetime_to_string_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
} else if (dst_tp.get_kind() == struct_kind) {
// Convert to struct using the "struct" property
return ::make_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
ndt::make_property(src_tp, "struct"), src_metadata,
kernreq, errmode, ectx);
}
// TODO
}
stringstream ss;
ss << "Cannot assign from " << src_tp << " to " << dst_tp;
throw runtime_error(ss.str());
}
示例10: is_lossless_assignment
bool categorical_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
if (dst_tp.extended() == this) {
if (src_tp.extended() == this) {
// Casting from identical types
return true;
} else {
return false; // TODO
}
} else {
return ::is_lossless_assignment(dst_tp, m_category_tp); // TODO
}
}
示例11: make_assignment_kernel
size_t string_type::make_assignment_kernel(
ckernel_builder *out, size_t offset_out,
const ndt::type& dst_tp, const char *dst_metadata,
const ndt::type& src_tp, const char *src_metadata,
kernel_request_t kernreq, assign_error_mode errmode,
const eval::eval_context *ectx) const
{
if (this == dst_tp.extended()) {
switch (src_tp.get_type_id()) {
case string_type_id: {
return make_blockref_string_assignment_kernel(out, offset_out,
dst_metadata, get_encoding(),
src_metadata, static_cast<const base_string_type *>(src_tp.extended())->get_encoding(),
kernreq, errmode, ectx);
}
case fixedstring_type_id: {
return make_fixedstring_to_blockref_string_assignment_kernel(out, offset_out,
dst_metadata, get_encoding(),
src_tp.get_data_size(),
static_cast<const base_string_type *>(src_tp.extended())->get_encoding(),
kernreq, errmode, ectx);
}
default: {
if (!src_tp.is_builtin()) {
return src_tp.extended()->make_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp, src_metadata,
kernreq, errmode, ectx);
} else {
return make_builtin_to_string_assignment_kernel(out, offset_out,
dst_tp, dst_metadata,
src_tp.get_type_id(),
kernreq, errmode, ectx);
}
}
}
} else {
if (dst_tp.is_builtin()) {
return make_string_to_builtin_assignment_kernel(out, offset_out,
dst_tp.get_type_id(),
src_tp, src_metadata,
kernreq, errmode, ectx);
} else {
stringstream ss;
ss << "Cannot assign from " << src_tp << " to " << dst_tp;
throw dynd::type_error(ss.str());
}
}
}
示例12: is_lossless_assignment
bool fixedbytes_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
if (dst_tp.extended() == this) {
if (src_tp.extended() == this) {
return true;
} else if (src_tp.get_type_id() == fixedbytes_type_id) {
const fixedbytes_type *src_fs = static_cast<const fixedbytes_type*>(src_tp.extended());
return get_data_size() == src_fs->get_data_size();
} else {
return false;
}
} else {
return false;
}
}
示例13: is_lossless_assignment
bool datetime_type::is_lossless_assignment(const ndt::type& dst_tp, const ndt::type& src_tp) const
{
if (dst_tp.extended() == this) {
if (src_tp.extended() == this) {
return true;
} else if (src_tp.get_type_id() == date_type_id) {
// There is only one possibility for the date type (TODO: timezones!)
return true;
} else {
return false;
}
} else {
return false;
}
}
示例14: try_view
/**
* Scans through the types, and tries to view data
* for 'tp'/'arrmeta' as 'view_tp'. For this to be
* possible, one must be able to construct
* arrmeta for 'tp' corresponding to the same data.
*
* \param tp The type of the data.
* \param arrmeta The array arrmeta of the data.
* \param view_tp The type the data should be viewed as.
* \param view_arrmeta The array arrmeta of the view, which should be populated.
* \param embedded_reference The containing memory block in case the data was embedded.
*
* \returns If it worked, returns true, otherwise false.
*/
static bool try_view(const ndt::type &tp, const char *arrmeta, const ndt::type &view_tp, char *view_arrmeta,
dynd::memory_block_data *embedded_reference)
{
switch (tp.get_type_id()) {
case fixed_dim_type_id: {
// All the strided dim types share the same arrmeta, so can be
// treated uniformly here
const ndt::base_dim_type *sdt = tp.extended<ndt::base_dim_type>();
const fixed_dim_type_arrmeta *md = reinterpret_cast<const fixed_dim_type_arrmeta *>(arrmeta);
switch (view_tp.get_type_id()) {
case fixed_dim_type_id: { // strided as fixed
const ndt::fixed_dim_type *view_fdt = view_tp.extended<ndt::fixed_dim_type>();
// The size must match exactly in this case
if (md->dim_size != view_fdt->get_fixed_dim_size()) {
return false;
}
fixed_dim_type_arrmeta *view_md = reinterpret_cast<fixed_dim_type_arrmeta *>(view_arrmeta);
if (try_view(sdt->get_element_type(), arrmeta + sizeof(fixed_dim_type_arrmeta), view_fdt->get_element_type(),
view_arrmeta + sizeof(fixed_dim_type_arrmeta), embedded_reference)) {
*view_md = *md;
return true;
} else {
return false;
}
}
default: // other cases cannot be handled
return false;
}
}
default:
if (tp == view_tp) {
// require equal types otherwise
if (tp.get_arrmeta_size() > 0) {
tp.extended()->arrmeta_copy_construct(view_arrmeta, arrmeta, embedded_reference);
}
return true;
} else if (tp.is_pod() && view_tp.is_pod() && tp.get_data_size() == view_tp.get_data_size() &&
tp.get_data_alignment() >= view_tp.get_data_alignment()) {
// POD types with matching properties
if (view_tp.get_arrmeta_size() > 0) {
view_tp.extended()->arrmeta_default_construct(view_arrmeta, true);
}
return true;
} else {
return false;
}
}
}
示例15: 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());
}
}
}