本文整理汇总了C++中Mat::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::begin方法的具体用法?C++ Mat::begin怎么用?C++ Mat::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::begin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(H5Handle_Test, QuickMatrixTest) {
Mat<float> mymat = ones<Mat<float> >(5,3);
Mat<float>::iterator i;
int count = 0;
for (i = mymat.begin(); i != mymat.end(); i++) {
*i = count++;
}
// mymat.raw_print(cout);
H5File::WriteMatrix("tmp.h5:/path/to/mat", mymat);
Mat<float> m;
H5File::ReadMatrix("tmp.h5:/path/to/mat", m);
Mat<float>::iterator gold, test;
for (gold = mymat.begin(), test = m.begin(); gold != mymat.end(); gold++, test++) {
float g = *gold;
float t = *test;
EXPECT_EQ(t, g);
}
}
示例2: invalid_argument
Mat<elem_type> diff(const Mat<elem_type>& X, size_type n = 1, size_type dim = 0)
{
static_assert(ARMA_VERSION_MAJOR <= 5 && ARMA_VERSION_MINOR < 400, "This function is deprecated. Use arma::diff instead.");
assert(n > 0);
Mat<elem_type> y;
if (X.empty() || dim > 1 || X.n_elem == 1) return y;
if (n > 1) return diff(diff(X, n - 1, dim));
if (X.is_vec()) {
y.resize(std::max(X.n_rows - 1, (size_type)1), std::max(X.n_cols - 1, (size_type)1));
#ifdef _MSC_VER
std::adjacent_difference(X.begin(), X.end(),
stdext::unchecked_array_iterator<elem_type *>(y.begin()));
#else
std::adjacent_difference(X.begin(), X.end(), y.begin());
#endif
return y;
}
switch (dim) {
case 0: // row difference
y.resize(X.n_rows - 1, X.n_cols);
for (size_type c = 0 ; c < X.n_cols ; c++)
#ifdef _MSC_VER
std::adjacent_difference(X.begin_col(c), X.end_col(c),
stdext::unchecked_array_iterator<elem_type *>(y.begin_col(c)));
#else
std::adjacent_difference(X.begin_col(c), X.end_col(c), y.begin_col(c));
#endif
break;
case 1: // column difference
y.resize(X.n_rows, X.n_cols - 1);
for (size_type c = 0 ; c < X.n_cols - 1; c++)
y.col(c) = X.col(c + 1) - X.col(c);
break;
default:
throw std::invalid_argument("dim should be 0 or 1"); //
}
return y;
}
示例3: indices
inline
bool
op_find_unique::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const bool ascending_indices)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const uword n_elem = P.get_n_elem();
if(n_elem == 0) {
out.set_size(0,1);
return true;
}
if(n_elem == 1) {
out.set_size(1,1);
out[0] = 0;
return true;
}
uvec indices(n_elem);
std::vector< arma_find_unique_packet<eT> > packet_vec(n_elem);
if(Proxy<T1>::prefer_at_accessor == false)
{
typename Proxy<T1>::ea_type Pea = P.get_ea();
for(uword i=0; i<n_elem; ++i)
{
const eT val = Pea[i];
if(arma_isnan(val)) {
return false;
}
packet_vec[i].val = val;
packet_vec[i].index = i;
}
}
else
{
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
uword i = 0;
for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row)
{
const eT val = P.at(row,col);
if(arma_isnan(val)) {
return false;
}
packet_vec[i].val = val;
packet_vec[i].index = i;
++i;
}
}
arma_find_unique_comparator<eT> comparator;
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
uword* indices_mem = indices.memptr();
indices_mem[0] = packet_vec[0].index;
uword count = 1;
for(uword i=1; i < n_elem; ++i)
{
const eT diff = packet_vec[i-1].val - packet_vec[i].val;
if(diff != eT(0))
{
indices_mem[count] = packet_vec[i].index;
++count;
}
}
out.steal_mem_col(indices,count);
if(ascending_indices) {
std::sort(out.begin(), out.end());
}
return true;
}