/* Return a subfield, gen_0 [ change p ] or NULL [ not a subfield ] */ static GEN subfield(GEN A, blockdata *B) { long N, i, j, d, lf, m = lg(A)-1; GEN M, pe, pol, fhk, g, e, d_1_term, delta, listdelta, whichdelta; GEN T = B->S->T, p = B->S->p, firstroot = B->S->firstroot; pol= (GEN)B->DATA[1]; N = degpol(pol); d = N/m; /* m | N */ pe = (GEN)B->DATA[2]; fhk= (GEN)B->DATA[3]; M = (GEN)B->DATA[8]; delta = cgetg(m+1,t_VEC); whichdelta = cgetg(N+1, t_VECSMALL); d_1_term = gen_0; for (i=1; i<=m; i++) { GEN Ai = gel(A,i), p1 = (GEN)fhk[Ai[1]]; for (j=2; j<=d; j++) p1 = Fq_mul(p1, (GEN)fhk[Ai[j]], T, pe); gel(delta,i) = p1; if (DEBUGLEVEL>2) fprintferr("delta[%ld] = %Z\n",i,p1); /* g = prod (X - delta[i]) * if g o h = 0 (pol), we'll have h(Ai[j]) = delta[i] for all j */ /* fk[k] belongs to block number whichdelta[k] */ for (j=1; j<=d; j++) whichdelta[Ai[j]] = i; if (typ(p1) == t_POL) p1 = constant_term(p1); d_1_term = addii(d_1_term, p1); } d_1_term = centermod(d_1_term, pe); /* Tr(g) */ if (absi_cmp(d_1_term, gel(M,3)) > 0) { if (DEBUGLEVEL>1) fprintferr("d-1 test failed\n"); return NULL; } g = FqV_roots_to_pol(delta, T, pe, 0); g = centermod(polsimplify(g), pe); /* assume g in Z[X] */ if (DEBUGLEVEL>2) fprintferr("pol. found = %Z\n",g); if (!ok_coeffs(g,M)) { if (DEBUGLEVEL>1) fprintferr("coeff too big for pol g(x)\n"); return NULL; } if (!FpX_is_squarefree(g, p)) { if (DEBUGLEVEL>1) fprintferr("changing f(x): p divides disc(g)\n"); compute_data(B); return subfield(A, B); } lf = lg(firstroot); listdelta = cgetg(lf, t_VEC); for (i=1; i<lf; i++) listdelta[i] = delta[whichdelta[firstroot[i]]]; if (DEBUGLEVEL) fprintferr("candidate = %Z\n", g); e = embedding(g, B->DATA, B->S, B->PD->den, listdelta); if (!e) return NULL; if (DEBUGLEVEL) fprintferr("embedding = %Z\n", e); return _subfield(g, e); }
DenseMatrix triangulate(RandomAccessIterator begin, RandomAccessIterator end, PairwiseCallback distance_callback, Landmarks& landmarks, DenseVector& landmark_distances_squared, EigendecompositionResult& landmarks_embedding, IndexType target_dimension) { timed_context context("Landmark triangulation"); const IndexType n_vectors = end-begin; const IndexType n_landmarks = landmarks.size(); bool* to_process = new bool[n_vectors]; std::fill(to_process,to_process+n_vectors,true); DenseMatrix embedding(n_vectors,target_dimension); for (IndexType index_iter=0; index_iter<n_landmarks; ++index_iter) { to_process[landmarks[index_iter]] = false; embedding.row(landmarks[index_iter]).noalias() = landmarks_embedding.first.row(index_iter); } for (IndexType i=0; i<target_dimension; ++i) landmarks_embedding.first.col(i).array() /= landmarks_embedding.second(i); #pragma omp parallel shared(begin,end,to_process,distance_callback,landmarks, \ landmarks_embedding,landmark_distances_squared,embedding) default(none) { DenseVector distances_to_landmarks(n_landmarks); IndexType index_iter; #pragma omp for nowait for (index_iter=0; index_iter<n_vectors; ++index_iter) { if (!to_process[index_iter]) continue; for (IndexType i=0; i<n_landmarks; ++i) { ScalarType d = distance_callback.distance(begin[index_iter],begin[landmarks[i]]); distances_to_landmarks(i) = d*d; } //distances_to_landmarks.array().square(); distances_to_landmarks -= landmark_distances_squared; embedding.row(index_iter).noalias() = -0.5*landmarks_embedding.first.transpose()*distances_to_landmarks; } } delete[] to_process; return embedding; }
void MonolingualModel::sentVec(istream& input, int policy) { string line; while(getline(input, line)) { vec embedding(config.dimension, 0); try { embedding = sentVec(line, policy); } catch (runtime_error) { // in case of error (empty sentence, or all words are OOV), print a vector of zeros }; for (int c = 0; c < config.dimension; ++c) { cout << embedding[c] << " "; } } }
void CPlanarGraph::DetectFaces() { // Based on the example in (http://www.boost.org/doc/libs/1_47_0/libs/graph/example/planar_face_traversal.cpp) int numOfNodes = GetNumOfNodes(); Graph g(numOfNodes); int numOfEdges = GetNumOfEdges(); for ( int i=0; i<numOfEdges; i++ ) { int idx0 = GetEdge(i).GetIdx0(); int idx1 = GetEdge(i).GetIdx1(); add_edge(idx0, idx1, g); } // Initialize the interior edge index property_map<Graph, edge_index_t>::type e_index = get(edge_index, g); graph_traits<Graph>::edges_size_type edge_count = 0; graph_traits<Graph>::edge_iterator ei, ei_end; for ( boost::tuples::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei ) { put(e_index, *ei, edge_count++); } typedef std::vector< graph_traits<Graph>::edge_descriptor > vec_t; std::vector<vec_t> embedding(num_vertices(g)); #if 0 // Test for planarity - we know it is planar, we just want to // compute the planar embedding as a side-effect if ( boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g, boyer_myrvold_params::embedding = &embedding[0] ) ) { std::cout << "Input graph is planar" << std::endl; } else { std::cout << "Input graph is not planar" << std::endl; } #else // Compute the planar embedding based on node positions... VertexIterator vi, vi_end; for ( boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; ++vi ) { OutEdgeIterator ei, ei_end; std::vector<EdgeDescriptor> adjacentEdges; for ( boost::tie(ei, ei_end) = boost::out_edges(*vi, g); ei != ei_end; ++ei ) { VertexDescriptor v1 = boost::source(*ei, g); VertexDescriptor v2 = boost::target(*ei, g); adjacentEdges.push_back(*ei); } SortAdjacentVertices(g, *vi, adjacentEdges); for(int i = 0; i < adjacentEdges.size(); ++i) { std::cout << *vi << " -> " << adjacentEdges[i] << std::endl; } if(adjacentEdges.size()>0) std::cout << std::endl; embedding[*vi] = adjacentEdges; } #endif std::cout << std::endl << "Vertices on the faces: " << std::endl; vertex_output_visitor v_vis; planar_face_traversal(g, &embedding[0], v_vis); std::cout << std::endl << "Edges on the faces: " << std::endl; edge_output_visitor e_vis; planar_face_traversal(g, &embedding[0], e_vis); RemoveTheOutsideFace(); }
STDMETHODIMP CExRichEditWindowless::GetClipboardData(CHARRANGE FAR *lpchrg, DWORD reco, LPDATAOBJECT FAR *lplpdataobj) { switch(reco) { case RECO_COPY: { HRESULT hr = E_NOTIMPL; FORMATETC formatEtc; STGMEDIUM stgMedium; CDataObject *pDataObject = new CDataObject(NULL); CString text = GetTextRange(lpchrg->cpMin,lpchrg->cpMax); CString embedding(WCH_EMBEDDING); text.Replace(embedding,_T("<objtct/>")); if(!text.IsEmpty()) { UINT uFormat = m_uOwnOleClipboardFormat; if (0 != uFormat) { HGLOBAL hMemBlock = ::GlobalAlloc(GMEM_MOVEABLE, (text.GetLength() + 1) * sizeof(TCHAR)); if (NULL != hMemBlock) { LPTSTR pDest = LPTSTR(::GlobalLock(hMemBlock)); _tcscpy(pDest, LPCTSTR(text)); ::GlobalUnlock(hMemBlock); SecureZeroMemory(&formatEtc, sizeof(FORMATETC)); formatEtc.cfFormat = uFormat; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.ptd = NULL; formatEtc.tymed = TYMED_HGLOBAL; SecureZeroMemory(&stgMedium, sizeof(STGMEDIUM)); stgMedium.tymed = TYMED_HGLOBAL; stgMedium.hGlobal = hMemBlock; hr = pDataObject->SetData(&formatEtc, &stgMedium, TRUE); if (FAILED(hr)) { ::GlobalFree(hMemBlock); hr &= E_FAIL; } } else { hr &= E_OUTOFMEMORY; } } else { hr &= E_FAIL; } } else { return E_UNEXPECTED; } if (SUCCEEDED(hr)) { (*lplpdataobj) = pDataObject; (*lplpdataobj)->AddRef(); } return hr; } case RECO_CUT: case RECO_DRAG: case RECO_DROP: case RECO_PASTE: default: return E_NOTIMPL; } }
/** * Generate blocks from the road network */ bool VBOPmBlocks::generateBlocks(VBORenderManager* renderManager, RoadGraph &roadGraph, BlockSet &blocks) { GraphUtil::normalizeLoop(roadGraph); roadGraphPtr = &roadGraph; blocksPtr = &blocks.blocks; blocksPtr->clear(); bool isPlanar = false; bool converges = true; //GraphUtil::planarify(roadGraph); //GraphUtil::clean(roadGraph); //Make sure graph is planar typedef std::vector< RoadEdgeDesc > tEdgeDescriptorVector; std::vector<tEdgeDescriptorVector> embedding(boost::num_vertices(roadGraph.graph)); int cont=0; removeIntersectingEdges(roadGraph); /* // Test for planarity while (cont<2) { if (boost::boyer_myrvold_planarity_test(boost::boyer_myrvold_params::graph =roadGraph.graph, boost::boyer_myrvold_params::embedding = &embedding[0]) ){ isPlanar = true; break; } else { std::cout << "Input graph is not planar trying removeIntersectingEdges" << std::endl; // No planar: Remove intersecting edges and check again removeIntersectingEdges(roadGraph); cont++; } } if (!isPlanar) { std::cout << "ERROR: Graph could not be planarized: (generateBlocks)\n"; return false; } */ // build embedding manually //embedding.clear(); //embedding.resize(boost::num_vertices(roadGraph.graph)); buildEmbedding(roadGraph, embedding); printf("embedding was built.\n"); //Create edge index property map? typedef std::map<RoadEdgeDesc, size_t> EdgeIndexMap; EdgeIndexMap mapEdgeIdx; boost::associative_property_map<EdgeIndexMap> pmEdgeIndex(mapEdgeIdx); RoadEdgeIter ei, ei_end; int edge_count = 0; for (boost::tie(ei, ei_end) = boost::edges(roadGraph.graph); ei != ei_end; ++ei) { mapEdgeIdx.insert(std::make_pair(*ei, edge_count++)); } //Extract blocks from road graph using boost graph planar_face_traversal vertex_output_visitor v_vis; boost::planar_face_traversal(roadGraph.graph, &embedding[0], v_vis, pmEdgeIndex); printf("roads graph was traversed. %d blocks were extracted.\n", blocks.size()); //Misc postprocessing operations on blocks ======= int maxVtxCount = 0; int maxVtxCountIdx = -1; std::vector<float> blockAreas; Loop3D sidewalkContourInset; for (int i = 0; i < blocks.size(); ++i) { //Reorient faces if (Polygon3D::reorientFace(blocks[i].sidewalkContour.contour)) { std::reverse(blocks[i].sidewalkContourRoadsWidths.begin(), blocks[i].sidewalkContourRoadsWidths.end() - 1); } if( blocks[i].sidewalkContour.contour.size() != blocks[i].sidewalkContourRoadsWidths.size() ){ std::cout << "Error: contour" << blocks[i].sidewalkContour.contour.size() << " widhts " << blocks[i].sidewalkContourRoadsWidths.size() << "\n"; blocks[i].sidewalkContour.clear(); blocks[i].valid = false; blockAreas.push_back(0.0f); continue; } if(blocks[i].sidewalkContour.contour.size() < 3){ std::cout << "Error: Contour <3 " << "\n"; blocks[i].valid = false; blockAreas.push_back(0.0f); continue; } //Compute block offset float insetArea = blocks[i].sidewalkContour.computeInset(blocks[i].sidewalkContourRoadsWidths,sidewalkContourInset); blocks[i].sidewalkContour.contour = sidewalkContourInset; //blocks[i].sidewalkContour.getBBox3D(blocks[i].bbox.minPt, blocks[i].bbox.maxPt); blockAreas.push_back(insetArea); } // Remove the largest block float maxArea = -FLT_MAX; int maxAreaIdx = -1; for (int i = 0; i < blocks.size(); ++i) { if (blocks[i].sidewalkContour.contour.size() < 3) { continue; } if (blockAreas[i] > maxArea) { maxArea = blockAreas[i]; maxAreaIdx = i; } } if (maxAreaIdx != -1) { blocks[maxAreaIdx].valid = false; //blocks.blocks.erase(blocks.blocks.begin()+maxAreaIdx); } // GEN: remove the blocks whose edges are less than 3 // This problem is caused by the computeInset() function. // ToDo: fix the computeInset function. for (int i = 0; i < blocks.size(); ++i) { if (blocks[i].sidewalkContour.contour.size() < 3) { blocks[i].valid = false; //blocks.blocks.erase(blocks.blocks.begin() + i); } } // assign a zone to each block generateSideWalk(renderManager, blocks); return true; }