コード例 #1
0
 /// 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
0
ファイル: serialization.hpp プロジェクト: feelpp/feelpp
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
0
  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
0
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
0
ファイル: DofMap.cpp プロジェクト: MiroK/DolfinSurface
//-----------------------------------------------------------------------------
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
0
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
0
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
0
void TrilinosVector::set( boost::multi_array<Real, 2>& data)
{
  cf_assert(m_is_created);
  cf_assert(data.shape()[0]==m_blockrow_size);
  cf_assert(data.shape()[1]==m_neq);
  for (int i=0; i<(const int)m_blockrow_size; i++)
    for (int j=0; j<(const int)m_neq; j++)
      (*m_vec)[m_p2m[i]*m_neq+j]=data[i][j];
}
コード例 #9
0
ファイル: buffer.hpp プロジェクト: aonorin/triSYCL
 /** 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())
        };
  }
コード例 #10
0
ファイル: mysqlstats.cpp プロジェクト: yp/cryptominisat
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");
}
コード例 #11
0
ファイル: png_io.cpp プロジェクト: ttk592/fdm
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);
}
コード例 #12
0
void
gmi_planner::get_GMI_sequence( double eps, int curr_vp,
									  boost::multi_array<double,3> const& oMap,
									  boost::multi_array<double,2> const& cMap,
									  std::vector<double>::iterator curr_bel_start, 
								  	  std::vector<double>::iterator curr_bel_end,
								  	  std::vector<int> & vp_seq )
{
	int num_vp = oMap.shape()[1] - 1;
	
	// Check if we can make a decision
	{
		int hid = 0;
		for( std::vector<double>::iterator it = curr_bel_start;
			it != curr_bel_end; ++it, ++hid)
			if( *it >= 1 - eps)
			{
				vp_seq.push_back(num_vp + hid);
				break;
			}
	}
	
	// rank the rest of the actions according to MI
	std::vector< std::pair<double, int> > mi_vp_vec;
	for( int vp = 0; vp < num_vp; ++vp)
		mi_vp_vec.push_back( std::make_pair( 
				MI( vp, oMap, curr_bel_start, curr_bel_end) / cMap[curr_vp][vp]
				, vp ) );

	// sort in ascending order
	//std::sort ( mi_vp_vec.begin(), mi_vp_vec.end() );
	
	// sort in descending MI order
	std::sort ( mi_vp_vec.rbegin(), mi_vp_vec.rend() );
	
	for( int vp = 0; vp < num_vp; ++vp)
	{
		vp_seq.push_back( mi_vp_vec[vp].second );
	}
}
コード例 #13
0
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;
        }
    }
}
コード例 #14
0
ファイル: Utilities.hpp プロジェクト: mforner/wpl-polsar
size_t rows(const boost::multi_array<T, N>& arr)
{
    return arr.shape()[0];
}
コード例 #15
0
ファイル: util.hpp プロジェクト: ALPSCore/CT-HYB
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;
}
コード例 #16
0
ファイル: tracker.cpp プロジェクト: MathieuLeocmach/colloids
/** \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;
};
コード例 #17
0
 /// 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);
 }
コード例 #18
0
ファイル: GraphBuilder.cpp プロジェクト: WeilinDeng/dolfin
std::int32_t GraphBuilder::compute_local_dual_graph_keyed(
  const MPI_Comm mpi_comm,
  const boost::multi_array<std::int64_t, 2>& cell_vertices,
  const CellType& cell_type,
  std::vector<std::vector<std::size_t>>& local_graph,
  FacetCellMap& facet_cell_map)
{
  Timer timer("Compute local part of mesh dual graph");

  const std::int8_t tdim = cell_type.dim();
  const std::int32_t num_local_cells = cell_vertices.shape()[0];
  const std::int8_t num_vertices_per_cell = cell_type.num_entities(0);
  const std::int8_t num_facets_per_cell = cell_type.num_entities(tdim - 1);
  const std::int8_t num_vertices_per_facet = cell_type.num_vertices(tdim - 1);

  dolfin_assert(N == num_vertices_per_facet);
  dolfin_assert(num_local_cells == (int) cell_vertices.shape()[0]);
  dolfin_assert(num_vertices_per_cell == (int) cell_vertices.shape()[1]);

  local_graph.resize(num_local_cells);
  facet_cell_map.clear();

  // Compute local edges (cell-cell connections) using global
  // (internal to this function, not the user numbering) numbering

  // Get offset for this process
  const std::int64_t cell_offset = MPI::global_offset(mpi_comm, num_local_cells,
                                                      true);

  // Create map from cell vertices to entity vertices
  boost::multi_array<unsigned int, 2>
    facet_vertices(boost::extents[num_facets_per_cell][num_vertices_per_facet]);
  std::vector<unsigned int> v(num_vertices_per_cell);
  std::iota(v.begin(), v.end(), 0);
  cell_type.create_entities(facet_vertices, tdim - 1, v.data());

  // Vector-of-arrays data structure, which is considerably faster than
  // vector-of-vectors.
  std::vector<std::pair<std::array<std::int32_t, N>, std::int32_t>>
    facets(num_facets_per_cell*num_local_cells);

  // Iterate over all cells and build list of all facets (keyed on
  // sorted vertex indices), with cell index attached
  int counter = 0;
  for (std::int32_t i = 0; i < num_local_cells; ++i)
  {
    // Iterate over facets of cell
    for (std::int8_t j = 0; j < num_facets_per_cell; ++j)
    {
      // Get list of facet vertices
      auto& facet = facets[counter].first;
      for (std::int8_t k = 0; k < N; ++k)
        facet[k] = cell_vertices[i][facet_vertices[j][k]];

      // Sort facet vertices
      std::sort(facet.begin(), facet.end());

      // Attach local cell index
      facets[counter].second = i;

      // Increment facet counter
      counter++;
    }
  }

  // Sort facets
  std::sort(facets.begin(), facets.end());

  // Find maching facets by comparing facet i and facet i -1
  std::size_t num_local_edges = 0;
  for (std::size_t i = 1; i < facets.size(); ++i)
  {
    const int ii = i;
    const int jj = i - 1;

    const auto& facet0 = facets[jj].first;
    const auto& facet1 = facets[ii].first;
    const int cell_index0 = facets[jj].second;
    if (std::equal(facet1.begin(), facet1.end(), facet0.begin()))
    {
      // Add edges (directed graph, so add both ways)
      const int cell_index1 = facets[ii].second;
      local_graph[cell_index0].push_back(cell_index1 + cell_offset);
      local_graph[cell_index1].push_back(cell_index0 + cell_offset);

      // Since we've just found a matching pair, the next pair cannot be
      // matching, so advance 1
      ++i;

      // Increment number of local edges found
      ++num_local_edges;
    }
    else
    {
      // No match, so add facet0 to map
      //facet_cell_map.insert(facet_cell_map.end(), {std::vector<std::size_t>(facet0.begin(),
      //    facet0.end()), cell_index0});
      facet_cell_map.push_back({std::vector<std::size_t>(facet0.begin(),
          facet0.end()), cell_index0});
    }
  }

  // Add last facet, as it's not covered by the above loop. We could
  // check it against the preceding facet, but it's easier to just
  // insert it here
  if (!facets.empty())
  {
    const int k = facets.size() - 1;
    const int cell_index = facets[k].second;
    facet_cell_map.push_back({std::vector<std::size_t>(facets[k].first.begin(),
        facets[k].first.end()), cell_index});
  }

  return num_local_edges;
}
コード例 #19
0
ファイル: png_io.cpp プロジェクト: ttk592/fdm
// writes a 2d array containing rgb information into a png file
bool write_png(const boost::multi_array<png::rgb,2>& pixel,
               const char* filename)
{
    FILE *fp=NULL;
    fp = fopen(filename, "wb");
    if(fp==NULL) {
        printf("write_png: error writing file %s\n", filename);
        return false;
    }

    // we need to copy the data into an array
    png_byte	**Array;
    int	height, width;
    height=pixel.shape()[0];
    width=pixel.shape()[1];

    Array = new png_byte*[height];
    for(int i=0; i<height; i++) {
        Array[i] = new png_byte[3*width];
        for(int j=0; j<width; j++) {
            assert( pixel[i][j].r<=255 );
            assert( pixel[i][j].g<=255 );
            assert( pixel[i][j].b<=255 );
            Array[i][3*j]=(png_byte) pixel[i][j].r;
            Array[i][3*j+1]=(png_byte) pixel[i][j].g;
            Array[i][3*j+2]=(png_byte) pixel[i][j].b;
        }
    }


    // initialise png_struct and png_info
    png_structp	png_ptr;
    png_infop	info_ptr;

    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
                                      NULL,writepng_error_handler,NULL);
    if(!png_ptr) {
        printf("write_png: error initialising png_ptr\n");
        return(false);
    }

    info_ptr = png_create_info_struct(png_ptr);
    if(!info_ptr) {
        printf("write_png: error creating info_ptr\n");
        png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
        return(false);
    }

    // set error handling (very strange!)
    if(setjmp(png_jmpbuf(png_ptr))) {
        printf("write_png: general error\n");
        png_destroy_write_struct(&png_ptr, &info_ptr);
        fclose(fp);
        return(false);
    }

    // making sure fp is opened in binary mode
    png_init_io(png_ptr, fp);

    // set image parameters
    png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
    png_set_IHDR(png_ptr, info_ptr, width, height,
                 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

    // writing the header
    png_write_info(png_ptr, info_ptr);

    // writing the actual data, provided by pointers to rows
    png_write_image(png_ptr, Array);

    // finishing up
    png_write_end(png_ptr, info_ptr);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    for(int i=0; i<height; i++) {
        delete[] Array[i];
    }
    delete[] Array;
    fclose(fp);

    return true;

}
コード例 #20
0
ファイル: GraphBuilder.cpp プロジェクト: WeilinDeng/dolfin
//-----------------------------------------------------------------------------
std::int32_t GraphBuilder::compute_nonlocal_dual_graph(
  const MPI_Comm mpi_comm,
  const boost::multi_array<std::int64_t, 2>& cell_vertices,
  const CellType& cell_type,
  const std::int64_t num_global_vertices,
  std::vector<std::vector<std::size_t>>& local_graph,
  FacetCellMap& facet_cell_map,
  std::set<std::int64_t>& ghost_vertices)
{
  log(PROGRESS, "Build nonlocal part of mesh dual graph");
  Timer timer("Compute non-local part of mesh dual graph");

  // Get number of MPI processes, and return if mesh is not distributed
  const int num_processes = MPI::size(mpi_comm);
  if (num_processes == 1)
    return 0;

  // At this stage facet_cell map only contains facets->cells with
  // edge facets either interprocess or external boundaries

  const int tdim = cell_type.dim();

  // List of cell vertices
  const std::int32_t num_local_cells = cell_vertices.shape()[0];
  const std::int8_t num_vertices_per_cell = cell_type.num_entities(0);
  const std::int8_t num_vertices_per_facet = cell_type.num_vertices(tdim - 1);

  dolfin_assert(num_local_cells == (int) cell_vertices.shape()[0]);
  dolfin_assert(num_vertices_per_cell == (int) cell_vertices.shape()[1]);

  // Compute local edges (cell-cell connections) using global
  // (internal to this function, not the user numbering) numbering

  // Get offset for this process
  const std::int64_t offset = MPI::global_offset(mpi_comm, num_local_cells,
                                                 true);

  // Send facet-cell map to intermediary match-making processes
  std::vector<std::vector<std::size_t>> send_buffer(num_processes);
  std::vector<std::vector<std::size_t>> received_buffer(num_processes);

  // Pack map data and send to match-maker process
  for (auto &it : facet_cell_map)
  {
    // FIXME: Could use a better index? First vertex is slightly
    //        skewed towards low values - may not be important

    // Use first vertex of facet to partition into blocks
    const int dest_proc = MPI::index_owner(mpi_comm, (it.first)[0],
                                           num_global_vertices);

    // Pack map into vectors to send
    send_buffer[dest_proc].insert(send_buffer[dest_proc].end(),
                                  it.first.begin(), it.first.end());

    // Add offset to cell numbers sent off process
    send_buffer[dest_proc].push_back(it.second + offset);
  }

  // FIXME: This does not look memory scalable. Switch to 'post-office' model.
  // Send data
  MPI::all_to_all(mpi_comm, send_buffer, received_buffer);

  // Clear send buffer
  send_buffer = std::vector<std::vector<std::size_t>>(num_processes);

  // Map to connect processes and cells, using facet as key
  typedef boost::unordered_map<std::vector<std::size_t>,
              std::pair<std::size_t, std::size_t>> MatchMap;
  MatchMap matchmap;

  // Look for matches to send back to other processes
  std::pair<std::vector<std::size_t>,
            std::pair<std::size_t, std::size_t>> key;
  key.first.resize(num_vertices_per_facet);
  for (int p = 0; p < num_processes; ++p)
  {
    // Unpack into map
    const std::vector<std::size_t>& data_p = received_buffer[p];
    for (auto it = data_p.begin(); it != data_p.end();
         it += (num_vertices_per_facet + 1))
    {
      // Build map key
      std::copy(it, it + num_vertices_per_facet, key.first.begin());
      key.second.first = p;
      key.second.second = *(it + num_vertices_per_facet);

      // Perform map insertion/look-up
      std::pair<MatchMap::iterator, bool> data = matchmap.insert(key);

      // If data is already in the map, extract data and remove from
      // map
      if (!data.second)
      {
        // Found a match of two facets - send back to owners
        const std::size_t proc1 = data.first->second.first;
        const std::size_t proc2 = p;
        const std::size_t cell1 = data.first->second.second;
        const std::size_t cell2 = key.second.second;
        send_buffer[proc1].push_back(cell1);
        send_buffer[proc1].push_back(cell2);
        send_buffer[proc2].push_back(cell2);
        send_buffer[proc2].push_back(cell1);

        // Remove facet - saves memory and search time
        matchmap.erase(data.first);
      }
    }
  }

  // Send matches to other processes
  MPI::all_to_all(mpi_comm, send_buffer, received_buffer);

  // Clear ghost vertices
  ghost_vertices.clear();

  // Flatten received data and insert connected cells into local map
  std::int32_t num_nonlocal_edges = 0;
  for (std::size_t p = 0; p < received_buffer.size(); ++p)
  {
    const std::vector<std::size_t>& cell_list = received_buffer[p];
    for (std::size_t i = 0; i < cell_list.size(); i += 2)
    {
      dolfin_assert((std::int64_t) cell_list[i] >= offset);
      dolfin_assert((std::int64_t)  (cell_list[i] - offset)
                    < (std::int64_t) local_graph.size());

      //local_graph[cell_list[i] - offset].insert(cell_list[i + 1]);
      auto& edges = local_graph[cell_list[i] - offset];
      auto it = std::find(edges.begin(), edges.end(), cell_list[i + 1]);
      if (it == local_graph[cell_list[i] - offset].end())
        edges.push_back(cell_list[i + 1]);

      ghost_vertices.insert(cell_list[i + 1]);
    }

    ++num_nonlocal_edges;
  }

  return num_nonlocal_edges;
}
コード例 #21
0
ファイル: multi_array.hpp プロジェクト: K-ballo/hpx
 void save(output_archive& ar, const boost::multi_array<T, N,
     Allocator>& marray, unsigned)
 {
     ar & make_array(marray.shape(), marray.num_dimensions());
     ar & make_array(marray.data(), marray.num_elements());
 }
コード例 #22
0
ファイル: Utilities.hpp プロジェクト: mforner/wpl-polsar
size_t cols(const boost::multi_array<T, N>& arr)
{
    return arr.shape()[1];
}
コード例 #23
0
//pb with convolution: regarder les pixels à l'intérieurs de la matrice. Affichage ligne 36. Travailler sur a qui semble etre nul trop souvent.
void Convolution(boost::multi_array<unsigned char,2> &input,
                       boost::multi_array<unsigned char,2> &output,
                       boost::multi_array<float,2>         &kernel){
	if (input.shape()[0]==output.shape()[0] and input.shape()[1]==output.shape()[1] 
		and kernel.shape()[0]== kernel.shape()[1] and kernel.shape()[0]%2==1
		and kernel.shape()[0]>=3 ){
		int k0 =int(kernel.shape()[0]);
	   
		int k1 = int(kernel.shape()[1]);
		int k = int(floor(double(kernel.shape()[0]/2)));
		int row_size = int(output.shape()[0]);
		int column_size = int(output.shape()[1]);
		
		boost::multi_array<float,2> a(boost::extents[2*k+row_size][2*k+column_size]);
		
		for(int j=0;j<k+1;j++){for(int i=0;i<k+1;i++){a[i][j]=float(input[0][0]);}}
		for(int j=0;j<k+1;j++){for(int i=row_size+k-1;i<row_size+2*k;i++){a[i][j]=float(input[row_size-1][0]);}}
		for(int j=column_size+k-1;j<column_size+2*k;j++){for(int i=0;i<k+1;i++){a[i][j]=float(input[0][column_size-1]);}}
		for(int j=column_size+k-1;j<column_size+2*k;j++){for(int i=row_size+k-1;i<row_size+2*k;i++){a[i][j]=float(input[row_size-1][column_size-1]);}}
			
		for(int j =0;j<k;j++){for(int i=k+1;i<k+row_size-1;i++){a[i][j]=float(input[i-k][k]);}}
		for(int j =k+column_size;j<2*k+column_size;j++){for(int i=k+1;i<row_size-1;i++){a[i][j]=float(input[i][column_size-1]);}}//pb
		for(int j =k+1;j<k+column_size-1;j++){for(int i=0;i<k;i++){a[i][j]=float(input[k][j-k]);}}
		for(int j =k+1;j<k+column_size-1;j++){for(int i=k+row_size;i<2*k+row_size;i++){a[i][j]=float(input[row_size-1][j-k]);}}
		for(int j = k+1;j<k+column_size-1;j++){for(int i=k+1;i<k+row_size-1;i++){a[i][j]=float(input[i-k][j-k]);}}
		
		for(int j=k;j<k+column_size;j++){for(int i=k;i<k+row_size;i++){
			float p=0;
		boost::multi_array<float,2> b(boost::extents[k0][k1]);
		
		for(int r=0;r<k0;r++){for(int s=0; s<k1;s++){
			b[r][s]=a[i-k+r][j-k+s];
		}}
		
		for(int r=0;r<k0;r++){for(int s=0; s<k1;s++){p=p+b[r][s]*float(kernel[r][s]);}}
			if(p<0){p=0;}
			if(p>=255){p=255;}
		
         output[i-k][j-k]= static_cast<unsigned char>(lround(p));
			
		}
		
	}
    }
   else{
    std::cout << "Error from the data:" << std::endl;
    std::cout <<  " See the usage of the function convolution" << std::endl;
    

   }


}