本文整理汇总了C++中dynd::nd::array::get_ndo_meta方法的典型用法代码示例。如果您正苦于以下问题:C++ array::get_ndo_meta方法的具体用法?C++ array::get_ndo_meta怎么用?C++ array::get_ndo_meta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynd::nd::array
的用法示例。
在下文中一共展示了array::get_ndo_meta方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: array_setitem
void pydynd::array_setitem(const dynd::nd::array& n, PyObject *subscript, PyObject *value)
{
if (subscript == Py_Ellipsis) {
array_broadcast_assign_from_py(n, value);
#if PY_VERSION_HEX < 0x03000000
} else if (PyInt_Check(subscript)) {
long i = PyInt_AS_LONG(subscript);
const char *metadata = n.get_ndo_meta();
char *data = n.get_readwrite_originptr();
ndt::type d = n.get_type().at_single(i, &metadata, const_cast<const char **>(&data));
array_broadcast_assign_from_py(d, metadata, data, value);
#endif // PY_VERSION_HEX < 0x03000000
} else if (PyLong_Check(subscript)) {
intptr_t i = PyLong_AsSsize_t(subscript);
if (i == -1 && PyErr_Occurred()) {
throw runtime_error("error converting int value");
}
const char *metadata = n.get_ndo_meta();
char *data = n.get_readwrite_originptr();
ndt::type d = n.get_type().at_single(i, &metadata, const_cast<const char **>(&data));
array_broadcast_assign_from_py(d, metadata, data, value);
} else {
intptr_t size;
shortvector<irange> indices;
pyobject_as_irange_array(size, indices, subscript);
array_broadcast_assign_from_py(n.at_array(size, indices.get(), false), value);
}
}
示例2: array_contains
bool pydynd::array_contains(const dynd::nd::array& n, PyObject *x)
{
if (n.get_ndo() == NULL) {
return false;
}
if (n.get_ndim() == 0) {
// TODO: Allow for struct types, etc?
throw runtime_error("cannot call __contains__ on a scalar dynd array");
}
// Turn 'n' into type/metadata/data with a uniform_dim leading dimension
nd::array tmp;
ndt::type dt;
const base_uniform_dim_type *budd;
const char *metadata, *data;
if (n.get_type().get_kind() == uniform_dim_kind) {
dt = n.get_type();
budd = static_cast<const base_uniform_dim_type *>(dt.extended());
metadata = n.get_ndo_meta();
data = n.get_readonly_originptr();
} else {
tmp = n.eval();
if (tmp.get_type().get_kind() != uniform_dim_kind) {
throw runtime_error("internal error in array_contains: expected uniform_dim kind after eval() call");
}
dt = tmp.get_type();
budd = static_cast<const base_uniform_dim_type *>(dt.extended());
metadata = tmp.get_ndo_meta();
data = tmp.get_readonly_originptr();
}
// Turn 'x' into a dynd array, and make a comparison kernel
nd::array x_ndo = array_from_py(x, 0, false);
const ndt::type& x_dt = x_ndo.get_type();
const char *x_metadata = x_ndo.get_ndo_meta();
const char *x_data = x_ndo.get_readonly_originptr();
const ndt::type& child_dt = budd->get_element_type();
const char *child_metadata = metadata + budd->get_element_metadata_offset();
comparison_ckernel_builder k;
try {
make_comparison_kernel(&k, 0,
x_dt, x_metadata, child_dt, child_metadata,
comparison_type_equal, &eval::default_eval_context);
} catch(const not_comparable_error&) {
return false;
}
contains_data aux;
aux.x_data = x_data;
aux.k = &k;
aux.found = false;
budd->foreach_leading(const_cast<char *>(data), metadata, &contains_callback, &aux);
return aux.found;
}