# Path: bp_acceptance_tests/helpers.py
# def random_vector(length, is_row, dtype, as_matrix):
#     """ Generate a random vector """
#     m, n = (1, length) if is_row else (length, 1)
#     vector = random.uniform(MIN, MAX, (m, n)).astype(dtype)
#     if as_matrix:
#         vector = asmatrix(vector)
#     return vector
# 
# def random_triangular_matrix(n, dtype, as_matrix, uplo, diag, trans='n'):
#     """ Generate a random triangular matrix """
#     rand_matrix = random_matrix(n, n, dtype, as_matrix)
#     if diag == 'u' or diag == 'U':
#         fill_diagonal(rand_matrix, 1)
#     rand_matrix = triu(rand_matrix) if (uplo == 'u' or uplo == 'U') else tril(rand_matrix)
#     return (rand_matrix if (trans == 'n' or trans == 'N') else rand_matrix.T).astype(dtype)
# 
# Path: blaspy/level_2/trmv.py
# def trmv(A, x, uplo='u', trans_a='n', diag='n', lda=None, inc_x=1):
#     """
#     Perform a triangular matrix-vector multiplication operation.
# 
#     x := A * x
# 
#     where alpha is a scalar, A is a triangular matrix, and x is a general column vector.
# 
#     The 'uplo' argument indicates whether the lower or upper triangle of A is to be referenced and
#     updated by the operation. The 'trans_a' argument allows the computation to proceed as if A is
#     transposed. The 'diag' argument indicates whether the diagonal of A is unit or non-unit.
# 
#     Vector x can be passed in as either row or column vector. If necessary, an implicit
#     transposition occurs.
# 
#     Args:
#         x:          2D NumPy matrix or ndarray representing vector x
#         A:          2D NumPy matrix or ndarray representing matrix A
# 
#         --optional arguments--
# 
#         uplo:       'u'  if the upper triangle of A is to be used
#                     'l'  if the lower triangle A is to be used
#                         < default is 'u' >
#         trans_a:    'n'  if the operation is to proceed normally
#                     't'  if the operation is to proceed as if A is transposed
#                         < default is 'n' >
#         diag:       'n'  if the diagonal of A is non-unit
#                     'u'  if the diagonal of A is unit
#                         < default is 'n' >
#         lda:        leading dimension of A (must be >= # of cols in A)
#                         < default is the number of columns in A >
#         inc_x:      stride of x (increment for the elements of x)
#                         < default is 1 >
# 
#     Returns:
#         Vector x (which is also overwritten)
# 
#     Raises:
#         ValueError: if any of the following conditions occur:
#                     - A or x is not a 2D NumPy ndarray or NumPy matrix
#                     - A and x do not have the same dtype or that dtype is not supported
#                     - A is not a square matrix
#                     - x is not a vector
#                     - the effective length of x does not equal the dimension of A
#                     - uplo is not equal to one of the following: 'u', 'U', 'l', 'L'
#                     - trans_a is not equal to one of the following: 'n', 'N', 't', 'T'
#                     - diag is not equal to one fo the following: 'n', 'N', 'u', 'U'
#     """
# 
#     # get the dimensions of the parameters
#     m_x, n_x, x_length = get_vector_dimensions('x', x, inc_x)
#     dim_A = get_square_matrix_dimension('A', A)
# 
#     # assign a default value to lda if necessary (assumes row-major order)
#     if lda is None:
#         lda = dim_A
# 
#     # ensure the parameters are appropriate for the operation
#     check_equal_sizes('A', dim_A, 'x', x_length)
# 
#     # convert to appropriate CBLAS values
#     cblas_uplo = convert_uplo(uplo)
#     cblas_trans_a = convert_trans(trans_a)
#     cblas_diag = convert_diag(diag)
# 
#     # determine which CBLAS subroutine to call and which ctypes data type to use
#     cblas_func, data_type = get_cblas_info('trmv', (A.dtype, x.dtype))
# 
#     # create a ctypes POINTER for each vector and matrix
#     ctype_x = POINTER(data_type * n_x * m_x)
#     ctype_A = POINTER(data_type * dim_A * dim_A)
# 
#     # call CBLAS using ctypes
#     cblas_func.argtypes = [c_int, c_int, c_int, c_int, c_int, ctype_A, c_int, ctype_x, c_int]
#     cblas_func.restype = None
#     cblas_func(ROW_MAJOR, cblas_uplo, cblas_trans_a, cblas_diag, dim_A,
#                A.ctypes.data_as(ctype_A), lda, x.ctypes.data_as(ctype_x), inc_x)
# 
#     return x  # x is also overwritten


