import torch


def init_c(hparams):
    """
    Initializes the hyperparameters as a scalar, vector, or matrix.

    Args:
        hparams: The experiment parameters to use for init.
                 Type: Namespace.
                 Expected to have the consituents:
                    hparams.outer.hyperparam_type - str in [scalar, vector, matrix]
                    hparams.problem.num_measurements - int
                    hparams.outer.hyperparam_init - int or float
    
    Returns:
        c: The initialized hyperparameters.
           Type: Tensor.
           Shape: [] for scalar hyperparam
                  [m] for vector hyperparam
                  [m,m] for matrix hyperparam
    """
    c_type = hparams.outer.hyperparam_type
    m = hparams.problem.num_measurements
    init_val = float(hparams.outer.hyperparam_init)

    if c_type == 'scalar':
        c = torch.tensor(init_val)
    elif c_type == 'vector':
        c = torch.ones(m) * init_val
    elif c_type == 'matrix':
        c = torch.eye(m) * init_val
    else:
        raise NotImplementedError

    return c