0

コードは次のようになります。

def func1(p1,p2,p3):
   #do samething
   res = func_a(p1,p3)  # a
   res = func_a(p2,p3)
   return res

def func2(p1,p2,p3):
   #do samething
   res = func_b(p1,p3)  # b
   res = func_b(p2,p3)
   return res

def func3(p1,p2,p3):
   #do samething
   res = func_c(p1,p3)  # c
   res = func_c(p2,p3)
   return res

私はすでに 3 つのパラメーターを持っているので、関数に追加のパラメーターを追加することが良い考えかどうかはわかりません。

しかし、さらに最適化を行わないと、現在のコードではパーツの繰り返しが多すぎます#do samething。(以下のオリジンコードのように)。

どうすれば改善できますか?


    @staticmethod
    def align_bev_tuple(relative_poses_tuple, t_index, *bev):
        if t_index == 0: 
            return bev
        ego_motion_matrix, dataAug_compensate_matrix = relative_poses_tuple
        if dataAug_compensate_matrix is not None:
            bev = list_2d_affine(
                bev, dataAug_compensate_matrix[:, t_index, :, :])
        output = list_2d_affine(
            bev, ego_motion_matrix[:, t_index, :, :])
        return output

    @staticmethod
    def align_bev_single_state(relative_poses_tuple, t_index, hidden_state):
        if t_index == 0:
            return hidden_state
        ego_motion_matrix, dataAug_compensate_matrix = relative_poses_tuple
        if dataAug_compensate_matrix is not None:
            hidden_state = bev_affine(
                hidden_state, dataAug_compensate_matrix[:, t_index, :, :])
        output = bev_affine(
            hidden_state, ego_motion_matrix[:, t_index, :, :])
        return output

    @staticmethod
    def align_bev_tensor(relative_poses_tuple, t_index, hidden_state):
        if t_index == 0:
            return hidden_state
        ego_motion_matrix, dataAug_compensate_matrix = relative_poses_tuple
        if dataAug_compensate_matrix is not None:
            hidden_state = tensor_2d_affine(
                hidden_state, dataAug_compensate_matrix[:, t_index, :, :])
        output = tensor_2d_affine(
            hidden_state, ego_motion_matrix[:, t_index, :, :])
        return output
4

0 に答える 0