import math
import numpy as np


# Generate Hadamhard matrix of atleast a given size using Sylvester's method
def generated_hadamhard_matrix(lower_bound):

    dim = 1
    h = np.array([[1.0]], dtype=float)

    while dim < lower_bound:
        h = np.block([[h, h], [h, -h]])
        dim = 2 * dim

    # Trim the columns of the matrix to match the lower bound
    return h[:, :lower_bound]


# Size of the smallest Hadamhard matrix which is greater than lower bound, as generated by Sylvester's method.
def get_sylvester_hadamhard_matrix_dim(lower_bound):
    return int(math.pow(2, math.ceil(math.log(lower_bound, 2))))
