######## Partitioned Vertices ##########
196494
private PartitionVertexAggregate<M> getPartitioned(long vertexId) {
        assert idManager.isPartitionedVertex(vertexId);
        vertexId=getCanonicalId(vertexId);
        PartitionVertexAggregate<M> state = partitionVertices.get(vertexId);
        if (state==null) {
            partitionVertices.putIfAbsent(vertexId,new PartitionVertexAggregate<>(previousScopes));
            state = partitionVertices.get(vertexId);
        }
        return state;
    }
681136
private IAtomContainer toFragment(int[] vertices) {

        int n = vertices.length;

        Set<IAtom> atoms = new HashSet<IAtom>(n > 3 ? n + 1 + n / 3 : n);
        List<IBond> bonds = new ArrayList<IBond>();

        // fill the atom set
        for (int v : vertices) {
            atoms.add(container.getAtom(v));
        }

        // include bonds that have both atoms in the atoms set
        for (IBond bond : container.bonds()) {
            IAtom either = bond.getBegin();
            IAtom other = bond.getEnd();
            if (atoms.contains(either) && atoms.contains(other)) {
                bonds.add(bond);
            }
        }

        IAtomContainer fragment = container.getBuilder().newInstance(IAtomContainer.class, 0, 0, 0, 0);

        fragment.setAtoms(atoms.toArray(new IAtom[n]));
        fragment.setBonds(bonds.toArray(new IBond[bonds.size()]));

        return fragment;
    }
985288
def integer_partition(size: int, nparts: int) -> Iterator[List[List[int]]]:
    
    for part in algorithm_u(range(size), nparts):
        yield part
1241241
private int[] makeVertexDeltas(float[] vertices, SortableVertex[] sortVertices, Grid grid) {
        int vc = sortVertices.length;

        // Vertex scaling factor
        float scale = 1.0f / vertexPrecision;

        float prevGridIndex = 0x7fffffff;
        int prevDeltaX = 0;
        int[] intVertices = new int[vc * CTM_POSITION_ELEMENT_COUNT];
        for (int i = 0; i < vc; ++i) {
            // Get grid box origin
            int gridIdx = sortVertices[i].gridIndex;
            float[] gridOrigin = gridIdxToPoint(grid, gridIdx);

            // Get old vertex coordinate index (before vertex sorting)
            int oldIdx = sortVertices[i].originalIndex;

            // Store delta to the grid box origin in the integer vertex array. For the
            // X axis (which is sorted) we also do the delta to the previous coordinate
            // in the box.
            int deltaX = (int) floor(scale * (vertices[oldIdx * 3] - gridOrigin[0]) + 0.5f);
            if (gridIdx == prevGridIndex) {
                intVertices[i * 3] = deltaX - prevDeltaX;
            } else {
                intVertices[i * 3] = deltaX;
            }

            intVertices[i * 3 + 1] = (int) floor(scale * (vertices[oldIdx * 3 + 1] - gridOrigin[1]) + 0.5f);
            intVertices[i * 3 + 2] = (int) floor(scale * (vertices[oldIdx * 3 + 2] - gridOrigin[2]) + 0.5f);

            prevGridIndex = gridIdx;
            prevDeltaX = deltaX;
        }

        return intVertices;
    }
729868
def _dfs(vertex, vertices_neighbours):
    
    visited = set()
    to_visit = deque([vertex])
    while to_visit:
        vertex = to_visit.pop()
        if vertex not in visited:
            yield vertex
            visited.add(vertex)
            to_visit.extend(vertices_neighbours[vertex])
448741
def vertices
      verts = Array.new(8)
      length_ary = self.length
      verts[0] = @min_point.clone
      verts[1] = @min_point + Vector3.new(length_ary[0],             0,            0 )
      verts[2] = @min_point + Vector3.new(length_ary[0], length_ary[1],            0 )
      verts[3] = @min_point + Vector3.new(            0, length_ary[1],            0 )
      verts[4] = @min_point + Vector3.new(            0,             0, length_ary[2])
      verts[5] = @min_point + Vector3.new(length_ary[0],             0, length_ary[2])
      verts[6] = @min_point + Vector3.new(length_ary[0], length_ary[1], length_ary[2])
      verts[7] = @min_point + Vector3.new(            0, length_ary[1], length_ary[2])
      return verts
    end
895162
def finalise_same_chip_constraints(substitutions, placements):
    
    for merged_vertex in reversed(substitutions):
        placement = placements.pop(merged_vertex)
        for v in merged_vertex.vertices:
            placements[v] = placement
745059
def full_subgraph(self, vertices):
        
        subgraph_vertices = {v for v in vertices}
        subgraph_edges = {edge
                          for v in subgraph_vertices
                          for edge in self._out_edges[v]
                          if self._heads[edge] in subgraph_vertices}
        subgraph_heads = {edge: self._heads[edge]
                          for edge in subgraph_edges}
        subgraph_tails = {edge: self._tails[edge]
                          for edge in subgraph_edges}
        return DirectedGraph._raw(
            vertices=subgraph_vertices,
            edges=subgraph_edges,
            heads=subgraph_heads,
            tails=subgraph_tails,
        )
1013102
def _ConstructPartitions(self, collection_links, partitions_per_node):
        
        collections_node_count = len(collection_links)
        partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]

        index = 0
        for collection_node in collection_links:
            hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node))
            for _ in xrange(0, partitions_per_node):
                partitions[index] = partition._Partition(hash_value, collection_node)
                index += 1
                hash_value = self.hash_generator.ComputeHash(hash_value)

        partitions.sort()
        return partitions
