def test_kmeans(self):
        tss = Array([[0.0,   1.0,  2.0,  3.0],
                     [6.0,   7.0,  8.0,  9.0],
                     [2.0,  -2.0,  4.0, -4.0],
                     [8.0,   5.0,  3.0,  1.0],
                     [15.0, 10.0,  5.0,  0.0],
                     [7.0,  -7.0,  1.0, -1.0]])

        expected_c = np.array([[0.0, 0.1667, 0.3333, 0.5],
                               [1.5, -1.5, 0.8333, -0.8333],
                               [4.8333, 3.6667, 2.6667, 1.6667]])

        result = k_means(tss, 3)
        result_c = result[0].to_numpy()

        for i in range(0, 4):
            self.assertAlmostEqual(result_c[0, i] + result_c[1, i] +
                                   result_c[2, i],
                                   expected_c[0, i] +
                                   expected_c[1, i] +
                                   expected_c[2, i], delta=self.DELTA)
Пример #2
0
def sbd(tss):
    """ Calculates the Shape-Based distance (SBD). It computes the normalized cross-correlation and
    it returns the value that maximizes the correlation value between time series.

    :param tss: Expects an input array whose dimension zero is the length of the time series (all the same) and
                dimension one indicates the number of time series.
    :return: Array with an upper triangular matrix where each position corresponds to the distance between two time series.
            Diagonal elements will be zero. For example: Position row 0 column 1 records the distance between time series 0
            and time series 1.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.sbd(ctypes.pointer(tss.arr_reference),
                                       ctypes.pointer(b),
                                       ctypes.pointer(error_code),
                                       error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #3
0
def max_min_norm(tss, high=1.0, low=0.0, epsilon=0.00000001):
    """ Normalizes the given time series according to its minimum and maximum value and adjusts each value within the
    range [low, high].

    :param tss: KHIVA array with the time series.
    :param high: Maximum final value (Defaults to 1.0).
    :param low: Minimum final value (Defaults to 0.0).
    :param epsilon: Safeguard for constant (or near constant) time series as the operation implies a unit scale
                    operation between min and max values in the tss.

    :return: KHIVA array with the same dimensions as tss where the time series have been adjusted for zero mean and
            one as standard deviation.
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.max_min_norm(
        ctypes.pointer(tss.arr_reference),
        ctypes.pointer(ctypes.c_double(high)),
        ctypes.pointer(ctypes.c_double(low)),
        ctypes.pointer(ctypes.c_double(epsilon)), ctypes.pointer(b))

    return Array(array_reference=b)
