[Python] How to enable and disable Intel MKL in numpy Python?

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I want to test and compare Numpy matrix multiplication and Eigen decomposition performance with Intel MKL and without Intel MKL.

    I have installed MKL using pip install mkl (Windows 10 (64-bit), Python 3.8).

    I then used examples from here for matmul and eigen decompositions.

    How do I now enable and disable MKL in order to check numpy performance with MKL and without it?

    Reference code:

    import numpy as np
    from time import time

    def matrix_mul(size, n=100):
    # reference: https://markus-beuckelmann.de/blog/boosting-numpy-blas.html
    np.random.seed(112)
    a, b = np.random.random((size, size)), np.random.random((size, size))
    t = time()
    for _ in range(n):
    np.dot(a, b)
    delta = time() - t
    print('Dotted two matrices of size %dx%d in %0.4f ms.' % (size, size, delta / n * 1000))


    def eigen_decomposition(size, n=10):
    np.random.seed(112)
    a = np.random.random((size, size))
    t = time()
    for _ in range(n):
    np.linalg.eig(a)
    delta = time() - t
    print('Eigen decomposition of size %dx%d in %0.4f ms.' % (size, size, delta / n * 1000))

    #Obtaining computation times:

    for i in range(20):
    eigen_decomposition(500)

    for i in range(20):
    matrix_mul(500)

    Continue reading...

Compartilhe esta Página