from ..helpers import random_vector, random_triangular_matrix
from blaspy import trmv
from numpy import allclose, copy, dot
from itertools import product
from random import randint
                         diag)
            test_name = "".join(variables)
            tests_failed.append(test_name)

    return tests_failed

def passed_test(dtype, as_matrix, x_is_row, stride, uplo, trans_a, diag):
    """
    Run one triangular matrix-vector multiplication test.

    Arguments:
        dtype:        either 'float64' or 'float32', the NumPy dtype to test
        as_matrix:    True to test a NumPy matrix, False to test a NumPy ndarray
        x_is_row:     True to test a row vector as parameter x, False to test a column vector
        stride:       stride of x and y to test; if None, a random stride is assigned
        uplo:         BLASpy uplo parameter to test
        trans:        BLASpy trans parameter to test
        diag:         BLASpy diag parameter to test

    Returns:
        True if the expected result is within the margin of error of the actual result,
        False otherwise.
    """

    # generate random sizes for matrix/vector dimensions and vector stride (if necessary)
    n = randint(N_MIN, N_MAX)
    stride = randint(N_MIN, STRIDE_MAX) if stride is None else stride
    n_A = n / stride + (n % stride > 0)

    # create random vectors and matrices to test

# Path: bp_acceptance_tests/helpers.py
# def random_vector(length, is_row, dtype, as_matrix):
#     """ Generate a random vector """
#     m, n = (1, length) if is_row else (length, 1)
#     vector = random.uniform(MIN, MAX, (m, n)).astype(dtype)
#     if as_matrix:
#         vector = asmatrix(vector)
#     return vector
# 
# def random_triangular_matrix(n, dtype, as_matrix, uplo, diag, trans='n'):
#     """ Generate a random triangular matrix """
#     rand_matrix = random_matrix(n, n, dtype, as_matrix)
#     if diag == 'u' or diag == 'U':
#         fill_diagonal(rand_matrix, 1)
#     rand_matrix = triu(rand_matrix) if (uplo == 'u' or uplo == 'U') else tril(rand_matrix)
#     return (rand_matrix if (trans == 'n' or trans == 'N') else rand_matrix.T).astype(dtype)
# 
# Path: blaspy/level_2/trmv.py
# def trmv(A, x, uplo='u', trans_a='n', diag='n', lda=None, inc_x=1):
#     """
#     Perform a triangular matrix-vector multiplication operation.
# 
#     x := A * x
# 
#     where alpha is a scalar, A is a triangular matrix, and x is a general column vector.
# 
#     The 'uplo' argument indicates whether the lower or upper triangle of A is to be referenced and
#     updated by the operation. The 'trans_a' argument allows the computation to proceed as if A is
#     transposed. The 'diag' argument indicates whether the diagonal of A is unit or non-unit.
# 
#     Vector x can be passed in as either row or column vector. If necessary, an implicit
#     transposition occurs.
# 
#     Args:
#         x:          2D NumPy matrix or ndarray representing vector x
#         A:          2D NumPy matrix or ndarray representing matrix A
# 
#         --optional arguments--
# 
#         uplo:       'u'  if the upper triangle of A is to be used
#                     'l'  if the lower triangle A is to be used
#                         < default is 'u' >
#         trans_a:    'n'  if the operation is to proceed normally
#                     't'  if the operation is to proceed as if A is transposed
#                         < default is 'n' >
#         diag:       'n'  if the diagonal of A is non-unit
#                     'u'  if the diagonal of A is unit
#                         < default is 'n' >
#         lda:        leading dimension of A (must be >= # of cols in A)
#                         < default is the number of columns in A >
#         inc_x:      stride of x (increment for the elements of x)
#                         < default is 1 >
# 
#     Returns:
#         Vector x (which is also overwritten)
# 
#     Raises:
#         ValueError: if any of the following conditions occur:
#                     - A or x is not a 2D NumPy ndarray or NumPy matrix
#                     - A and x do not have the same dtype or that dtype is not supported
#                     - A is not a square matrix
#                     - x is not a vector
#                     - the effective length of x does not equal the dimension of A
#                     - uplo is not equal to one of the following: 'u', 'U', 'l', 'L'
#                     - trans_a is not equal to one of the following: 'n', 'N', 't', 'T'
#                     - diag is not equal to one fo the following: 'n', 'N', 'u', 'U'
#     """
# 
#     # get the dimensions of the parameters
#     m_x, n_x, x_length = get_vector_dimensions('x', x, inc_x)
#     dim_A = get_square_matrix_dimension('A', A)
# 
#     # assign a default value to lda if necessary (assumes row-major order)
#     if lda is None:
#         lda = dim_A
# 
#     # ensure the parameters are appropriate for the operation
#     check_equal_sizes('A', dim_A, 'x', x_length)
# 
#     # convert to appropriate CBLAS values
#     cblas_uplo = convert_uplo(uplo)
#     cblas_trans_a = convert_trans(trans_a)
#     cblas_diag = convert_diag(diag)
# 
#     # determine which CBLAS subroutine to call and which ctypes data type to use
#     cblas_func, data_type = get_cblas_info('trmv', (A.dtype, x.dtype))
# 
#     # create a ctypes POINTER for each vector and matrix
#     ctype_x = POINTER(data_type * n_x * m_x)
#     ctype_A = POINTER(data_type * dim_A * dim_A)
# 
#     # call CBLAS using ctypes
#     cblas_func.argtypes = [c_int, c_int, c_int, c_int, c_int, ctype_A, c_int, ctype_x, c_int]
#     cblas_func.restype = None
#     cblas_func(ROW_MAJOR, cblas_uplo, cblas_trans_a, cblas_diag, dim_A,
#                A.ctypes.data_as(ctype_A), lda, x.ctypes.data_as(ctype_x), inc_x)
# 
#     return x  # x is also overwritten


