本文整理汇总了C++中Mat::fill方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::fill方法的具体用法?C++ Mat::fill怎么用?C++ Mat::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proxy
inline
void
op_sp_plus::apply(Mat<typename T1::elem_type>& out, const SpToDOp<T1,op_sp_plus>& in)
{
arma_extra_debug_sigprint();
// Note that T1 will be a sparse type, so we use SpProxy.
const SpProxy<T1> proxy(in.m);
out.set_size(proxy.get_n_rows(), proxy.get_n_cols());
out.fill(in.aux);
typename SpProxy<T1>::const_iterator_type it = proxy.begin();
typename SpProxy<T1>::const_iterator_type it_end = proxy.end();
for(; it != it_end; ++it)
{
out.at(it.row(), it.col()) += (*it);
}
}
示例2: forward
int LRN::forward(const Mat& bottom_blob, Mat& top_blob) const
{
int w = bottom_blob.w;
int h = bottom_blob.h;
int channels = bottom_blob.c;
int size = w * h;
top_blob.create(w, h, channels);
if (top_blob.empty())
return -100;
// squared values with local_size padding
Mat square_blob;
square_blob.create(w, h, channels);
if (square_blob.empty())
return -100;
#pragma omp parallel for
for (int q=0; q<channels; q++)
{
const float* ptr = bottom_blob.channel(q);
float* outptr = square_blob.channel(q);
for (int i=0; i<size; i++)
{
outptr[i] = ptr[i] * ptr[i];
}
}
if (region_type == NormRegion_ACROSS_CHANNELS)
{
top_blob.fill(0.f);
const float alpha_div_size = alpha / local_size;
#pragma omp parallel for
for (int q=0; q<channels; q++)
{
// square sum
float* outptr = top_blob.channel(q);
for (int p=q - local_size / 2; p<=q + local_size / 2; p++)
{
if (p < 0 || p >= channels)
continue;
const float* sptr = square_blob.channel(p);
for (int i=0; i<size; i++)
{
outptr[i] += sptr[i];
}
}
const float* ptr = bottom_blob.channel(q);
for (int i=0; i<size; i++)
{
outptr[i] = ptr[i] * pow(1.f + alpha_div_size * outptr[i], -beta);
}
}
}
else if (region_type == NormRegion_WITHIN_CHANNEL)
{
int outw = w;
int outh = h;
Mat square_blob_bordered = square_blob;
int pad = local_size / 2;
if (pad > 0)
{
copy_make_border(square_blob, square_blob_bordered, pad, local_size - pad - 1, pad, local_size - pad - 1, BORDER_CONSTANT, 0.f);
if (square_blob_bordered.empty())
return -100;
w = square_blob_bordered.w;
h = square_blob_bordered.h;
}
const int maxk = local_size * local_size;
const float alpha_div_size = alpha / maxk;
// norm window offsets
std::vector<int> _space_ofs(maxk);
int* space_ofs = &_space_ofs[0];
{
int p1 = 0;
int p2 = 0;
int gap = w - local_size;
for (int i = 0; i < local_size; i++)
{
for (int j = 0; j < local_size; j++)
{
space_ofs[p1] = p2;
p1++;
p2++;
}
p2 += gap;
}
}
#pragma omp parallel for
//.........这里部分代码省略.........
示例3: forward
int DeconvolutionDepthWise::forward(const Mat& bottom_blob, Mat& top_blob) const
{
// deconvolv with NxN kernel
// value = value + bias
int w = bottom_blob.w;
int h = bottom_blob.h;
int channels = bottom_blob.c;
if (channels % group != 0 || num_output % group != 0)
{
// reject invalid group
return -100;
}
const int kernel_extent_w = dilation_w * (kernel_w - 1) + 1;
const int kernel_extent_h = dilation_h * (kernel_h - 1) + 1;
int outw = (w - 1) * stride_w + kernel_extent_w;
int outh = (h - 1) * stride_h + kernel_extent_h;
Mat top_blob_bordered = top_blob;
top_blob_bordered.create(outw, outh, num_output);
if (top_blob_bordered.empty())
return -100;
const int maxk = kernel_w * kernel_h;
// kernel offsets
std::vector<int> _space_ofs(maxk);
int* space_ofs = &_space_ofs[0];
{
int p1 = 0;
int p2 = 0;
int gap = outw * dilation_h - kernel_w * dilation_w;
for (int i = 0; i < kernel_h; i++)
{
for (int j = 0; j < kernel_w; j++)
{
space_ofs[p1] = p2;
p1++;
p2 += dilation_w;
}
p2 += gap;
}
}
// depth-wise
if (channels == group && group == num_output)
{
#pragma omp parallel for
for (int g=0; g<group; g++)
{
const float* inptr = bottom_blob.channel(g);
const float* kptr = (const float*)weight_data + maxk * g;
Mat m = top_blob_bordered.channel(g);
const float bias = bias_term ? bias_data[g] : 0.f;
m.fill(bias);
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
float* outptr = m.row(i*stride_h) + j*stride_w;
for (int k = 0; k < maxk; k++)
{
float val = inptr[i*w + j];
float w = kptr[k];
outptr[ space_ofs[k] ] += val * w;
}
}
}
}
}
else
{
// num_output
const int channels_g = channels / group;
const int num_output_g = num_output / group;
#pragma omp parallel for
for (int g = 0; g < group; g++)
{
const float* weight_data_ptr = (const float*)weight_data + maxk * channels_g * num_output_g * g;
for (int p = 0; p < num_output_g; p++)
{
Mat out = top_blob_bordered.channel(g * num_output_g + p);
const float bias = bias_term ? bias_data[g * num_output_g + p] : 0.f;
out.fill(bias);
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
float* outptr = out.row(i*stride_h) + j*stride_w;
//.........这里部分代码省略.........