Exemplo n.º 1
0
    ntheta = params.shape[0]
    npts = us.shape[0]
    seed = np.zeros((2 + ntheta, all_params.shape[0]), dtype=all_params.dtype)
    for i in range(npts):
        seed[0][2 * i] = 1.
        seed[1][2 * i + 1] = 1.
    for i in range(ntheta):
        seed[i + 2][i + 2 * npts] = 1.

    if nruns_J > 0:
        tJ, J = utils.timer(
            lambda all_params, *params: np.array(
                [fjac(all_params, curr_seed, *params)
                 for curr_seed in seed]).transpose(),
            (all_params, data.model.nbones, data.model.base_relatives,
             data.model.parents, data.model.inverse_base_absolutes,
             data.model.base_positions, data.model.weights, mirror_factor,
             data.points, data.correspondences, data.model.triangles),
            nruns=nruns_J,
            limit=time_limit,
            ret_val=True)

        tJ += tf  # !!!!!!!!! adding this because no function value is returned by fjac
        print("J:")
        # print(J)
        hand_io.write_J(fn_out + "_J_" + name + ".txt", J)
    else:
        tJ = 0

    utils.write_times(fn_out + "_times_" + name + ".txt", tf, tJ)
Exemplo n.º 2
0
    name = "PyTorch"

    ntheta = params.shape[0]
    npts = us.shape[0]
    seed = torch.zeros((2 + ntheta, all_params.shape[0]), dtype=torch.float64)
    for i in range(npts):
        seed[0][2 * i] = 1.
        seed[1][2 * i + 1] = 1.
    for i in range(ntheta):
        seed[i + 2][i + 2 * npts] = 1.

    if nruns_J > 0:
        tJ, res = utils.timer(
            lambda *args: torch_seed_wrapper(seed, args),
            (hand_objective_complicated, (all_params, ),
             (data.model.nbones, data.model.base_relatives, data.model.parents,
              data.model.inverse_base_absolutes, data.model.base_positions,
              data.model.weights, mirror_factor, data.points,
              data.correspondences, data.model.triangles), True),
            nruns=nruns_J,
            limit=time_limit,
            ret_val=True)
        tJ += tf  # !!!!!!!!! adding this because no function value is returned by fjac
        # print("J:")
        # print(J)
        hand_io.write_J(fn_out + "_J_" + name + ".txt", res[1])
    else:
        tJ = 0

    utils.write_times(fn_out + "_times_" + name + ".txt", tf, tJ)