コード例 #1
0
ファイル: intersect1d.hpp プロジェクト: artas360/pythran
 types::ndarray<
     typename __combined<typename types::numpy_expr_to_ndarray<E>::T,
                         typename types::numpy_expr_to_ndarray<F>::T>::type,
     1>
 intersect1d(E const &e, F const &f)
 {
   using T = typename __combined<
       typename types::numpy_expr_to_ndarray<E>::T,
       typename types::numpy_expr_to_ndarray<F>::T>::type;
   auto ae = asarray(e);
   auto af = asarray(f);
   std::set<T> sae(ae.fbegin(), ae.fend());
   std::set<T> found;
   types::list<T> lout(0);
   lout.reserve(sae.size());
   for (auto iter = af.fbegin(), end = af.fend(); iter != end; ++iter) {
     auto curr = *iter;
     if (sae.find(curr) != sae.end() and found.find(curr) == found.end()) {
       found.insert(curr);
       lout.push_back(curr);
     }
   }
   std::sort(lout.begin(), lout.end());
   return types::ndarray<T, 1>(lout);
 }
コード例 #2
0
ファイル: globobj.cpp プロジェクト: dspinellis/cscout
void
GlobObj::dumpSql(Sql *db, ostream &of)
{
	// First define all functions
	for (const_fmap_iterator_type i = fbegin(); i != fend(); i++) {
		Call *fun = i->second;
		Tokid t = fun->get_site();
		of << "INSERT INTO FUNCTIONS VALUES(" <<
		ptr_offset(fun) << ", '" <<
		fun->name << "', " <<
		db->boolval(fun->is_macro()) << ',' <<
		db->boolval(fun->is_defined()) << ',' <<
		db->boolval(fun->is_declared()) << ',' <<
		db->boolval(fun->is_file_scoped()) << ',' <<
		t.get_fileid().get_id() << ',' <<
		(unsigned)(t.get_streampos()) << ',' <<
		fun->get_num_caller();
		of << ");\n";

		if (fun->is_defined()) {
			of << "INSERT INTO FUNCTIONMETRICS VALUES(" << ptr_offset(fun);
			for (int j = 0; j < FunMetrics::metric_max; j++)
				if (!Metrics::is_internal<FunMetrics>(j))
					cout << ',' << fun->metrics().get_metric(j);
			of << ',' << fun->get_begin().get_tokid().get_fileid().get_id() <<
			',' << (unsigned)(fun->get_begin().get_tokid().get_streampos()) <<
			',' << fun->get_end().get_tokid().get_fileid().get_id() <<
			',' << (unsigned)(fun->get_end().get_tokid().get_streampos());
			of << ");\n";
		}

		int start = 0, ord = 0;
		for (dequeTpart::const_iterator j = fun->get_token().get_parts_begin(); j != fun->get_token().get_parts_end(); j++) {
			Tokid t2 = j->get_tokid();
			int len = j->get_len() - start;
			int pos = 0;
			while (pos < len) {
				Eclass *ec = t2.get_ec();
				of << "INSERT INTO FUNCTIONID VALUES(" <<
				ptr_offset(fun) << ',' <<
				ord << ',' <<
				ptr_offset(ec) << ");\n";
				pos += ec->get_len();
				t2 += ec->get_len();
				ord++;
			}
			start += j->get_len();
		}
	}

	// Then their calls to satisfy integrity constraints
	for (const_fmap_iterator_type i = fbegin(); i != fend(); i++) {
		Call *fun = i->second;
		for (Call::const_fiterator_type dest = fun->call_begin(); dest != fun->call_end(); dest++)
			of << "INSERT INTO FCALLS VALUES(" <<
			    ptr_offset(fun) << ',' <<
			    ptr_offset(*dest) << ");\n";
	}
}
コード例 #3
0
ファイル: KISS.cpp プロジェクト: CInsights/AX25
size_t KISS::writePacket(Packet *p) {
  fend();
  unsigned int i;
  write((uint8_t)0x0);
  for(i = 0; i < p->len; ++i) {
	unsigned char c = p->getByte();
    if(c == HDLC_ESCAPE)
      write((uint8_t)p->getByte());
    else
      write((uint8_t)c);
  }
  fend();
  return i;
}
コード例 #4
0
 types::ndarray<typename __combined<typename types::dtype_of<T>::type,
                                    typename types::dtype_of<U>::type>::type,
                types::pshape<long>>
 setdiff1d(T const &ar1, U const &ar2, bool assume_unique)
 {
   using dtype = typename __combined<typename types::dtype_of<T>::type,
                                     typename types::dtype_of<U>::type>::type;
   auto far1 = numpy::functor::array{}(ar1);
   auto far2 = numpy::functor::array{}(ar2);
   if (assume_unique) {
     std::sort(far1.fbegin(), far1.fend());
     std::sort(far2.fbegin(), far2.fend());
     dtype *out =
         (dtype *)malloc(far1.flat_size() * far2.flat_size() * sizeof(dtype));
     dtype *out_last = std::set_difference(far1.fbegin(), far1.fend(),
                                           far2.fbegin(), far2.fend(), out);
     auto size = out_last - out;
     out = (dtype *)realloc(out, size * sizeof(dtype));
     return {out, types::pshape<long>(size), types::ownership::owned};
   } else {
     std::sort(far1.fbegin(), far1.fend());
     std::sort(far2.fbegin(), far2.fend());
     dtype *out =
         (dtype *)malloc(far1.flat_size() * far2.flat_size() * sizeof(dtype));
     dtype *out_last = impl::set_difference_unique(
         far1.fbegin(), far1.fend(), far2.fbegin(), far2.fend(), out);
     auto size = out_last - out;
     out = (dtype *)realloc(out, size * sizeof(dtype));
     return {out, types::pshape<long>(size), types::ownership::owned};
   }
 }
