class_docstr: Unit tests for the NeuralNetwork test class. 
docstr: Tests computation and retrieval of the distances to all layers. 
docstr_tok: ["Tests","computation","and","retrieval","of","the","distances","to","all","layers","."]
code: def test_bkwd_ip_fwd_op_dists_of_all_layers(self):
      """Tests computation and retrieval of the distances to all layers."""
      self.report(
          "Testing computation/retrieval of backward and forward distances."
      )
      for cnn in self.cnns:
          all_label_order = [
              "all-shortest",
              "conv-shortest",
              "pool-shortest",
          ]
          np.random.shuffle(all_label_order)
          # First comptue the distances and check if the sizes are ok.
          (
              curr_bkwd_to_ip_comp,
              curr_fwd_to_op_comp,
          ) = cnn.get_bkwd_ip_fwd_op_dists_of_all_layers(
              all_label_order
          )
          assert curr_fwd_to_op_comp.shape == (
              cnn.num_layers,
              len(all_label_order),
          )
          assert curr_bkwd_to_ip_comp.shape == (
              cnn.num_layers,
              len(all_label_order),
          )
          # Now check for values - we will use floyd warshall to compute the distances here.
          ip_idx = cnn.get_ip_layer_idx()
          op_idx = cnn.get_op_layer_idx()
          curr_edge_wts = cnn.get_edge_weights_from_conn_mat()
          curr_fwd_to_op = []
          curr_bkwd_to_ip = []
          # compute the all pairs distances
          for ll in all_label_order:
              if ll == "all-shortest":
                  curr_fwd_to_op.append(
                      apsp_floyd_warshall_costs(curr_edge_wts)[
                          :, op_idx
                      ]
                  )
                  curr_bkwd_to_ip.append(
                      apsp_floyd_warshall_costs(curr_edge_wts.T)[
                          :, ip_idx
                      ]
                  )
              else:
                  dist_type = ll.split("-")[0]
                  ll_edge_wts = cnn.get_layer_or_group_edge_weights_from_edge_weights(
                      curr_edge_wts.T, dist_type
                  )
                  ll_edge_wtsT = cnn.get_layer_or_group_edge_weights_from_edge_weights(
                      curr_edge_wts, dist_type
                  )
                  curr_bkwd_to_ip.append(
                      apsp_floyd_warshall_costs(ll_edge_wtsT)[ip_idx, :]
                  )
                  curr_fwd_to_op.append(
                      apsp_floyd_warshall_costs(ll_edge_wts)[op_idx, :]
                  )
          curr_fwd_to_op = np.array(curr_fwd_to_op).T
          curr_bkwd_to_ip = np.array(curr_bkwd_to_ip).T
  
file_path: dragonfly/dragonfly/nn/unittest_neural_network.py
imports: import numpy
  from .None import neural_network
  from .nn_examples import generate_cnn_architectures, generate_mlp_architectures
  from ..utils.base_test_class import BaseTestClass, execute_tests
  from ..utils.graph_utils import apsp_floyd_warshall_costs
label_desc: Use image node_id 5 for calling the NeuralNetworkTestCase obj's underlying member method code with example usage: obj.test_bkwd_ip_fwd_op_dists_of_all_layers() without return types