Пример #4
0
def approximate_entropy(arr, m, r):
    """ Calculates a vectorized Approximate entropy algorithm.
    https://en.wikipedia.org/wiki/Approximate_entropy
    For short time-series this method is highly dependent on the parameters, but should be stable for N > 2000,
    see: Yentes et al. (2012) - The Appropriate Use of Approximate Entropy and Sample Entropy with Short Data Sets
    Other shortcomings and alternatives discussed in:
    Richman & Moorman (2000) - Physiological time-series analysis using approximate entropy and sample entropy


    :param arr: A KHIVA array with the time series.
    :param m: Length of compared run of data.
    :param r: Filtering level, must be positive.
    :return: KHIVA array with the vectorized approximate entropy for all the input time series in tss.
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.approximate_entropy(ctypes.pointer(arr.arr_reference),
                                                       ctypes.pointer(ctypes.c_int(m)),
                                                       ctypes.pointer(ctypes.c_float(r)),
                                                       ctypes.pointer(b))

    return Array(array_reference=b)
Пример #5
0
def pip(a, number_ips):
    """ Calculates the number of Perceptually Important Points (PIP) in the time series.

    [1] Fu TC, Chung FL, Luk R, and Ng CM. Representing financial time series based on data point importance.
    Engineering Applications of Artificial Intelligence, 21(2):277-300, 2008.

    :param a: KHIVA array whose dimension zero is the length of the time series.
    :param number_ips: The number of points to be returned.

    :return: KHIVA array with the most Perceptually Important number_ips.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.pip(
        ctypes.pointer(a.arr_reference),
        ctypes.pointer(ctypes.c_int(number_ips)), ctypes.pointer(b),
        ctypes.pointer(error_code), error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #6
0
def mean_norm(tss):
    """ Normalizes the given time series according to its maximum-minimum value and its mean. It follows the following
    formulae:

    .. math::
        \\acute{x} = frac{x - mean(x)}{max(x) - min(x)}.

    :param tss: KHIVA array with the time series.

    :return: An array with the same dimensions as tss, whose values (time series in dimension 0) have been
            normalized by substracting the mean from each number and dividing each number by :math:`max(x) - min(`x)`,
            in the time series.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.mean_norm(ctypes.pointer(tss.arr_reference),
                                             ctypes.pointer(b), ctypes.pointer(error_code), error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #7
0
def percentage_of_reoccurring_values_to_all_values(arr, is_sorted):
    """ Calculates the percentage of unique values, that are present in the time series more than once.

    .. math::

        \\frac{\\textit{number of data points occurring more than once}}{\\textit{number of all data points})}

    This means the percentage is normalized to the number of unique values, in contrast to the
    percentage_of_reoccurring_datapoints_to_all_datapoints.

    :param arr: KHIVA array with the time series.
    :param is_sorted: Indicates if the input time series is sorted or not. Defaults to false.
    :return: KHIVA array with the percentage of unique values, that are present in the time series more than once.
    """
    b = ctypes.c_void_p(0)

    KhivaLibrary().c_khiva_library.percentage_of_reoccurring_values_to_all_values(ctypes.pointer(arr.arr_reference),
                                                                                  ctypes.pointer(
                                                                                      ctypes.c_bool(is_sorted)),
                                                                                  ctypes.pointer(b))

    return Array(array_reference=b)
Пример #8
0
def spkt_welch_density(arr, coeff):
    """ Estimates the cross power spectral density of the time series array at different frequencies. To do so, the
    time series is first shifted from the time domain to the frequency domain.

    Welch's method computes an estimate of the power spectral density by dividing the data into overlapping
    segments, computing a modified periodogram for each segment and averaging the periodograms.
    [1] P. Welch, "The use of the fast Fourier transform for the estimation of power spectra: A method based on time
    averaging over short, modified periodograms", IEEE Trans. Audio Electroacoust. vol. 15, pp. 70-73, 1967.
    [2] M.S. Bartlett, "Periodogram Analysis and Continuous Spectra", Biometrika, vol. 37, pp. 1-16, 1950.
    [3] Rabiner, Lawrence R., and B. Gold. "Theory and Application of Digital Signal Processing" Prentice-Hall, pp.
    414-419, 1975.

    :param arr: KHIVA array with the time series.
    :param coeff: The coefficient to be returned.
    :return: KHIVA array containing the power spectrum of the different frequencies for each time series in arr.
    """
    b = ctypes.c_void_p(0)

    KhivaLibrary().c_khiva_library.spkt_welch_density(ctypes.pointer(arr.arr_reference),
                                                      ctypes.pointer(ctypes.c_int(coeff)), ctypes.pointer(b))

    return Array(array_reference=b)
Пример #9
0
def ljung_box(tss, lags):
    """ The Ljung–Box test checks that data whithin the time series are independently distributed (i.e. the correlations
    in the population from which the sample is taken are 0, so that any observed correlations in the data result from
    randomness of the sampling process). Data are no independently distributed, if they exhibit serial correlation.
    The test statistic is:

    .. math::
        Q = n\\left(n+2\\right)\sum_{k=1}^h\\frac{\hat{\\rho}^2_k}{n-k}

    where :math:`n` is the sample size, :math:`\hat{\\rho}k` is the sample autocorrelation at lag :math:`k`, and
    :math:`h` is the number of lags being tested. Under :math:`H_0` the statistic Q follows a :math:`\\chi^2{(h)}`.
    For significance level :math:`\\alpha`, the :math:`critical region` for rejection of the hypothesis of randomness
    is:

    .. math::
        Q > \\chi_{1-\\alpha,h}^2

    where :math:`\\chi_{1-\\alpha,h}^2` is the :math:`\\alpha`-quantile of the chi-squared distribution with :math:`h`
    degrees of freedom.

    [1] G. M. Ljung G. E. P. Box (1978). On a measure of lack of fit in time series models.
    Biometrika, Volume 65, Issue 2, 1 August 1978, Pages 297–303.

    :param tss: Expects an input array whose dimension zero is the length of the time series (all the same) and
                dimension one indicates the number of time series.
    :param lags: Number of lags being tested.
    :return: Array containing the Ljung-Box statistic test.
    """
    ljung_box_out = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.ljung_box(
        ctypes.pointer(tss.arr_reference), ctypes.pointer(ctypes.c_long(lags)),
        ctypes.pointer(ljung_box_out), ctypes.pointer(error_code),
        error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=ljung_box_out)
Пример #10
0
def quantiles_cut(tss, quantiles, precision=1e-8):
    """ Discretizes the time series into equal-sized buckets based on sample quantiles.

    :param tss: Expects an input array whose dimension zero is the length of the time series (all the same) and dimension
                one indicates the number of time series. NOTE: the time series should be sorted.
    :param quantiles: Number of quantiles to extract. From 0 to 1, step 1/quantiles.
    :param precision: Number of decimals expected.
    :return: Matrix with the categories, one category per row, the start of the category in the first column and
            the end in the second category.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.quantiles_cut_statistics(
        ctypes.pointer(tss.arr_reference),
        ctypes.pointer(ctypes.c_float(quantiles)),
        ctypes.pointer(ctypes.c_float(precision)), ctypes.pointer(b),
        ctypes.pointer(error_code), error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #11
0
def visvalingam(a, num_points):
    """ Reduces a set of points by applying the Visvalingam method (minimun triangle area) until the number
    of points is reduced to numPoints.

    [1] M. Visvalingam and J. D. Whyatt, Line generalisation by repeated elimination of points,
    The Cartographic Journal, 1993.

    :param a: KHIVA array with the x-coordinates and y-coordinates of the input points (x in column 0 and y in column 1).
    :param num_points: Sets the number of points returned after the execution of the method.

    :return: KHIVA array with the x-coordinates and y-coordinates of the selected points (x in column 0 and y in
            column 1).
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.visvalingam(
        ctypes.pointer(a.arr_reference),
        ctypes.pointer(ctypes.c_int(num_points)), ctypes.pointer(b),
        ctypes.pointer(error_code), error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))
    return Array(array_reference=b)
Пример #12
0
def paa(a, bins):
    """ Piecewise Aggregate Approximation (PAA) approximates a time series :math:`X` of length :math:`n` into vector
    :math:`\\bar{X}=(\\bar{x}_{1},…,\\bar{x}_{M})` of any arbitrary length :math:`M \\leq n` where each of
    :math:`\\bar{x_{i}}` is calculated as follows:

    .. math::
        \\bar{x}_{i} = \\frac{M}{n} \\sum_{j=n/M(i-1)+1}^{(n/M)i} x_{j}.

    Which simply means that in order to reduce the dimensionality from :math:`n` to :math:`M`, we first divide the original
    time series into :math:`M` equally sized frames and secondly compute the mean values for each frame. The sequence
    assembled from the mean values is the PAA approximation (i.e., transform) of the original time series.

    :param a: Set of points.
    :param bins: Sets the total number of divisions.

    :return: KHIVA array of points with the reduced dimensionality.
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.paa(ctypes.pointer(a.arr_reference),
                                       ctypes.pointer(ctypes.c_int(bins)),
                                       ctypes.pointer(b))

    return Array(array_reference=b)
Пример #13
0
def ramer_douglas_peucker(a, epsilon):
    """ The Ramer–Douglas–Peucker algorithm (RDP) is an algorithm for reducing the number of points in a curve that is
    approximated by a series of points. It reduces a set of points depending on the perpendicular distance of the points
    and epsilon, the greater epsilon, more points are deleted.

    [1] Urs Ramer, "An iterative procedure for the polygonal approximation of plane curves", Computer Graphics and Image
    Processing, 1(3), 244–256 (1972) doi:10.1016/S0146-664X(72)80017-0.

    [2] David Douglas & Thomas Peucker, "Algorithms for the reduction of the number of points required to represent a
    digitized line or its caricature", The Canadian Cartographer 10(2), 112–122 (1973) doi:10.3138/FM57-6770-U75U-7727

    :param a: KHIVA array with the x-coordinates and y-coordinates of the input points (x in column 0 and y in column 1).
    :param epsilon: It acts as the threshold value to decide which points should be considered meaningful or not.

    :return: KHIVA array with the x-coordinates and y-coordinates of the selected points (x in column 0 and y in
            column 1).
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.ramer_douglas_peucker(
        ctypes.pointer(a.arr_reference),
        ctypes.pointer(ctypes.c_double(epsilon)), ctypes.pointer(b))

    return Array(array_reference=b)
Пример #14
0
def roots(p):
    """ Calculates the roots of a polynomial with coefficients given in :math:`p`. The values in the rank-1 array
    :math:`p` are coefficients of a polynomial. If the length of :math:`p` is :math:`n+1` then the polynomial is
    described by:

    .. math::
        p[0] * x^n + p[1] * x^{n-1} + ... + p[n-1] * x + p[n]

    :param p: KHIVA array with the polynomial coefficients.

    :return: KHIVA array with the roots of the polynomial.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.roots(ctypes.pointer(p.arr_reference),
                                         ctypes.pointer(b),
                                         ctypes.pointer(error_code),
                                         error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #15
0
def polyfit(x, y, deg):
    """ Least squares polynomial fit. Fit a polynomial :math:`p(x) = p[0] * x^{deg} + ... + p[deg]` of degree
    :math:`deg` to points :math:`(x, y)`. Returns a vector of coefficients :math:`p` that minimises the squared error.

    :param x: KHIVA array with the x-coordinates of the M sample points :math:`(x[i], y[i])`.
    :param y: KHIVA array with the y-coordinates of the sample points.
    :param deg: Degree of the fitting polynomial

    :return: KHIVA array with the polynomial coefficients, highest power first.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.polyfit(ctypes.pointer(x.arr_reference),
                                           ctypes.pointer(y.arr_reference),
                                           ctypes.pointer(ctypes.c_int(deg)),
                                           ctypes.pointer(b),
                                           ctypes.pointer(error_code),
                                           error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #16
0
def pla_sliding_window(ts, max_error):
    """
    Applies the Piecewise Linear Approximation (PLA Sliding Window) to the time series.

    [1] Zhu Y, Wu D, Li Sh (2007). A Piecewise Linear Representation Method of Time Series Based on Feature Points.
    Knowledge-Based Intelligent Information and Engineering Systems 4693:1066-1072.

    :param ts: Expects a khiva array containing the set of points to be reduced. The first component of the points in
                the first column and the second component of the points in the second column.
    :param max_error: The maximum approximation error allowed.
    :return: The reduced number of points.
    """
    b = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.pla_sliding_window(
        ctypes.pointer(ts.arr_reference),
        ctypes.pointer(ctypes.c_float(max_error)), ctypes.pointer(b),
        ctypes.pointer(error_code), error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=b)
Пример #17
0
def aggregated_autocorrelation(arr, aggregation_function):
    """ Calculates a linear least-squares regression for values of the time series that were aggregated
    over chunks versus the sequence from 0 up to the number of chunks minus one.

    :param arr: A KHIVA array with the time series.
    :param aggregation_function: Function to be used in the aggregation. It receives an integer which indicates
                                the function to be applied.
                                0 : mean,
                                1 : median
                                2 : min,
                                3 : max,
                                4 : stdev,
                                5 : var,
                                default : mean

    :return: KHIVA array that contains the aggregated correlation for each time series.
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.aggregated_autocorrelation(ctypes.pointer(arr.arr_reference),
                                                              ctypes.pointer(ctypes.c_int(aggregation_function)),
                                                              ctypes.pointer(b))

    return Array(array_reference=b)
Пример #18
0
def lls(a, b):
    """ Calculates the minimum norm least squares solution :math:`x` :math:`(||A·x - b||^2)` to :math:`A·x = b`. This
    function uses the singular value decomposition function of Arrayfire. The actual formula that this function computes
    is :math:`x = V·D\\dagger·U^T·b`. Where :math:`U` and :math:`V` are orthogonal matrices and :math:`D\\dagger` contains
    the inverse values of the singular values contained in :math:`D` if they are not zero, and zero otherwise.

    :param a: KHIVA array with the coefficients of the linear equation problem to solve. It accepts a list of lists or
              a numpy array with one or several time series.
    :param b: KHIVA array with the measured values.
    :return: KHIVA array with the solution to the linear equation problem minimizing the norm 2.
    """
    c = ctypes.c_void_p(0)
    error_code = ctypes.c_int(0)
    error_message = ctypes.create_string_buffer(KHIVA_ERROR_LENGTH)
    KhivaLibrary().c_khiva_library.lls(ctypes.pointer(a.arr_reference),
                                       ctypes.pointer(b.arr_reference),
                                       ctypes.pointer(c),
                                       ctypes.pointer(error_code),
                                       error_message)
    if error_code.value != 0:
        raise Exception(str(error_message.value.decode()))

    return Array(array_reference=c)
Пример #19
0
def sax(a, alphabet_size):
    """ Symbolic Aggregate approXimation (SAX). It transforms a numeric time series into a time series of symbols with
    the same size. The algorithm was proposed by Lin et al.) and extends the PAA-based approach inheriting the original
    algorithm simplicity and low computational complexity while providing satisfactory sensitivity and selectivity in
    range query processing. Moreover, the use of a symbolic representation opened a door to the existing wealth of
    data-structures and string-manipulation algorithms in computer science such as hashing, regular expression, pattern
    matching, suffix trees, and grammatical inference.

    [1] Lin, J., Keogh, E., Lonardi, S. & Chiu, B. (2003) A Symbolic Representation of Time Series, with Implications
    for Streaming Algorithms. In proceedings of the 8th ACM SIGMOD Workshop on Research Issues in Data Mining and
    Knowledge Discovery. San Diego, CA. June 13.

    :param a: KHIVA array with the input time series.
    :param alphabet_size: Number of element within the alphabet.

    :return: KHIVA array of points with the reduced dimensionality.
    """
    b = ctypes.c_void_p(0)
    KhivaLibrary().c_khiva_library.sax(
        ctypes.pointer(a.arr_reference),
        ctypes.pointer(ctypes.c_int(alphabet_size)), ctypes.pointer(b))

    return Array(array_reference=b)
 def test_polyfit3(self):
     polyfit_result = polyfit(Array.from_list([0.0, 1.0, 2.0, 3.0, 4.0, 5.0], dtype.f32), Array.from_list([0.0, 0.8, 0.9, 0.1, -0.8, -1.0], dtype.f32),
                              3).to_numpy()
     expected = np.array([0.08703704, -0.81349206, 1.69312169, -0.03968254])
     np.testing.assert_array_almost_equal(
         polyfit_result, expected, decimal=self.DECIMAL - 1)
 def test_roots(self):
     roots_result = roots(Array.from_list(
         [5, -20, 5, 50, -20, -40], dtype.s32)).to_numpy()
     expected = np.array([2 + 0j, 2 + 0j, 2 + 0j, -1 + 0j, -1 + 0j])
     np.testing.assert_array_almost_equal(roots_result, expected, decimal=2)
Пример #22
0
 def test_complex64_1d(self):
     a = Array(np.array([1 + 5j, 2 + 6j, 3 + 7j, 4 + 8j]).astype(np.complex64), khiva_type=dtype.c32)
     expected = np.array([1 + 5j, 2 + 6j, 3 + 7j, 4 + 8j]).astype(np.complex64)
     np.testing.assert_array_equal(a.to_numpy(), expected)
 def test_polyfit1(self):
     polyfit_result = polyfit(Array.from_list([0, 1, 2, 3, 4, 5], dtype.f32), Array.from_list(
         [0, 1, 2, 3, 4, 5], dtype.f32), 1).to_numpy()
     expected = np.array([1.0, 0.0])
     np.testing.assert_array_almost_equal(
         polyfit_result, expected, decimal=self.DECIMAL)
Пример #24
0
 def test_real_3d_large_column(self):
     a = Array([[[1, 5, 3], [2, 6, 9]], [[3, 7, 4], [4, 8, 1]]])
     expected = np.array([[[1, 5, 3], [2, 6, 9]], [[3, 7, 4], [4, 8, 1]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Пример #25
0
 def test_real_4d(self):
     a = Array([[[[1, 9], [2, 10]], [[3, 11], [4, 12]]], [[[5, 13], [6, 14]], [[7, 15], [8, 16]]]])
     expected = np.array([[[[1, 9], [2, 10]], [[3, 11], [4, 12]]], [[[5, 13], [6, 14]], [[7, 15], [8, 16]]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Пример #26
0
 def test_real_3d(self):
     a = Array([[[1, 5], [2, 6]], [[3, 7], [4, 8]]])
     expected = np.array([[[1, 5], [2, 6]], [[3, 7], [4, 8]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Пример #27
0
 def test_real_3d_creation(self):
     a = Array([[[1, 5, 3, 1], [2, 6, 9, 8], [3, 4, 1, 3]],
                [[3, 7, 4, 2], [4, 8, 1, 9], [1, 5, 9, 2]]])
     np.testing.assert_array_equal(a.dims, np.array([4, 3, 2, 1]))
Пример #28
0
 def test_real_2d(self):
     a = Array([[1, 2, 3, 4], [5, 6, 7, 8]])
     expected = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Пример #29
0
 def test_real_2d_creation(self):
     a = Array([[1, 5, 3, 1], [2, 6, 9, 8], [3, 4, 1, 3]])
     np.testing.assert_array_equal(a.dims, np.array([4, 3, 1, 1]))
Пример #30
0
 def testToList1(self):
     a = Array([1])
     self.assertIs(type(a.to_list()), list)
     self.assertEqual(a.to_list()[0], 1)