467097
def remove_vertices(*vertices)
      vertices = to_vertices(*vertices).sort{|v1,v2| v2<=>v1}
      vertices.each do |vertex|
        remove_edges(vertex.in_edges+vertex.out_edges)
        @vertices.delete_at(vertex.index)
        vertex.index=-1
      end
      @vertices.each_with_index {|v,i| v.index=i}
      self
    end
1197449
function subdivide( face, detail ) {

		var cols = Math.pow( 2, detail );
		var a = prepare( that.vertices[ face.a ] );
		var b = prepare( that.vertices[ face.b ] );
		var c = prepare( that.vertices[ face.c ] );
		var v = [];

		// Construct all of the vertices for this subdivision.

		for ( var i = 0 ; i <= cols; i ++ ) {

			v[ i ] = [];

			var aj = prepare( a.clone().lerp( c, i / cols ) );
			var bj = prepare( b.clone().lerp( c, i / cols ) );
			var rows = cols - i;

			for ( var j = 0; j <= rows; j ++ ) {

				if ( j === 0 && i === cols ) {

					v[ i ][ j ] = aj;

				} else {

					v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );

				}

			}

		}

		// Construct all of the faces.

		for ( var i = 0; i < cols ; i ++ ) {

			for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {

				var k = Math.floor( j / 2 );

				if ( j % 2 === 0 ) {

					make(
						v[ i ][ k + 1 ],
						v[ i + 1 ][ k ],
						v[ i ][ k ]
					);

				} else {

					make(
						v[ i ][ k + 1 ],
						v[ i + 1 ][ k + 1 ],
						v[ i + 1 ][ k ]
					);

				}

			}

		}

	}
609344
function connectedComponents_sparse(cells) {
  var vertices  = unique(normalize(skeleton(cells, 0)))
    , labels    = new UnionFind(vertices.length)
  for(var i=0; i<cells.length; ++i) {
    var c = cells[i]
    for(var j=0; j<c.length; ++j) {
      var vj = findCell(vertices, [c[j]])
      for(var k=j+1; k<c.length; ++k) {
        labels.link(vj, findCell(vertices, [c[k]]))
      }
    }
  }
  var components        = []
    , component_labels  = labels.ranks
  for(var i=0; i<component_labels.length; ++i) {
    component_labels[i] = -1
  }
  for(var i=0; i<cells.length; ++i) {
    var l = labels.find(findCell(vertices, [cells[i][0]]));
    if(component_labels[l] < 0) {
      component_labels[l] = components.length
      components.push([cells[i].slice(0)])
    } else {
      components[component_labels[l]].push(cells[i].slice(0))
    }
  }
  return components
}
1006331
def merge_vertices(self):
        
        # run unique rows
        unique, inverse = grouping.unique_rows(self.vertices)

        # apply unique mask to vertices
        self.vertices = self.vertices[unique]

        # apply unique mask to colors
        if (self.colors is not None and
                len(self.colors) == len(inverse)):
            self.colors = self.colors[unique]
169318
def merge_vertices(self):
        """"""

        # groupby expects sorted data
        sorted_vertices = sorted(list(self.vertices.items()), key=lambda v: hash(v[1]))
        groups = []
        for k, g in groupby(sorted_vertices, lambda v: hash(v[1])):
            groups.append(list(g))
        for group in groups:
            if len(group) == 1:
                continue
            names = [v[0] for v in group]
            self.reduce_vertex(*names)
1097517
def subdivide(face, detail)
      cols = 2.0 ** detail
      a = prepare(@vertices[face.a])
      b = prepare(@vertices[face.b])
      c = prepare(@vertices[face.c])
      v = []

      # Construct all of the vertices for this subdivision.
      for i in 0..cols do
        v[i] = []

        aj = prepare(a.clone.lerp(c, i.to_f / cols.to_f))
        bj = prepare(b.clone.lerp(c, i.to_f / cols.to_f))
        rows = cols - i

        for j in 0..rows do
          v[i][j] = if j.zero? && i == cols
                      aj
                    else
                      prepare(aj.clone.lerp(bj, j.to_f / rows.to_f))
                    end
        end
      end

      # Construct all of the faces
      for i in 0...cols do
        for j in (0...(2 * (cols - i) - 1)) do
          k = j/2

          if j.even?
            make(
              v[i][k + 1],
              v[i + 1][k],
              v[i][k]
            )
          else
            make(
              v[i][k + 1],
              v[i + 1][k + 1],
              v[i + 1][k]
            )
          end
        end
      end
    end
703097
function flatten(data) {
        var dim = data[0][0].length, result = { vertices: new Array(), holes: new Array(), dimensions: dim }, holeIndex = 0;
        for (var i = 0; i < data.length; i++) {
            for (var j = 0; j < data[i].length; j++) {
                for (var d = 0; d < dim; d++)
                    result.vertices.push(data[i][j][d]);
            }
            if (i > 0) {
                holeIndex += data[i - 1].length;
                result.holes.push(holeIndex);
            }
        }
        return result;
    }
838281
def resolve_polytomies(self):
        ''''''
        q = deque(); q.append(self)
        while len(q) != 0:
            node = q.popleft()
            while len(node.children) > 2:
                c1 = node.children.pop(); c2 = node.children.pop()
                nn = Node(edge_length=0); node.add_child(nn)
                nn.add_child(c1); nn.add_child(c2)
            q.extend(node.children)