本文整理汇总了C++中ndt::type::get_flags方法的典型用法代码示例。如果您正苦于以下问题:C++ type::get_flags方法的具体用法?C++ type::get_flags怎么用?C++ type::get_flags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndt::type
的用法示例。
在下文中一共展示了type::get_flags方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
}
示例2:
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)
{
}
示例3: runtime_error
view_type::view_type(const ndt::type& value_type, const ndt::type& operand_type)
: base_expression_type(view_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()),
m_value_type(value_type), m_operand_type(operand_type)
{
if (value_type.get_data_size() != operand_type.value_type().get_data_size()) {
std::stringstream ss;
ss << "view_type: Cannot view " << operand_type.value_type() << " as " << value_type << " because they have different sizes";
throw std::runtime_error(ss.str());
}
if (!value_type.is_pod()) {
throw std::runtime_error("view_type: Only POD types are supported");
}
}
示例4: runtime_error
fixed_dim_type::fixed_dim_type(size_t dimension_size, const ndt::type& element_tp, intptr_t stride)
: base_uniform_dim_type(fixed_dim_type_id, element_tp, 0, element_tp.get_data_alignment(),
0, type_flag_none),
m_stride(stride), m_dim_size(dimension_size)
{
size_t child_element_size = element_tp.get_data_size();
if (child_element_size == 0) {
stringstream ss;
ss << "Cannot create dynd fixed_dim type with element type " << element_tp;
ss << ", as it does not have a fixed size";
throw runtime_error(ss.str());
}
if (dimension_size <= 1 && stride != 0) {
stringstream ss;
ss << "Cannot create dynd fixed_dim type with size " << dimension_size;
ss << " and stride " << stride << ", as the stride must be zero when the dimension size is 1";
throw runtime_error(ss.str());
}
if (dimension_size > 1 && stride == 0) {
stringstream ss;
ss << "Cannot create dynd fixed_dim type with size " << dimension_size;
ss << " and stride 0, as the stride must be non-zero when the dimension size is > 1";
throw runtime_error(ss.str());
}
m_members.data_size = m_stride * (m_dim_size-1) + child_element_size;
// Propagate the zeroinit flag from the element
m_members.flags |= (element_tp.get_flags()&type_flag_zeroinit);
// Copy ndobject properties and functions from the first non-array dimension
get_scalar_properties_and_functions(m_array_properties, m_array_functions);
}
示例5: 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());
}
}
示例6: sizeof
strided_dim_type::strided_dim_type(const ndt::type& element_tp)
: base_dim_type(strided_dim_type_id, element_tp, 0, element_tp.get_data_alignment(),
sizeof(strided_dim_type_arrmeta), type_flag_none, true)
{
// Propagate the inherited flags from the element
m_members.flags |=
(element_tp.get_flags() &
((type_flags_operand_inherited | type_flags_value_inherited) &
~type_flag_scalar));
}
示例7: runtime_error
objectarray_memory_block(const ndt::type &dt, size_t arrmeta_size, const char *arrmeta, intptr_t stride,
intptr_t initial_count)
: m_dt(dt), arrmeta_size(arrmeta_size), m_arrmeta(arrmeta), m_stride(stride), m_total_allocated_count(0),
m_finalized(false), m_memory_handles() {
if ((dt.get_flags() & type_flag_destructor) == 0) {
std::stringstream ss;
ss << "Cannot create objectarray memory block with dynd type " << dt;
ss << " because it does not have a destructor, use a POD memory block instead";
throw std::runtime_error(ss.str());
}
append_memory(initial_count);
}
示例8:
~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;
}
}
示例9:
cuda_host_type::cuda_host_type(const ndt::type& storage_tp, unsigned int cuda_host_flags)
: base_memory_type(cuda_host_type_id, storage_tp, storage_tp.get_data_size(),
get_cuda_device_data_alignment(storage_tp), 0, storage_tp.get_flags()),
m_cuda_host_flags(cuda_host_flags)
{
}
示例10:
ndt::cuda_device_type::cuda_device_type(type_id_t id, const ndt::type &element_tp)
: base_memory_type(id, element_tp, element_tp.get_data_size(), get_cuda_device_data_alignment(element_tp), 0,
element_tp.get_flags() | type_flag_not_host_readable) {}
示例11: array
static nd::array view_from_bytes(const nd::array &arr, const ndt::type &tp)
{
if (tp.get_flags() & (type_flag_blockref | type_flag_destructor | type_flag_not_host_readable)) {
// Bytes cannot be viewed as blockref types, types which require
// destruction, or types not on host memory.
return nd::array();
}
const bytes_type_arrmeta *bytes_meta = reinterpret_cast<const bytes_type_arrmeta *>(arr.get_arrmeta());
bytes_type_data *bytes_d = reinterpret_cast<bytes_type_data *>(arr.get_ndo()->data.ptr);
memory_block_ptr data_ref;
if (bytes_meta->blockref != NULL) {
data_ref = bytes_meta->blockref;
} else {
data_ref = arr.get_data_memblock();
}
char *data_ptr = bytes_d->begin;
intptr_t data_size = bytes_d->end - data_ptr;
size_t tp_data_size = tp.get_data_size();
if (tp_data_size > 0) {
// If the data type has a single chunk of POD memory, it's ok
if ((intptr_t)tp_data_size == data_size &&
offset_is_aligned(reinterpret_cast<size_t>(data_ptr), tp.get_data_alignment())) {
// Allocate a result array to attempt the view in it
nd::array result(make_array_memory_block(tp.get_arrmeta_size()));
// Initialize the fields
result.get_ndo()->data.ptr = data_ptr;
result.get_ndo()->data.ref = data_ref.release();
result.get_ndo()->m_type = ndt::type(tp).release();
result.get_ndo()->m_flags = arr.get_ndo()->m_flags;
if (tp.get_arrmeta_size() > 0) {
tp.extended()->arrmeta_default_construct(result.get_arrmeta(), true);
}
return result;
}
} else if (tp.get_type_id() == fixed_dim_type_id) {
ndt::type arr_tp = tp;
ndt::type el_tp = arr_tp.extended<ndt::base_dim_type>()->get_element_type();
size_t el_data_size = el_tp.get_data_size();
// If the element type has a single chunk of POD memory, and
// it divides into the memory size, it's ok
if (data_size % (intptr_t)el_data_size == 0 &&
offset_is_aligned(reinterpret_cast<size_t>(data_ptr), arr_tp.get_data_alignment())) {
intptr_t dim_size = data_size / el_data_size;
if (arr_tp.get_kind() != kind_kind) {
if (arr_tp.extended<ndt::fixed_dim_type>()->get_fixed_dim_size() != dim_size) {
return nd::array();
}
} else {
// Transform the symbolic fixed type into a concrete one
arr_tp = ndt::make_fixed_dim(dim_size, el_tp);
}
// Allocate a result array to attempt the view in it
nd::array result(make_array_memory_block(arr_tp.get_arrmeta_size()));
// Initialize the fields
result.get_ndo()->data.ptr = data_ptr;
result.get_ndo()->data.ref = data_ref.release();
result.get_ndo()->m_type = ndt::type(arr_tp).release();
result.get_ndo()->m_flags = arr.get_ndo()->m_flags;
if (el_tp.get_arrmeta_size() > 0) {
el_tp.extended()->arrmeta_default_construct(result.get_arrmeta() + sizeof(fixed_dim_type_arrmeta), true);
}
fixed_dim_type_arrmeta *fixed_meta = reinterpret_cast<fixed_dim_type_arrmeta *>(result.get_arrmeta());
fixed_meta->dim_size = dim_size;
fixed_meta->stride = el_data_size;
return result;
}
}
// No view could be produced
return nd::array();
}