本文整理汇总了C++中boost::multi_array::shape方法的典型用法代码示例。如果您正苦于以下问题:C++ multi_array::shape方法的具体用法?C++ multi_array::shape怎么用?C++ multi_array::shape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::multi_array
的用法示例。
在下文中一共展示了multi_array::shape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get
/// Copies the contents out of the LSS::Vector to table.
void get( boost::multi_array<Real, 2>& data)
{
cf3_assert(m_is_created);
cf3_assert(data.shape()[0]==m_blockrow_size);
cf3_assert(data.shape()[1]==m_neq);
for (boost::multi_array_types::index i = 0; i < data.shape()[0]; ++i)
for (boost::multi_array_types::index j = 0; j < data.shape()[1]; ++j)
data[i][j]=0.;
}
示例2: save
void save( Archive & ar,
const boost::multi_array<double,2> & t,
const unsigned int file_version )
{
typedef boost::multi_array<double,2> multi_array_;
typedef typename multi_array_::size_type size_;
size_ n0 = ( t.shape()[0] );
ar << BOOST_SERIALIZATION_NVP( n0 );
size_ n1 = ( t.shape()[1] );
ar << BOOST_SERIALIZATION_NVP( n1 );
ar << boost::serialization::make_array( t.data(),
t.num_elements() );
}
示例3: save
void save(handle const& loc,
boost::multi_array<ValueType, NumDims, Allocator> const& h,
const char* name)
{
datatype type = datatype_from<ValueType>::value();
std::array<hsize_t, NumDims> extents;
std::copy(h.shape(), h.shape() + NumDims, extents.begin());
dataspace space = dataspace::create_simple(extents);
( link_exists(loc, name)
? dataset::open(loc, name)
: dataset::create(loc, name, type, space) )
.write(type, space, h.data());
}
示例4:
double
gmi_planner::MI( int vp, boost::multi_array<double,3> const& oMap,
std::vector<double>::iterator curr_bel_start,
std::vector<double>::iterator curr_bel_end )
{
int num_obs = oMap.shape()[0];
double mi = 0.0;
for(int obs = 0; obs < num_obs; ++obs)
{
double qTp = 0.0;
int hid = 0;
for( std::vector<double>::iterator it = curr_bel_start;
it != curr_bel_end; ++it, ++hid)
{
qTp += oMap[obs][vp][hid] * (*it);
}
hid = 0;
for( std::vector<double>::iterator it = curr_bel_start;
it != curr_bel_end; ++it, ++hid)
{
mi += (oMap[obs][vp][hid] * (*it)) * log2( qTp / (oMap[obs][vp][hid] * (*it)));
}
}
return mi;
}
示例5: tabulate_coordinates
//-----------------------------------------------------------------------------
void DofMap::tabulate_coordinates(boost::multi_array<double, 2>& coordinates,
const ufc::cell& ufc_cell) const
{
// FIXME: This is a hack because UFC wants a double pointer for coordinates
dolfin_assert(_ufc_dofmap);
// Check dimensions
if (coordinates.shape()[0] != cell_dimension(ufc_cell.index) ||
coordinates.shape()[1] != _ufc_dofmap->geometric_dimension())
{
boost::multi_array<double, 2>::extent_gen extents;
const std::size_t cell_dim = cell_dimension(ufc_cell.index);
coordinates.resize(extents[cell_dim][_ufc_dofmap->geometric_dimension()]);
}
// Set vertex coordinates
const std::size_t num_points = coordinates.size();
std::vector<double*> coords(num_points);
for (std::size_t i = 0; i < num_points; ++i)
coords[i] = &(coordinates[i][0]);
// Tabulate coordinates
_ufc_dofmap->tabulate_coordinates(coords.data(),
&ufc_cell.vertex_coordinates[0]);
}
示例6: From
inline DataSpace DataSpace::From(const boost::multi_array<Value, Dims> & container){
std::vector<size_t> dims(Dims);
for(std::size_t i = 0; i < Dims; ++i){
dims[i] = container.shape()[i];
}
return DataSpace(dims);
}
示例7: write_png
bool wotreplay::write_png(std::ostream &os, boost::multi_array<uint8_t, 3> &image) {
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
png_infop info_ptr = png_create_info_struct(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_write_struct(&png_ptr, &info_ptr);
return false;
}
png_set_write_fn(png_ptr, &os, &user_write_data, &user_flush_data);
png_set_filter(png_ptr, 0,PNG_FILTER_VALUE_NONE);
const size_t *shape = image.shape();
size_t width = shape[1], height = shape[0], channels = shape[2];
bool alpha = channels == 4;
png_set_IHDR(png_ptr, info_ptr, static_cast<uint32_t>(width), static_cast<uint32_t>(height),
8, alpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
std::vector<png_bytep> row_pointers;
get_row_pointers(image, row_pointers);
png_set_rows(png_ptr, info_ptr, &row_pointers[0]);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
return true;
}
示例8: get_range
/** Return a range object representing the size of the buffer in
terms of number of elements in each dimension as passed to the
constructor
*/
auto get_range() const {
/* Interpret the shape which is a pointer to the first element as an
array of Dimensions elements so that the range<Dimensions>
constructor is happy with this collection
\todo Add also a constructor in range<> to accept a const
std::size_t *?
*/
return range<Dimensions> {
*(const std::size_t (*)[Dimensions])(allocation.shape())
};
}
示例9: clauseSizeGlueScatter
void MySQLStats::clauseSizeGlueScatter(
uint64_t sumConflicts
, boost::multi_array<uint32_t, 2>& sizeAndGlue
) {
//assert(glues.size() == stmtClsDistrib.value.size());
//assert(glues.size() == stmtClsDistrib.num.size());
const size_t numInserts = stmtSizeGlueScatter.size.size();
stmtSizeGlueScatter.sumConflicts = sumConflicts;
size_t at = 0;
for(size_t i = 0; i < sizeAndGlue.shape()[0]; i++) {
for(size_t i2 = 0; i2 < sizeAndGlue.shape()[1]; i2++) {
stmtSizeGlueScatter.size[at] = i;
stmtSizeGlueScatter.glue[at] = i2;
stmtSizeGlueScatter.num[at] = sizeAndGlue[i][i2];
at++;
if (at == numInserts) {
if (mysql_stmt_execute(stmtSizeGlueScatter.stmt)) {
cout
<< "ERROR: while executing restart insertion MySQL prepared statement"
<< endl;
cout << "Error from mysql: "
<< mysql_stmt_error(stmtSizeGlueScatter.stmt)
<< endl;
std::exit(-1);
}
at = 0;
}
}
}
assert(at == 0 && "numInserts must be divisible");
}
示例10: write_png
bool write_png(const boost::multi_array<double,2>& value,
const char* filename)
{
int n0=value.shape()[0];
int n1=value.shape()[1];
boost::multi_array<png::rgb,2> pixels(boost::extents[n0][n1]);
double x;
for(int i=0; i<n0; i++) {
for(int j=0; j<n1; j++) {
x=value[i][j];
if(x<0.0) x=0.0;
if(x>1.0) x=1.0;
pixels[i][j]=wavelength2rgb(420.0+200.0*x);
}
}
return write_png(pixels,filename);
}
示例11: draw_position
void image_writer_t::draw_position(const packet_t &packet, const game_t &game, boost::multi_array<float, 3> &image) {
uint32_t player_id = packet.player_id();
int team_id = game.get_team_id(player_id);
if (team_id < 0) return;
auto shape = image.shape();
int width = static_cast<int>(shape[2]);
int height = static_cast<int>(shape[1]);
float x,y;
std::tie(x,y) = get_2d_coord( packet.position(), game, width, height);
if (x >= 0 && y >= 0 && x <= (width - 1) && y <= (height - 1)) {
image[team_id][y][x] = 1;
if (player_id == game.get_recorder_id()) {
image[2][y][x] = 1;
}
}
}
示例12: rows
size_t rows(const boost::multi_array<T, N>& arr)
{
return arr.shape()[0];
}
示例13:
boost::multi_array<double, DIMENSION>
get_imag_parts(const boost::multi_array<SCALAR, DIMENSION> &data) {
boost::multi_array<double, DIMENSION> imag_part(data.shape());
std::transform(data.begin(), data.end(), imag_part.begin(), get_imag);
return imag_part;
}
示例14: range
/** \brief get the centroid of the neighbourhood of an image pixel given by it's offset */
valarray<double> centroid::operator()(const size_t& l) const
{
const int scope = 1;
//convert the raveled index to 3D indices
size_t
i = l / image.strides()[0],
j = (l % image.strides()[0]) / image.strides()[1],
k = (l % image.strides()[0]) % image.strides()[1];
//cout<<"l="<<l<<" -> i="<<i<<" j="<<j<<" k="<<k<<" ... ";
//the data of the neighbourhood view are copied together for the coder's sanity
boost::multi_array<float,3> ngb =
image[boost::indices
[image.shape()[0]<2*scope+1 ? range() : range(i-scope, i+scope+1)]
[image.shape()[1]<2*scope+1 ? range() : range(j-scope, j+scope+1)]
[image.shape()[2]<2*scope+1 ? range() : range(k-scope, k+scope+1)]
];
//Find the extrema of the neighbourhood.
std::pair<float*, float*> minmax = boost::minmax_element(ngb.origin(), ngb.origin()+ngb.num_elements());
//If the neighbourhood contains a negative pixel, we are at the edge of a Fourier filtering artefact that should not be considered a particle
if(*minmax.first < 0)
return valarray<double>(-1.0, 3);
//marking non local maxima (including diagonals)
if(image.origin()[l] != *minmax.second)
return valarray<double>(-1.0, 3);
//calculation of the intensity centroid
valarray<double> c(0.0,3);
double total_w = 0.0;
float *px = ngb.origin();
for(int x=0; x<ngb.shape()[0];++x)
for(int y=0; y<ngb.shape()[1];++y)
for(int z=0; z<ngb.shape()[2];++z)
{
const double weight = pow((double)(x-scope), 2) + pow((double)(y-scope), 2) + pow((double)(z-scope), 2) * (double)(*px);
c[0] += (x-scope)*weight;
c[1] += (y-scope)*weight;
c[2] += (z-scope)*weight;
total_w += weight ;
px++;
}
//cout<<c[0]<<"\t"<<c[1]<<"\t"<<c[2]<<endl;
//cout<<"divide by a weight of "<<total_w<<endl;
c /= total_w/pow(2.0*scope+1, 2);
//cout<<c[0]<<"\t"<<c[1]<<"\t"<<c[2]<<endl;
//c /= (double)accumulate(ngb.origin(), ngb.origin()+ngb.num_elements(), 0.0);
//double sum = accumulate(ngb.origin(),ngb.origin()+ngb.num_elements(),0.0);
//cout<<"valarrays ... ";
/*valarray<double> c(0.0,3), pos(0.0,3), middle(0.0,3);
for(size_t d=0; d<3;++d)
middle[d] = ngb.shape()[d]/3;
float *v = ngb.origin();
for(pos[0]=0;pos[0]<ngb.shape()[0];++pos[0])
for(pos[1]=0;pos[1]<ngb.shape()[1];++pos[1])
for(pos[2]=0;pos[2]<ngb.shape()[2];++pos[2])
c += (pos-middle) * (*v++);//pow(*v++, 2.0f);
c /= image.origin()[l];//pow(image.origin()[l], 2.0f);
for(size_t d=0;d<3;++d)
c[d] = (c[d]<0?-1:1) * sqrt(abs(c[d]))/4.5;*/
c[0] += i;
c[1] += j;
c[2] += k;
return c;
};
示例15: set
/// Copies the contents of the table into the LSS::Vector.
void set( boost::multi_array<Real, 2>& data)
{
cf3_assert(m_is_created);
cf3_assert(data.shape()[0]==m_blockrow_size);
cf3_assert(data.shape()[1]==m_neq);
}