コード例 #1
0
ファイル: dag_node.py プロジェクト: knut0815/graph-learn
 def feed_values(self, dag_values):
     shape, degrees = self._get_shape_and_degrees(dag_values)
     edge_ids = pywrap.get_dag_value(dag_values, self._nid, pywrap.kEdgeIds)
     src_ids = pywrap.get_dag_value(dag_values, self._nid, pywrap.kSrcIds)
     dst_ids = pywrap.get_dag_value(dag_values, self._nid, pywrap.kDstIds)
     return self._graph.get_edges(self._type, src_ids, dst_ids, edge_ids,
                                  degrees, shape)
コード例 #2
0
ファイル: dag_node.py プロジェクト: knut0815/graph-learn
 def feed_values(self, dag_values):
     shape, degrees = self._get_shape_and_degrees(dag_values)
     edge_ids = pywrap.get_dag_value(dag_values, self._nid, pywrap.kEdgeIds)
     assert isinstance(shape, tuple) and len(shape) == 2
     nbr_counts = degrees if self._sparse else [shape[1]] * shape[0]
     src_ids = pywrap.get_dag_value(dag_values, self._upstream.nid,
                                    pywrap.kNodeIds)
     src_ids = src_ids.reshape(self._upstream.shape)
     src_ids = np.concatenate(
         [src_ids[idx].repeat(d) for idx, d in enumerate(nbr_counts)])
     dst_ids = pywrap.get_dag_value(dag_values, self._nid, pywrap.kNodeIds)
     return self._graph.get_edges(self._type, src_ids, dst_ids, edge_ids,
                                  degrees, shape)
コード例 #3
0
ファイル: dag_node.py プロジェクト: knut0815/graph-learn
 def _get_shape_and_degrees(self, dag_values):
     shape = self._shape
     degrees = None
     if self._sparse:
         assert isinstance(shape, tuple) and len(shape) == 2
         degrees = pywrap.get_dag_value(dag_values, self._nid,
                                        pywrap.kDegreeKey)
         shape = (shape[0], shape[1] if shape[1] else max(degrees))
     return shape, degrees
コード例 #4
0
ファイル: dag_dataset.py プロジェクト: knut0815/graph-learn
    def __getitem__(self, alias):
        # Get the DagNode of alias.
        node = self._dag.get_node(alias)
        if not node:
            raise ValueError(
                "Alias {} is not existed in the query.".format(alias))

        # If Nodes/Edges of the alias already got from response,
        # just get them from python values, instead of converting from C++.
        if alias in self._cache.keys():
            return self._cache[alias]

        # Cache Nodes/Edges.
        res = node.feed_values(self._res)
        self._cache[alias] = res

        # Add the attributes for the Nodes/Edges.
        lookup_node = node.get_lookup_node()
        res.int_attrs = pywrap.get_dag_value(self._res, lookup_node.nid, "ia")
        res.float_attrs = pywrap.get_dag_value(self._res, lookup_node.nid,
                                               "fa")
        res.string_attrs = pywrap.get_dag_value(self._res, lookup_node.nid,
                                                "sa")
        res.weights = pywrap.get_dag_value(self._res, lookup_node.nid, "wei")
        res.labels = pywrap.get_dag_value(self._res, lookup_node.nid, "lb")

        # Add degrees for the Nodes.
        for dg_node in node.get_degree_nodes():
            if dg_node.node_from == pywrap.NodeFrom.EDGE_SRC:
                res.add_out_degrees(
                    dg_node.edge_type,
                    pywrap.get_dag_value(self._res, dg_node.nid, "dg"))
            if dg_node.node_from == pywrap.NodeFrom.EDGE_DST or \
                dg_node.edge_type in self._graph.undirected_edges:
                res.add_in_degrees(
                    dg_node.edge_type,
                    pywrap.get_dag_value(self._res, dg_node.nid, "dg"))
        return res
コード例 #5
0
ファイル: dag_node.py プロジェクト: knut0815/graph-learn
 def feed_values(self, dag_values):
     shape, degrees = self._get_shape_and_degrees(dag_values)
     return self._graph.get_nodes(
         self._type,
         pywrap.get_dag_value(dag_values, self._nid, pywrap.kNodeIds),
         degrees, shape)