def test_float_cast_weight_func(self): dag = retworkx.PyDAG() node_a = dag.add_node('a') dag.add_child(node_a, 'b', 7.0) res = retworkx.dag_adjacency_matrix(dag, lambda x: float(x)) self.assertIsInstance(res, np.ndarray) self.assertTrue(np.array_equal(np.array([[0.0, 7.0], [0.0, 0.0]]), res))
def test_dag_with_index_holes(self): dag = retworkx.PyDAG() node_a = dag.add_node('a') node_b = dag.add_child(node_a, 'b', 1) dag.add_child(node_a, 'c', 1) dag.remove_node(node_b) res = retworkx.dag_adjacency_matrix(dag, lambda x: 1) self.assertIsInstance(res, np.ndarray) self.assertTrue(np.array_equal(np.array([[0, 1], [0, 0]]), res))
def test_single_neighbor(self): dag = retworkx.PyDAG() node_a = dag.add_node('a') dag.add_child(node_a, 'b', {'a': 1}) dag.add_child(node_a, 'c', {'a': 2}) res = retworkx.dag_adjacency_matrix(dag, lambda x: 1) self.assertIsInstance(res, np.ndarray) self.assertTrue( np.array_equal( np.array([[0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=np.float64), res))
def test_no_edge_dag_adjacency_matrix(self): dag = retworkx.PyDAG() for i in range(50): dag.add_node(i) res = retworkx.dag_adjacency_matrix(dag, lambda x: 1) self.assertTrue(np.array_equal(np.zeros([50, 50]), res))