Esempio n. 1
0
def f():
    """
    Self-contained profile function for this library

    Compares cython array sum vs. numpy.sum vs. pure python implementation

    Can be used to identify possible areas to re-write as c/c++ extensions
    """
    import numpy as np
    from cython_example_proj import array_sum

    def array_sum2(A):
        m, n = A.shape
        result = 0
        for i in range(n):
            for j in range(n):
                result += A[i, j]

    A = np.random.randn(5000, 5000)
    array_sum(A)
    A.sum()
    array_sum2(A)
    def test_array_sum(self):

        A = np.random.randn(500, 500)
        result = array_sum(A)
        self.assertAlmostEqual(A.sum(), result)
Esempio n. 3
0
            results[idx + 1, 3:6] = this_pt
            results[idx + 1, 6:9] = bottom_left
            results[idx + 1, 9:] = bottom_right

    return results


if __name__ == "__main__":

    A = np.random.randn(5000, 5000)
    print(59 * "-")
    print("Initialized array for sum; starting comparison:")
    print(59 * "-")

    t = time.time()
    array_sum(A)
    print("cython finished :", time.time() - t, "s")

    t = time.time()
    A.sum()
    print("numpy finished :", time.time() - t, "s")

    t = time.time()
    array_sum_python(A)
    print("python finished :", time.time() - t, "s")

    print()

    A = np.random.randn(1024, 1024)
    print(59 * "-")
    print("Initialized array for tessellate; starting comparison:")
Esempio n. 4
0
    def test_array_sum(self):

        A = np.random.randn(500, 500)
        result = array_sum(A)
        self.assertAlmostEqual(A.sum(), result)
            results[idx, 9:] = bottom_right
            results[idx + 1, 3:6] = this_pt
            results[idx + 1, 6:9] = bottom_left
            results[idx + 1, 9:] = bottom_right

    return results

if __name__ == "__main__":

    A = np.random.randn(5000, 5000)
    print(59 * "-")
    print("Initialized array for sum; starting comparison:")
    print(59 * "-")

    t = time.time()
    array_sum(A)
    print("cython finished :", time.time() - t, "s")

    t = time.time()
    A.sum()
    print("numpy finished :", time.time() - t, "s")

    t = time.time()
    array_sum_python(A)
    print("python finished :", time.time() - t, "s")

    print()

    A = np.random.randn(1024, 1024)
    print(59 * "-")
    print("Initialized array for tessellate; starting comparison:")