コード例 #5
0
ファイル: argmax.hpp プロジェクト: OnlySang/pythran
 long argmax(E&& expr) {
     auto arr = asarray(expr);
     long sz = arr.size();
     if(not sz) 
         throw types::ValueError("empty sequence");
     return std::max_element(arr.fbegin(), arr.fend()) - arr.fbegin();
 }
コード例 #6
0
ファイル: ft_strtrim.c プロジェクト: Toms88/libft
char			*ft_strtrim(char const *s)
{
	size_t	end;
	size_t	start;
	size_t	i;
	char	*ret;

	if (s)
	{
		i = 0;
		start = fstart(s);
		end = fend(s);
		if ((int)(end - start) >= 0)
			ret = (char *)malloc(sizeof(ret) * ((end - start) + 1));
		while ((s[start] != '\0') && (start <= end))
		{
			ret[i] = s[start];
			i++;
			start++;
		}
		ret[i] = '\0';
		if (ret == NULL)
			return (NULL);
		return (ret);
	}
	return (NULL);
}
コード例 #7
0
ファイル: array_equiv.hpp プロジェクト: OnlySang/pythran
 typename std::enable_if<types::has_shape<U>::value and types::has_shape<V>::value,bool>::type array_equiv(U const& u, V const&v) {
     if(u.shape == v.shape) {
         return array_equal(u,v);
     }
     else if(u.size() > v.size()) {
         return array_equiv(v,u);
     }
     else if(v.size()%u.size() ==0) {
         auto uu = asarray(u);
         auto vv = asarray(v);
         for(auto vi = vv.fbegin(), ve = vv.fend(); vi != ve;)
             for(auto ui = uu.fbegin(), ue = uu.fend(); ui != ue; ++ui, ++vi)
                 if(*ui != *vi)
                     return false;
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: ediff1d.hpp プロジェクト: OnlySang/pythran
 types::ndarray<typename types::numpy_expr_to_ndarray<E>::T, 1>
 ediff1d(E const& expr)
 {
     auto arr = asarray(expr);
     long n = arr.size() -1 ;
     types::ndarray<typename types::numpy_expr_to_ndarray<E>::T, 1> out(types::make_tuple(n), __builtin__::None);
     // Compute adjacent difference except for the first element
     std::adjacent_difference (arr.fbegin() + 1, arr.fend(), out.fbegin());
     // First element can be done now
     (*out.fbegin()) = *(arr.fbegin()+1) - *(arr.fbegin());
     return out;
 }
コード例 #9
0
				//----------
				void Mesh2DFromGraycode::triangulate() {
					this->throwIfMissingAnyConnection();

					auto dataSet = this->getInput<Scan::Graycode>()->getDataSet();
					if (!dataSet.getHasData()) {
						throw(Exception("No scan data available"));
					}

					//get camera coords in projector space map
					const auto & cameraInProjector = dataSet.getDataInverse();
					const auto & active = dataSet.getActive();

					const auto projectorWidth = cameraInProjector.getWidth();
					const auto projectorHeight = cameraInProjector.getHeight();

					const auto cameraWidth = active.getWidth();

					auto getCameraPixelPosition = [&cameraInProjector, projectorWidth, cameraWidth](int i, int j) {
						const auto cameraPixelIndex = cameraInProjector.getData()[i + j * projectorWidth];
						return ofVec2f(cameraPixelIndex % cameraWidth, cameraPixelIndex / cameraWidth);
					};
					auto isActive = [& cameraInProjector, &active, projectorWidth](int i, int j) {
						const auto cameraPixelIndex = cameraInProjector.getData()[i + j * projectorWidth];
						const auto isActive = active.getData()[cameraPixelIndex];
						return isActive;
					};

					vector<ofPoint> projectorSpaceActivePoints;

					//find all active pixels
					for (int j = 0; j < projectorHeight; j++) {
						for (int i = 0; i < projectorWidth; i++) {
							if (isActive(i, j)) {
								projectorSpaceActivePoints.emplace_back(ofVec2f(i, j));
							}
						}
					}

					//triangulate
					ofMesh mesh;
					{
						//make vertices and tex coords
						Delaunay::Point tempP;
						vector<Delaunay::Point> delauneyPoints;
						for (const auto & projectorSpaceActivePoint : projectorSpaceActivePoints) {
							delauneyPoints.emplace_back(projectorSpaceActivePoint.x, projectorSpaceActivePoint.y);
							mesh.addVertex(projectorSpaceActivePoint);
							mesh.addTexCoord(getCameraPixelPosition(projectorSpaceActivePoint.x, projectorSpaceActivePoint.y));
						}

						//triangulate
						auto delauney = make_shared<Delaunay>(delauneyPoints);
						delauney->Triangulate();

						//apply indices
						for (auto it = delauney->fbegin(); it != delauney->fend(); ++it) {
							mesh.addIndex(delauney->Org(it));
							mesh.addIndex(delauney->Dest(it));
							mesh.addIndex(delauney->Apex(it));
						}
					}
					swap(this->getInput<Data::Mesh>()->getMesh(), mesh);
				}
コード例 #10
0
ViewVertex *ViewMap::InsertViewVertex(SVertex *iVertex, vector<ViewEdge*>& newViewEdges)
{
	NonTVertex *vva = dynamic_cast<NonTVertex*>(iVertex->viewvertex());
	if (vva)
		return vva;
	// because it is not already a ViewVertex, this SVertex must have only 2 FEdges. The incoming one still belongs
	// to ioEdge, the outgoing one now belongs to newVEdge
	const vector<FEdge *>& fedges = iVertex->fedges();
	if (fedges.size() != 2) {
		cerr << "ViewMap warning: Can't split the ViewEdge" << endl;
		return NULL;
	}
	FEdge *fend(NULL), *fbegin(NULL);
	for (vector<FEdge *>::const_iterator fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) {
		if ((*fe)->vertexB() == iVertex) {
			fend = (*fe);
		}
		if ((*fe)->vertexA() == iVertex) {
			fbegin = (*fe);
		}
		if ((fbegin != NULL) && (fend != NULL))
			break;
	}
	ViewEdge *ioEdge = fbegin->viewedge();
	ViewShape *vshape = ioEdge->viewShape();
	vva = new NonTVertex(iVertex);
	// if the ViewEdge is a closed loop, we don't create a new VEdge
	if (ioEdge->A() == 0) {
		// closed loop
		ioEdge->setA(vva);
		ioEdge->setB(vva);
		// update sshape
		vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeA());
		vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeB());

		ioEdge->setFEdgeA(fbegin);
		ioEdge->setFEdgeB(fend);

		// Update FEdges
		fend->setNextEdge(NULL);
		fbegin->setPreviousEdge(NULL);

		// update new View Vertex:
		vva->AddOutgoingViewEdge(ioEdge);
		vva->AddIncomingViewEdge(ioEdge);

		vshape->sshape()->AddChain(ioEdge->fedgeA());
		vshape->sshape()->AddChain(ioEdge->fedgeB());
	}
	else {
		// Create new ViewEdge
		ViewEdge *newVEdge = new ViewEdge(vva, ioEdge->B(), fbegin, ioEdge->fedgeB(), vshape);
		newVEdge->setId(Id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1));
		newVEdge->setNature(ioEdge->getNature());
		//newVEdge->UpdateFEdges(); // done in the ViewEdge constructor
		// Update old ViewEdge
		ioEdge->setB(vva);
		ioEdge->setFEdgeB(fend);

		// Update FEdges
		fend->setNextEdge(NULL);
		fbegin->setPreviousEdge(NULL);

		// update new View Vertex:
		vva->AddOutgoingViewEdge(newVEdge);
		vva->AddIncomingViewEdge(ioEdge);

		NonTVertex *vvb = dynamic_cast<NonTVertex*>(newVEdge->B());
		if (vvb)
			vvb->Replace(ioEdge, newVEdge);

		// update ViewShape
		//vshape->AddEdge(newVEdge);
		// update SShape
		vshape->sshape()->AddChain(fbegin);
		// update ViewMap
		//_VEdges.push_back(newVEdge);
		newViewEdges.push_back(newVEdge);
	}

	// update ViewShape
	vshape->AddVertex(vva);

	// update ViewMap
	_VVertices.push_back(vva);

	return vva;
}
コード例 #11
0
ファイル: pathfinder.cpp プロジェクト: astrellon/GPP
	bool Pathfinder::search(const Vector2i &start, Vector2i end, NodePath &path, Map *map, const GameObject *forObj)
	{
		if (!map || 
			start.x < 0 || start.x >= map->getMapWidth() ||
			start.y < 0 || start.y >= map->getMapHeight() ||
			end.x < 0 || end.x >= map->getMapWidth() ||
			end.y < 0 || end.y >= map->getMapHeight() ||
			(start.x == end.x && start.y == end.y))
		{
			return false;
		}

		mMap = map;
		int startGroup = map->mMapData[start.x][start.y].group;
		int endGroup = map->mMapData[end.x][end.y].group;
		if(startGroup != endGroup)
		{
			mMap = NULL;
			return false;
		}

		if (!map->isValidGridLocation(end.x, end.y, forObj))
		{
			// Move back towards the start position until we do find a passable location.
			Engine *engine = Engine::getEngine();
			Vector2f fstart(start);
			Vector2f fend(end);
			Vector2f toStart(fend.sub(fstart));
			int numSteps = static_cast<int>(toStart.length() * 2.0f);
			toStart.normalise();
			toStart.scale(0.5f);

			for (int step = 0; step < numSteps; step++)
			{
				fend = fend.sub(toStart);
				Vector2i grid(fend);
				if (map->isValidGridLocation(grid.x, grid.y, forObj))
				{
					break;
				}
			}

			end.x = round(fend.x);
			end.y = round(fend.y);

			endGroup = map->mMapData[end.x][end.y].group;
			if(startGroup != endGroup)
			{
				mMap = NULL;
				return false;
			}
		}

		mOpenList.clear();
		mClosedList.clear();

		mNodeUseCounter++;

		mOpenList.push_back(&map->mMapData[start.x][start.y]);

		AStarNode *endNode = &map->mMapData[end.x][end.y];
		endNode->parent = NULL;

		while(!mOpenList.empty())
		{
			AStarNode *node = mOpenList.front();
			if(node->useCounter < mNodeUseCounter)
			{
				node->g = 0;
				node->useCounter = mNodeUseCounter;
				node->parent = NULL;
			}
		
			if (node == endNode)
			{
				// Complete
				getPath(node, path);
				mMap = NULL;
				return true;
			}
			else
			{
				mOpenList.erase(mOpenList.begin());
				mClosedList.push_back(node);

				mNeighbors.clear();
				getNeighbors(node->gridPosition, forObj);
				for(auto iter = mNeighbors.begin(); iter != mNeighbors.end(); ++iter)
				{
					AStarNode *n = *iter;
					if (!Utils::listContains(mOpenList, n) &&
						!Utils::listContains(mClosedList, n))
					{
						if (n->useCounter < mNodeUseCounter)
						{
							n->g = 0;
							n->useCounter = mNodeUseCounter;
						}
						n->g += node->g;

						n->f = n->g + manhattanDistance(n->position, endNode->position);

						n->parent = node;
						mOpenList.push_back(n);
					}
				}

				mNeighbors.clear();
				sortAStarList(mOpenList);
			}
		}
		// NO PATH! D:
		mMap = NULL;
		return false;
	}
