def LayerNormReference(begin_norm_axis, begin_params_axis, x, gamma, beta):
    begin_norm_axis = (begin_norm_axis if (begin_norm_axis >= 0) else (begin_norm_axis + len(x.shape)))
    begin_params_axis = (begin_params_axis if (begin_params_axis >= 0) else (begin_params_axis + len(x.shape)))
    axis = [i for i in range(begin_norm_axis, len(x.shape))]
    mean = np.mean(x, axis=tuple(axis), keepdims=True)
    var = np.var(x, axis=tuple(axis), keepdims=True)
    gamma = gamma.reshape((*((1,) * begin_params_axis), *x.shape[begin_params_axis:]))
    beta = beta.reshape((*((1,) * begin_params_axis), *x.shape[begin_params_axis:]))
    y = (((np.subtract(x, mean) / np.sqrt((var + 1e-12))) * gamma) + beta)
    return (y, mean, var)
def LayerNormReference(begin_norm_axis, begin_params_axis, x, gamma, beta):
    begin_norm_axis = (begin_norm_axis if (begin_norm_axis >= 0) else (begin_norm_axis + len(x.shape)))
    begin_params_axis = (begin_params_axis if (begin_params_axis >= 0) else (begin_params_axis + len(x.shape)))
    axis = [i for i in range(begin_norm_axis, len(x.shape))]
    mean = np.mean(x, axis=tuple(axis), keepdims=True)
    var = np.var(x, axis=tuple(axis), keepdims=True)
    gamma = gamma.reshape((*((1,) * begin_params_axis), *x.shape[begin_params_axis:]))
    beta = beta.reshape((*((1,) * begin_params_axis), *x.shape[begin_params_axis:]))
    y = (((np.subtract(x, mean) / np.sqrt((var + 1e-12))) * gamma) + beta)
    return (y, mean, var)