def passed_test(output, as_matrix, x_is_row, y_is_row, stride):
    """
    Run one extended-precision dot (inner) product test.

    Arguments:
        output:       BLASpy 'output' parameter 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
        y_is_row:     True to test a row vector as parameter y, False to test a column vector
        stride:       stride of x and y to test; if None, a random stride is assigned

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

    # generate random sizes for vector dimensions and vector stride (if necessary)
    length = randint(N_MIN, N_MAX)
    stride = randint(N_MIN, STRIDE_MAX) if stride is None else stride

    # create random vectors to test
    x = random_vector(length, x_is_row, 'float32', as_matrix)
    y = random_vector(length, y_is_row, 'float32', as_matrix)

    # create views of x and y that can be used to calculate the expected result
    x_2 = x if x_is_row else x.T
    y_2 = y.T if y_is_row else y

    # compute the expected result
    if stride == 1:
        expected = dot(x_2, y_2)[0][0]
    else:
        expected = 0
        for i in range(0, length, stride):
            expected += x_2[0, i] * y_2[i, 0]

    # get the actual result
    actual = sdot(x, y, stride, stride, output)

    # compare the actual result to the expected result and return result of the test
    return abs(actual - expected) / expected < EPSILON
Exemplo n.º 2
0
 def test_unequal_strides(self):
     x = array([[1., 2., 3., 4., 5., 6.]], dtype='float32')
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y, inc_x=3, inc_y=2), 7)
Exemplo n.º 3
0
 def test_float64_output(self):
     x = array([[1., 2., 3.]], dtype='float32')
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y, output='float64'), 10)
Exemplo n.º 4
0
 def test_strides_less_than_length(self):
     x = array([[1., 2., 3.]], dtype='float32')
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y, inc_x=2, inc_y=2), 6)
Exemplo n.º 5
0
 def test_strides_greater_than_length(self):
     x = array([[1., 2., 3.]], dtype='float32')
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y, inc_x=3, inc_y=3), 3)
Exemplo n.º 6
0
 def test_vectors_as_mixed_matrices_and_ndarrays(self):
     x = asmatrix(array([[1., 2., 3.]], dtype='float32'))
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y), 10)
Exemplo n.º 7
0
 def test_vectors_with_negatives_in_values(self):
     x = array([[-1., -2., 3.]], dtype='float32')
     y = array([[3., 2., 1.]], dtype='float32')
     self.assertEqual(sdot(x, y), -4)
Exemplo n.º 8
0
 def test_row_and_col_vectors_as_ndarrays(self):
     x = array([[1., 2., 3.]], dtype='float32')
     y = array([[3.], [2.], [1.]], dtype='float32')
     self.assertEqual(sdot(x, y), 10)
Exemplo n.º 9
0
 def test_two_column_vectors_as_ndarrays(self):
     x = array([[1.], [2.], [3.]], dtype='float32')
     y = array([[3.], [2.], [1.]], dtype='float32')
     self.assertEqual(sdot(x, y), 10)
Exemplo n.º 10
0
 def test_scalar_as_ndarray(self):
     x = array([[1.]], dtype='float32')
     y = array([[2.]], dtype='float32')
     self.assertEqual(sdot(x, y), 2)