# Path: bp_acceptance_tests/level_2/acceptance_test_trmv.py
from ..helpers import random_vector, random_triangular_matrix
from blaspy import trmv
from numpy import allclose, copy, dot
from itertools import product
from random import randint

                         diag)
            test_name = "".join(variables)
            tests_failed.append(test_name)

    return tests_failed

def passed_test(dtype, as_matrix, x_is_row, stride, uplo, trans_a, diag):
    """
    Run one triangular matrix-vector multiplication test.

    Arguments:
        dtype:        either 'float64' or 'float32', the NumPy dtype to test
        as_matrix:    True to test a NumPy matrix, False to test a NumPy ndarray
        x_is_row:     True to test a row vector as parameter x, False to test a column vector
        stride:       stride of x and y to test; if None, a random stride is assigned
        uplo:         BLASpy uplo parameter to test
        trans:        BLASpy trans parameter to test
        diag:         BLASpy diag parameter to test

    Returns:
        True if the expected result is within the margin of error of the actual result,
        False otherwise.
    """

    # generate random sizes for matrix/vector dimensions and vector stride (if necessary)
    n = randint(N_MIN, N_MAX)
    stride = randint(N_MIN, STRIDE_MAX) if stride is None else stride
    n_A = n / stride + (n % stride > 0)

    # create random vectors and matrices to test

    x = random_vector(n, x_is_row, dtype, as_matrix)