本文整理汇总了C++中ndt::type::get_data_alignment方法的典型用法代码示例。如果您正苦于以下问题:C++ type::get_data_alignment方法的具体用法?C++ type::get_data_alignment怎么用?C++ type::get_data_alignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndt::type
的用法示例。
在下文中一共展示了type::get_data_alignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type_error
byteswap_type::byteswap_type(const ndt::type& value_type)
: base_expr_type(byteswap_type_id, expr_kind, value_type.get_data_size(),
value_type.get_data_alignment(), type_flag_scalar, 0),
m_value_type(value_type),
m_operand_type(ndt::make_fixedbytes(value_type.get_data_size(), value_type.get_data_alignment()))
{
if (!value_type.is_builtin()) {
throw dynd::type_error("byteswap_type: Only built-in types are supported presently");
}
}
示例2: make_expression_comparison_kernel
size_t dynd::make_expression_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)
{
size_t current_offset = offset_out + sizeof(buffered_kernel_extra);
out->ensure_capacity(current_offset);
buffered_kernel_extra *e = out->get_at<buffered_kernel_extra>(offset_out);
e->base.set_function<binary_single_predicate_t>(&buffered_kernel_extra::kernel);
e->base.destructor = &buffered_kernel_extra::destruct;
// Initialize the information for buffering the operands
if (src0_dt.get_kind() == expression_kind) {
e->init_buffer(0, src0_dt.value_type());
e->buf[0].kernel_offset = current_offset - offset_out;
current_offset = make_assignment_kernel(out, current_offset,
src0_dt.value_type(), e->buf[0].metadata,
src0_dt, src0_metadata,
kernel_request_single, assign_error_none, ectx);
// Have to re-retrieve 'e', because creating another kernel may invalidate it
e = out->get_at<buffered_kernel_extra>(offset_out);
}
if (src1_dt.get_kind() == expression_kind) {
e->init_buffer(1, src1_dt.value_type());
e->buf[1].kernel_offset = current_offset - offset_out;
current_offset = make_assignment_kernel(out, current_offset,
src1_dt.value_type(), e->buf[1].metadata,
src1_dt, src1_metadata,
kernel_request_single, assign_error_none, ectx);
// Have to re-retrieve 'e', because creating another kernel may invalidate it
e = out->get_at<buffered_kernel_extra>(offset_out);
}
// Allocate the data for the buffers
if (e->buf[0].kernel_offset != 0) {
current_offset = inc_to_alignment(current_offset, src0_dt.get_data_alignment());
e->buf[0].data_offset = current_offset - offset_out;
current_offset += e->buf[0].data_size;
}
if (e->buf[1].kernel_offset != 0) {
current_offset = inc_to_alignment(current_offset, src1_dt.get_data_alignment());
e->buf[1].data_offset = current_offset - offset_out;
current_offset += e->buf[1].data_size;
}
out->ensure_capacity(current_offset);
// Have to re-retrieve 'e', because allocating the buffer data may invalidate it
e = out->get_at<buffered_kernel_extra>(offset_out);
e->cmp_kernel_offset = current_offset - offset_out;
return make_comparison_kernel(out, current_offset,
src0_dt.value_type(),
(e->buf[0].kernel_offset != 0) ? e->buf[0].metadata : src0_metadata,
src1_dt.value_type(),
(e->buf[1].kernel_offset != 0) ? e->buf[1].metadata : src1_metadata,
comptype, ectx);
}
示例3: 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;
}
}
}
示例4: 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());
}
}
}
示例5: 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);
}
示例6: 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);
}
示例7:
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)
{
}
示例8: make_elwise_reduce_result
/**
* Creates a result array for an elementwise
* reduce operation.
*/
static ndarray_node_ptr make_elwise_reduce_result(const ndt::type& result_dt, uint32_t access_flags, bool keepdims,
int ndim, const dynd_bool *reduce_axes, const intptr_t *src_shape, const int *src_axis_perm,
char *&result_originptr, intptr_t *result_strides)
{
dimvector result_shape(ndim);
// Calculate the shape and strides of the reduction result
// without removing the dimensions
intptr_t num_elements = 1;
intptr_t stride = result_dt.get_data_size();
for (int i = 0; i < ndim; ++i) {
int p = src_axis_perm[i];
if (reduce_axes[p]) {
result_shape[p] = 1;
result_strides[p] = 0;
} else {
intptr_t size = src_shape[p];
result_shape[p] = size;
if (size == 1) {
result_strides[p] = 0;
} else {
result_strides[p] = stride;
stride *= size;
num_elements *= size;
}
}
}
// Allocate the memoryblock for the data
char *originptr = NULL;
memory_block_ptr memblock = make_fixed_size_pod_memory_block(result_dt.get_data_size() * num_elements,
result_dt.get_data_alignment(), &originptr,
NULL, NULL);
ndarray_node_ptr result;
// Create the strided ndarray node, compressing the dimensions if requested
if (!keepdims) {
dimvector compressed_shape(ndim), compressed_strides(ndim);
int compressed_ndim = 0;
for (int i = 0; i < ndim; ++i) {
if (!reduce_axes[i]) {
compressed_shape[compressed_ndim] = result_shape[i];
compressed_strides[compressed_ndim] = result_strides[i];
++compressed_ndim;
}
}
result = make_strided_ndarray_node(result_dt, compressed_ndim,
compressed_shape.get(), compressed_strides.get(), originptr, access_flags, memblock);
} else {
result = make_strided_ndarray_node(result_dt, ndim,
result_shape.get(), result_strides, originptr, access_flags, memblock);
}
// Because we just allocated this buffer, we can write to it even though it
// might be marked as readonly because the src memory block is readonly
result_originptr = const_cast<char *>(result->get_readonly_originptr());
return DYND_MOVE(result);
}
示例9: 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));
}
示例10:
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)
{
}
示例11: typed_data_assign
void dynd::typed_data_assign(const ndt::type &dst_tp, const char *dst_arrmeta,
char *dst_data, const ndt::type &src_tp,
const char *src_arrmeta, const char *src_data,
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);
unary_ckernel_builder k;
make_assignment_kernel(&k, 0, dst_tp, dst_arrmeta, src_tp, src_arrmeta,
kernel_request_single, ectx);
k(dst_data, src_data);
}
示例12: 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");
}
}
示例13: typed_data_assign
void dynd::typed_data_assign(const ndt::type &dst_tp, const char *dst_arrmeta,
char *dst_data, const ndt::type &src_tp,
const char *src_arrmeta, const char *src_data,
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);
ckernel_builder<kernel_request_host> k;
make_assignment_kernel(&k, 0, dst_tp, dst_arrmeta, src_tp, src_arrmeta,
kernel_request_single, ectx);
expr_single_t fn = k.get()->get_function<expr_single_t>();
char *src = const_cast<char *>(src_data);
fn(dst_data, &src, k.get());
}
示例14: make_zeroinit_memory_block
memory_block_ptr dynd::make_zeroinit_memory_block(const ndt::type &element_tp, intptr_t initial_capacity_bytes)
{
// This is a temporary hack until the new bytes and string types are working
size_t data_size;
switch (element_tp.get_type_id()) {
case bytes_type_id:
case string_type_id:
data_size = 1;
break;
default:
data_size = element_tp.get_default_data_size();
}
zeroinit_memory_block *pmb =
new zeroinit_memory_block(data_size, element_tp.get_data_alignment(), initial_capacity_bytes);
return memory_block_ptr(reinterpret_cast<memory_block_data *>(pmb), false);
}
示例15: 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());
}
}