def passed_test(dtype, as_matrix, side, uplo, trans_a, diag): """ Run one triangular solve with multiple right-hand sides 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 side: BLASpy 'side' parameter to test uplo: BLASpy 'uplo' parameter to test trans_a: BLASpy 'trans_a' 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. """ side_is_left = side == 'l' or side == 'L' a_is_unit = diag == 'u' or diag == 'U' # generate random sizes for matrix dimensions m = randint(N_MIN, N_MAX) n = randint(N_MIN, N_MAX) dim_A = m if side_is_left else n # create random scalars and matrices to test alpha = uniform(SCAL_MIN, SCAL_MAX) A = random_triangular_matrix(dim_A, dtype, as_matrix, uplo, diag='n') B = random_matrix(m, n, dtype, as_matrix) # scale off-diagonals to avoid numerical issues A /= dim_A B /= dim_A # fill diagonal with 1 if unit-triangular, else fill diagonal with values between 1 and 2 if a_is_unit: fill_diagonal(A, 1) else: for i in range(dim_A): A[i, i] = uniform(1, 2) # compute the expected result expected = alpha * B #compute the actual result trsm(A, B, side, uplo, trans_a, diag, alpha) trmm(A, B, side, uplo, trans_a, diag) actual = B # compare the actual result to the expected result and return result of the test return allclose(actual, expected, RTOL, ATOL)
def passed_test(dtype, as_matrix, uplo, side, trans_a, diag): """ Run one symmetric matrix-matrix 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 uplo: BLASpy 'uplo' parameter to test side: BLASpy 'side' parameter to test trans_a: BLASpy 'trans_a' 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. """ side_is_left = side == 'l' or side == 'L' transpose = trans_a == 't' or trans_a == 'T' # generate random sizes for matrix dimensions m = randint(N_MIN, N_MAX) n = randint(N_MIN, N_MAX) k = m if side_is_left else n # create random scalars and matrices to test alpha = uniform(SCAL_MIN, SCAL_MAX) A = random_triangular_matrix(k, dtype, as_matrix, uplo, diag, trans_a) B = random_matrix((k if side_is_left else m), (n if side_is_left else k), dtype, as_matrix) # compute the expected result B_2 = alpha * (dot(A, B) if side_is_left else dot(B, A)) # get the actual result trmm(A, B, side, uplo, trans_a, diag, alpha) # compare the actual result to the expected result and return result of the test return allclose(B, B_2, RTOL, ATOL)