コード例 #12
0
ファイル: array.hpp プロジェクト: codealphago/instant
 inline float* fend(array& a) {
     return const_cast<float*>(fend(const_cast<array const&>(a)));
 }
コード例 #13
0
TrianglesList meshSimplification(TrianglesList &triangles, int stopPredicate) {

	#ifdef MESHSIMPLIFICATION_LOG
	CGAL::Timer timer;
	timer.start();
	#endif

	TrianglesList result;

	try
	{
		Polyhedron P;

		#ifdef MESHSIMPLIFICATION_LOG
		std::cout << "Start Building Polyhedron surface... " << std::endl;
		#endif

		Build_triangle_mesh_coherent_surface<HalfedgeDS> triangle(triangles);
		P.delegate(triangle);
		P.normalize_border();

		#ifdef MESHSIMPLIFICATION_LOG
		std::cout << "Completed Building Polyhedron surface:" << std::endl;
		std::cout << "Polyhedron is_pure_triangle: " << P.is_pure_triangle() << std::endl;
		std::cout << "Polyhedron is_closed: " << P.is_closed() << std::endl;
		std::cout << "Polyhedron is_pure_bivalent : " << P.is_pure_bivalent () << std::endl;
		std::cout << "Polyhedron is_pure_trivalent: " << P.is_pure_trivalent() << std::endl;
		std::cout << "Polyhedron is_valid 0: " << P.is_valid(false, 0) << std::endl;
		std::cout << "Polyhedron is_valid 1: " << P.is_valid(false, 1) << std::endl;
		std::cout << "Polyhedron is_valid 2: " << P.is_valid(false, 2) << std::endl;
		std::cout << "Polyhedron is_valid 3: " << P.is_valid(false, 3) << std::endl;
		std::cout << "Polyhedron is_valid 4: " << P.is_valid(false, 4) << std::endl;
		std::cout << "Polyhedron normalized_border_is_valid : " << P.normalized_border_is_valid(false) << std::endl;
		#endif

		#ifdef MESHSIMPLIFICATION_LOG
		std::cout << "Start edge_collapse... " << std::endl;
		#endif

		SMS::Count_stop_predicate<Polyhedron> stop(stopPredicate);

		int removedEdges = SMS::edge_collapse(P, stop,
				CGAL::vertex_index_map(boost::get(CGAL::vertex_external_index, P)).edge_index_map(boost::get(CGAL::edge_external_index ,P))
		);

		#ifdef MESHSIMPLIFICATION_LOG
		std::cout << "Completed edge_collapse:" << std::endl;
		std::cout << "Finished with: " << removedEdges << " edges removed and "  << (P.size_of_halfedges()/2) << " final edges." << std::endl;
		#endif

		//Build output result
		for ( Polyhedron::Facet_iterator fit( P.facets_begin() ), fend( P.facets_end() ); fit != fend; ++fit )
		{
			if ( fit->is_triangle() )
			{
				PointCGAL verts[3];
				int tick = 0;

				Polyhedron::Halfedge_around_facet_circulator hit( fit->facet_begin() ), hend( hit );
				do
				{
					if ( tick < 3 )
					{
						verts[tick++] = PointCGAL( hit->vertex()->point().x(), hit->vertex()->point().y(), hit->vertex()->point().z() );
					}
					else
					{
						std::cout << "meshSimplification: We've got facets with more than 3 vertices even though the facet reported to be triangular..." << std::endl;
					}

				} while( ++hit != hend );

				result.push_back( Triangle(verts[0], verts[1], verts[2]) );
			}
			else
			{
				std::cout << "meshSimplification: Skipping non-triangular facet" << std::endl;
			}

		}

	}
	catch (CGAL::Assertion_exception e)
	{
		std::cout << "ERROR: meshSimplification CGAL::Assertion_exception" << e.message() << std::endl;
	}

	#ifdef MESHSIMPLIFICATION_LOG
	timer.stop();
	std::cout << "meshSimplification result with: " << result.size() << " triangles." << std::endl;
	std::cout << "Total meshSimplification time: " << timer.time() << std::endl;
	#endif

	return result;
}
コード例 #14
0
ファイル: model.hpp プロジェクト: codealphago/instant
    inline auto make_parameter_memory_table(
      onnx::GraphProto const& graph,
      std::unordered_map<std::string, instant::array> const& parameter_table,
      mkldnn::engine const& engine) {
        std::unordered_map<std::string, const mkldnn::memory> memory_table;
        std::vector<array> temp_array_list;
        for(auto const& node : graph.node()) {
            if(node.op_type() == "Conv") {
                constexpr auto weight_index = 1;
                memory_table.insert(make_parameter_memory_pair(
                  node, weight_index, mkldnn::memory::format::oihw,
                  parameter_table, engine));

                if(node.input_size() != 2) {
                    constexpr auto bias_index = 2;
                    memory_table.insert(make_parameter_memory_pair(
                      node, bias_index, mkldnn::memory::format::x,
                      parameter_table, engine));
                }
            } else if(node.op_type() == "FC") {
                constexpr auto weight_index = 1;
                constexpr auto bias_index = 2;
                memory_table.insert(make_parameter_memory_pair(
                  node, weight_index,
                  mkldnn::memory::format::oi, // MEMO: is it correct? result is
                                              // correct...
                  parameter_table, engine));
                memory_table.insert(make_parameter_memory_pair(
                  node, bias_index, mkldnn::memory::format::x, parameter_table,
                  engine));
            } else if(node.op_type() == "BatchNormalization") {
                constexpr auto scale_index = 1;
                constexpr auto b_index = 2;
                constexpr auto mean_index = 3;
                constexpr auto var_index = 4;

                auto const& scale_name = node.input(scale_index);
                auto const& scale_arr = find_value(parameter_table, scale_name);
                auto const& b_name = node.input(b_index);
                auto const& b_arr = find_value(parameter_table, b_name);
                mkldnn::memory::dims scale_dims(scale_arr.dims().begin(),
                                                scale_arr.dims().end());
                std::vector<int> weights_dims{{2}};
                weights_dims.insert(weights_dims.end(), scale_dims.begin(),
                                    scale_dims.end());
                array weights_arr(dtype_t::float_, weights_dims);
                std::copy(fbegin(scale_arr), fend(scale_arr),
                          fbegin(weights_arr));
                std::copy(fbegin(b_arr), fend(b_arr),
                          fbegin(weights_arr) + calc_total_size(scale_dims));
                temp_array_list.push_back(weights_arr);
                auto weights_mem =
                  mkldnn::memory({{{weights_dims},
                                   mkldnn::memory::data_type::f32,
                                   mkldnn::memory::format::nc},
                                  engine},
                                 weights_arr.data());
                memory_table.insert({scale_name, weights_mem});

                /*
                memory_table.insert(make_parameter_memory_pair(
                  node, scale_index, mkldnn::memory::format::x, parameter_table,
                  engine));
                memory_table.insert(make_parameter_memory_pair(
                  node, b_index, mkldnn::memory::format::x, parameter_table,
                  engine));
                */
                memory_table.insert(make_parameter_memory_pair(
                  node, mean_index, mkldnn::memory::format::x, parameter_table,
                  engine));
                memory_table.insert(make_parameter_memory_pair(
                  node, var_index, mkldnn::memory::format::x, parameter_table,
                  engine));
            } else {
                // TODO
                /*
                throw std::runtime_error("Not implemented yet: " +
                                         node.op_type());
                */
            }
        }
        return std::make_tuple(memory_table, temp_array_list);
    } // namespace instant