Exemplo n.º 1
0
def get_infos():
    import numpy
    from numpy.distutils.system_info import get_info
    # Print out full BLAS / LAPACK linkage info.
    numpy.show_config()
    if env_lib_dirs or env_libs:
        print('using environment variables for blas/lapack libraries')
        env_vars = {}
        if env_lib_dirs:
            env_vars['library_dirs'] = [env_lib_dirs]
        if env_libs:
            env_vars['libraries'] = env_libs.split(':')
        return env_vars, {}

    # environment variables not set, using defaults instead
    blas_info = get_info('blas_opt')
    if not blas_info:
        blas_info = get_info('blas')
    print(blas_info)

    lapack_info = get_info('lapack_opt')
    if not lapack_info:
        lapack_info = get_info('lapack')
    print(lapack_info)

    return blas_info, lapack_info
Exemplo n.º 2
0
def main():
    subtitle(multiprocessing)
    print "multiprocessing.cpu_count(): {}".format(multiprocessing.cpu_count())

    subtitle(np)
    np.show_config()

    subtitle(os)
    print_dictionary("os.environ", os.environ, [
        'BOOST_NUMPY_LIB', 'HOME', 'LIBRARY_PATH', 'PI_HOME', 'PYENV_ROOT',
        'PYTHONPATH', 'SHERLOCK'
    ])
    print "os.getcwd(): {}".format(os.getcwd())
    print "os.uname(): {}".format(os.uname())

    subtitle(scipy)
    scipy.__config__.show()

    subtitle(sys)
    print "sys.platform: {}".format(sys.platform)
    print "sys.prefix: {}".format(sys.prefix)
    print "sys.version: {}".format(sys.version)
    print "sys.api_version: {}".format(sys.api_version)
    print "sys.version_info: {}".format(sys.version_info)
    print
Exemplo n.º 3
0
def get_numpy_info():
    """
    Retrieves information about numpy compilation.
    """
    s = io.StringIO()
    with contextlib.redirect_stdout(s):
        numpy.show_config()
    return s.getvalue()
Exemplo n.º 4
0
def execute(execute=True, verbose=True, M=2000, N=2000, K=2000,
            iters=10, order='C'):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    a = theano.shared(numpy.ones((M, N), dtype=theano.config.floatX,
                                 order=order))
    b = theano.shared(numpy.ones((N, K), dtype=theano.config.floatX,
                                 order=order))
    c = theano.shared(numpy.ones((M, K), dtype=theano.config.floatX,
                                 order=order))
    f = theano.function([], updates={c: 0.4 * c + .8 * T.dot(a, b)})

    if verbose:
        print 'Some Theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print 'Some environment variables:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print ('Numpy config: (used when the Theano flag'
               ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy location:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        print
    t0 = 0
    t1 = -1

    if any([x.op.__class__.__name__ == 'Gemm' for x in
            f.maker.env.toposort()]):
        impl = 'cpu'
    elif any([x.op.__class__.__name__ == 'GpuGemm' for x in
              f.maker.env.toposort()]):
        impl = 'gpu'
    else:
        impl = 'ERROR, unable to tell if Theano used the cpu or the gpu:\n'
        impl += str(f.maker.env.toposort())

    if execute:
        t0 = time.time()
        for i in range(iters):
            f()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 5
0
def execute(execute=True, verbose=True):

    a = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))
    b = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))
    c = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))

    f = theano.function([], updates={c: 0.4 * c + .8 * T.dot(a, b)})

    if verbose:
        print 'Some theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print 'Some env flags:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print(
            'Numpy config: (used when the theano flags'
            ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy file location that was loaded:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        print
        if any([
                x.op.__class__.__name__ == 'Gemm'
                for x in f.maker.env.toposort()
        ]):
            print 'Used the cpu'
        elif any([
                x.op.__class__.__name__ == 'GpuGemm'
                for x in f.maker.env.toposort()
        ]):
            print 'Used the gpu'
        else:
            print 'ERROR, not able to tell if theano used the cpu or the gpu'
            print f.maker.env.toposort()
    t0 = 0
    t1 = -1

    if execute:
        t0 = time.time()
        for i in range(iters):
            f()
        t1 = time.time()
    if verbose and execute:
        print
        print 'This execution time took %.2fs' % (t1 - t0)
        print
        print(
            'Try to run this script a few times. Experience show that'
            ' the first time is not as fast as followings call. The'
            ' difference is not big, but consistent.')
    return t1 - t0
Exemplo n.º 6
0
def execute(execute=True, verbose=True, M=2000, N=2000, K=2000, iters=10, order="C"):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    if verbose:
        print "Some Theano flags:"
        print "    blas.ldflags=", theano.config.blas.ldflags
        print "    compiledir=", theano.config.compiledir
        print "    floatX=", theano.config.floatX
        print "Some environment variables:"
        print "    MKL_NUM_THREADS=", os.getenv("MKL_NUM_THREADS")
        print "    OMP_NUM_THREADS=", os.getenv("OMP_NUM_THREADS")
        print "    GOTO_NUM_THREADS=", os.getenv("GOTO_NUM_THREADS")
        print
        print ("Numpy config: (used when the Theano flag" ' "blas.ldflags" is empty)')
        numpy.show_config()
        print "Numpy dot module:", numpy.dot.__module__
        print "Numpy location:", numpy.__file__
        print "Numpy version:", numpy.__version__
        print

    a = theano.shared(numpy.ones((M, N), dtype=theano.config.floatX, order=order))
    b = theano.shared(numpy.ones((N, K), dtype=theano.config.floatX, order=order))
    c = theano.shared(numpy.ones((M, K), dtype=theano.config.floatX, order=order))
    f = theano.function([], updates={c: 0.4 * c + 0.8 * T.dot(a, b)}, mode=theano.compile.ProfileMode())

    if any([x.op.__class__.__name__ == "Gemm" for x in f.maker.env.toposort()]):
        c_impl = f.profile.apply_cimpl.values()
        assert len(c_impl) == 1
        if c_impl[0]:
            impl = "CPU (with direct Theano binding to blas)"
        else:
            impl = "CPU (without direct Theano binding to blas but with numpy/scipy binding to blas)"
    elif any([x.op.__class__.__name__ == "GpuGemm" for x in f.maker.env.toposort()]):
        impl = "GPU"
    else:
        impl = "ERROR, unable to tell if Theano used the cpu or the gpu:\n"
        impl += str(f.maker.env.toposort())

    t0 = 0
    t1 = -1

    if execute:
        t0 = time.time()
        for i in range(iters):
            f()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 7
0
def execute(execute=True, verbose=True):

    a = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))
    b = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))
    c = theano.shared(numpy.ones(shapes, dtype=theano.config.floatX))

    f = theano.function([], updates={c: 0.4 * c + .8 * T.dot(a, b)})

    if verbose:
        print 'Some theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print 'Some env flags:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print ('Numpy config: (used when the theano flags'
               ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy file location that was loaded:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        print
        if any([x.op.__class__.__name__ == 'Gemm' for x in
                f.maker.env.toposort()]):
            print 'Used the cpu'
        elif any([x.op.__class__.__name__ == 'GpuGemm' for x in
                  f.maker.env.toposort()]):
            print 'Used the gpu'
        else:
            print 'ERROR, not able to tell if theano used the cpu or the gpu'
            print f.maker.env.toposort()
    t0 = 0
    t1 = -1

    if execute:
        t0 = time.time()
        for i in range(iters):
            f()
        t1 = time.time()
    if verbose and execute:
        print
        print 'This execution time took %.2fs' % (t1 - t0)
        print
        print ('Try to run this script a few times. Experience show that'
               ' the first time is not as fast as followings call. The'
               ' difference is not big, but consistent.')
    return t1 - t0
Exemplo n.º 8
0
def print_system_info():

    log_msg('System information\n')
    log_msg('\tpython: ' + sys.version)
    log_msg('\tnumpy: ' + np.__version__)
    log_msg('\tpandas: ' + pd.__version__)

    # additional info about numpy libraries
    if False:
        old_stdout = sys.stdout
        result = StringIO()
        sys.stdout = result
        np.show_config()
        sys.stdout = old_stdout
        log_msg(result.getvalue())
Exemplo n.º 9
0
def getBlas():
    file_ = open("npConfg_file.txt", "w")
    with contextlib.redirect_stdout(file_):
        numpy.show_config()
    file_.close()
    np_confg = open('npConfg_file.txt', 'r')
    lib = ""
    for line in np_confg:
        if 'libraries' in line:
            lib = line
            break
    np_confg.close()
    os.remove("npConfg_file.txt")
    if lib != "":
        blas = lib.split('[')[1].split(',')[0]
        return blas[1:len(blas) - 1]

    return lib
Exemplo n.º 10
0
def print_system_info():

    log_msg('System information\n')
    log_msg(f'\tlocal time zone: {datetime.utcnow().astimezone().tzinfo}')
    log_msg(f'\tpython: {sys.version}')
    log_msg(f'\tnumpy: {np.__version__}')
    log_msg(f'\tpandas: {pd.__version__}')

    # additional info about numpy libraries
    if False:
        from io import StringIO  # only import this when actually needed

        old_stdout = sys.stdout
        result = StringIO()
        sys.stdout = result
        np.show_config()
        sys.stdout = old_stdout
        log_msg(result.getvalue())
Exemplo n.º 11
0
def _get_numpy_libs():
    from ._testing import SilenceStdout
    with SilenceStdout() as capture:
        np.show_config()
    lines = capture.getvalue().split('\n')
    libs = []
    for li, line in enumerate(lines):
        for key in ('lapack', 'blas'):
            if line.startswith('%s_opt_info' % key):
                lib = lines[li + 1]
                if 'NOT AVAILABLE' in lib:
                    lib = 'unknown'
                else:
                    try:
                        lib = lib.split('[')[1].split("'")[1]
                    except IndexError:
                        pass  # keep whatever it was
                libs += ['%s=%s' % (key, lib)]
    libs = ', '.join(libs)
    return libs
Exemplo n.º 12
0
def main():
    print('numpy config (python 3.7 image):')
    print(numpy.__version__)
    print(numpy.show_config())
    print('')

    print('scipy config:')
    print(scipy.__version__)
    print(scipy.show_config())
    print('')

    return 0
Exemplo n.º 13
0
def main():
    print('numpy config (miniconda:4.6.14 image):')
    print(numpy.__version__)
    print(numpy.show_config())
    print('')

    print('scipy config:')
    print(scipy.__version__)
    print(scipy.show_config())
    print('')

    return 0
Exemplo n.º 14
0
 def find_parameter(self):
     for i in range(0, 10):
         print(i)
         temp = (self.Y == i).astype(np.float64)
         temp_test = (self.Y_test == i).astype(np.float64)
         self.regr.fit(self.X, temp)
         self.theta1 = self.regr.coef_
         intercept = self.regr.intercept_
         self.theta[:,i] = np.column_stack((intercept, self.theta1))
         self.score = self.regr.score(self.X_test, temp_test)
         print(self.score)
     print(np.show_config())
     np.savetxt("parameter.txt",self.theta,delimiter=',',newline='\n')
Exemplo n.º 15
0
def _get_numpy_libs():
    "Return info on 'Blas/Lapack' lib linked to numpy."

    # Import is nested to avoid long import time.
    import numpy as np

    with contextlib.redirect_stdout(io.StringIO()) as capture:
        np.show_config()
    lines = capture.getvalue().splitlines()
    libs = []
    for li, line in enumerate(lines):
        for key in ("lapack", "blas"):
            if line.startswith(f"{key}_opt_info"):
                lib = lines[li + 1]
                if "NOT AVAILABLE" in lib:
                    lib = "unknown"
                else:
                    try:
                        lib = lib.split("[")[1].split("'")[1]
                    except IndexError:
                        pass  # keep whatever it was
                libs += [f"{key}={lib}"]
    libs = ", ".join(libs)
    return libs
Exemplo n.º 16
0
def numpy_version_and_config():
    # Task 2: Print numpy version and config
    print(f"Task 2: {np.__version__}, type: {type(np.__version__)}")
    np.show_config()
Exemplo n.º 17
0
import numpy as np


print(np.__version__)
np.show_config()        # include openblas atlas etc.

foo = np.zeros((10,10))     # float64, 8 bytes
print("%d bytes" % (foo.size * foo.itemsize))   # 800

np.info(np.add)

np.arange(10, 50)

nz = np.nonzero([1,2,0,0,4,0])
print nz

np.eye(3,4)
# array([[ 1.,  0.,  0.,  0.],
#        [ 0.,  1.,  0.,  0.],
#        [ 0.,  0.,  1.,  0.]])

foo = np.random.random((3, 3))
foo.min()
foo.max()

foo = np.ones((5,5))
foo = np.pad(foo, pad_width=1, mode='constant', constant_values=0)
print(foo)

print(0.3 == 3 * 0.1)   # False
# 3*0.1 = 0.30000000000000004
Exemplo n.º 18
0
import numpy as np  
import time   
N = 6000  
M = 10000  
  
k_list = [64, 80, 96, 104, 112, 120, 128, 144, 160, 176, 192, 200, 208, 224, 240, 256, 384]  
  
def get_gflops(M, N, K):  
    return M*N*(2.0*K-1.0) / 1000**3  
  
np.show_config()  
  
for K in k_list:  
    a = np.array(np.random.random((M, N)), dtype=np.double, order='C', copy=False)  
    b = np.array(np.random.random((N, K)), dtype=np.double, order='C', copy=False)  
    A = np.matrix(a, dtype=np.double, copy=False)  
    B = np.matrix(b, dtype=np.double, copy=False)  
  
    C = A*B  
  
    start = time.time()  
  
    C = A*B  
    C = A*B  
    C = A*B  
    C = A*B  
    C = A*B  
  
    end = time.time()  
  
    tm = (end-start) / 5.0  
Exemplo n.º 19
0
def execute(execute=True, verbose=True, M=2000, N=2000, K=2000,
            iters=10, order='C'):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    if verbose:
        print 'Some Theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print '    device=', theano.config.device
        print 'Some OS information:'
        print '    sys.platform=', sys.platform
        print '    sys.version=', sys.version
        print '    sys.prefix=', sys.prefix
        print 'Some environment variables:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print ('Numpy config: (used when the Theano flag'
               ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy location:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        if (theano.config.device.startswith("gpu") or
            theano.config.init_gpu_device.startswith("gpu")):
            print 'nvcc version:'
            subprocess.call((theano.sandbox.cuda.nvcc_compiler.nvcc_path,
                             "--version"))
            print

    a = theano.shared(numpy.ones((M, N), dtype=theano.config.floatX,
                                 order=order))
    b = theano.shared(numpy.ones((N, K), dtype=theano.config.floatX,
                                 order=order))
    c = theano.shared(numpy.ones((M, K), dtype=theano.config.floatX,
                                 order=order))
    f = theano.function([], updates=[(c, 0.4 * c + .8 * T.dot(a, b))])

    if any([x.op.__class__.__name__ == 'Gemm' for x in
            f.maker.fgraph.toposort()]):
        c_impl = [hasattr(thunk, 'cthunk')
                  for node, thunk in zip(f.fn.nodes, f.fn.thunks)
                  if node.op.__class__.__name__ == "Gemm"]
        assert len(c_impl) == 1
        if c_impl[0]:
            impl = 'CPU (with direct Theano binding to blas)'
        else:
            impl = 'CPU (without direct Theano binding to blas but with numpy/scipy binding to blas)'
    elif any([x.op.__class__.__name__ == 'GpuGemm' for x in
              f.maker.fgraph.toposort()]):
        impl = 'GPU'
    else:
        impl = 'ERROR, unable to tell if Theano used the cpu or the gpu:\n'
        impl += str(f.maker.fgraph.toposort())

    t0 = 0
    t1 = -1

    if execute:
        sync = (hasattr(theano, "sandbox") and
                hasattr(theano.sandbox, "cuda") and
                theano.sandbox.cuda.cuda_available)
        t0 = time.time()
        for i in range(iters):
            f()
        if sync:
            theano.sandbox.cuda.synchronize()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 20
0
import os
import re
import subprocess
import numpy

numpy_root = os.path.dirname(numpy.__file__)
print "numpy root:", numpy_root

print
print "##### core files #####"
numpy_core = os.path.join(numpy_root, "core")
core_files = sorted(os.listdir(numpy_core))
for filename in core_files:
    print filename


print
print "##### numpy packages #####"
process = subprocess.Popen("dpkg --get-selections".split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
for line in output.split("\n"):
    if line.find("numpy") >= 0:
        print line

print
print "##### numpy.show_config() #####"
print numpy.show_config()
Exemplo n.º 21
0
    which += [('matplotlib')]
    which += [('tables')]

    which += [('contracts')]
    which += [('geometry')]
    which += [('compmake')]
    which += [('reprep')]

    which += [('procgraph')]
    which += [('playerc')]
    which += [('patience')]
    which += [('cjson')]
    which += [('PIL')]
    which += [('Image')]
    which += [('cv')]
    which += [('pyparsing')]
    which += [('decorator')]
    which += [('nose')]
    which += [('cairo')]

for x in which:
    show_version(x)
#show_version('flydra.version', lambda m: m.__version__) #lambda m: m.version.version)

if False:
    try:
        import numpy
        numpy.show_config()
    except:
        pass
Exemplo n.º 22
0
def run_numpy_tests(*args, **kwargs):
    import numpy

    numpy.show_config()
    numpy.test()
Exemplo n.º 23
0
def sys_info(fid=None, show_paths=False):
    """Print the system information for debugging.

    This function is useful for printing system information
    to help triage bugs.

    Parameters
    ----------
    fid : file-like | None
        The file to write to. Will be passed to :func:`print()`.
        Can be None to use :data:`sys.stdout`.
    show_paths : bool
        If True, print paths for each module.

    Examples
    --------
    Running this function with no arguments prints an output that is
    useful when submitting bug reports::

        >>> import mne
        >>> mne.sys_info() # doctest: +SKIP
        Platform:      Linux-4.2.0-27-generic-x86_64-with-Ubuntu-15.10-wily
        Python:        2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
        Executable:    /usr/bin/python

        mne:           0.12.dev0
        numpy:         1.12.0.dev0+ec5bd81 {lapack=mkl_rt, blas=mkl_rt}
        scipy:         0.18.0.dev0+3deede3
        matplotlib:    1.5.1+1107.g1fa2697

        sklearn:       0.18.dev0
        nibabel:       2.1.0dev
        mayavi:        4.3.1
        cupy:          4.1.0
        pandas:        0.17.1+25.g547750a
        dipy:          0.14.0

    """  # noqa: E501
    ljust = 15
    out = 'Platform:'.ljust(ljust) + platform.platform() + '\n'
    out += 'Python:'.ljust(ljust) + str(sys.version).replace('\n', ' ') + '\n'
    out += 'Executable:'.ljust(ljust) + sys.executable + '\n'
    out += 'CPU:'.ljust(ljust) + ('%s: ' % platform.processor())
    try:
        import multiprocessing
    except ImportError:
        out += ('number of processors unavailable ' +
                '(requires "multiprocessing" package)\n')
    else:
        out += '%s cores\n' % multiprocessing.cpu_count()
    out += 'Memory:'.ljust(ljust)
    try:
        import psutil
    except ImportError:
        out += 'Unavailable (requires "psutil" package)'
    else:
        out += '%0.1f GB\n' % (psutil.virtual_memory().total / float(2**30), )
    out += '\n'
    old_stdout = sys.stdout
    capture = StringIO()
    try:
        sys.stdout = capture
        np.show_config()
    finally:
        sys.stdout = old_stdout
    lines = capture.getvalue().split('\n')
    libs = []
    for li, line in enumerate(lines):
        for key in ('lapack', 'blas'):
            if line.startswith('%s_opt_info' % key):
                lib = lines[li + 1]
                if 'NOT AVAILABLE' in lib:
                    lib = 'unknown'
                else:
                    try:
                        lib = lib.split('[')[1].split("'")[1]
                    except IndexError:
                        pass  # keep whatever it was
                libs += ['%s=%s' % (key, lib)]
    libs = ', '.join(libs)
    for mod_name in ('mne', 'numpy', 'scipy', 'matplotlib', '', 'sklearn',
                     'nibabel', 'mayavi', 'cupy', 'pandas', 'dipy'):
        if mod_name == '':
            out += '\n'
            continue
        out += ('%s:' % mod_name).ljust(ljust)
        try:
            mod = __import__(mod_name)
            if mod_name == 'mayavi':
                # the real test
                from mayavi import mlab  # noqa, analysis:ignore
        except Exception:
            out += 'Not found\n'
        else:
            extra = (' (%s)' % op.dirname(mod.__file__)) if show_paths else ''
            if mod_name == 'numpy':
                extra = ' {%s}%s' % (libs, extra)
            elif mod_name == 'matplotlib':
                extra = ' {backend=%s}%s' % (mod.get_backend(), extra)
            elif mod_name == 'mayavi':
                try:
                    from pyface.qt import qt_api
                except Exception:
                    qt_api = 'unknown'
                if qt_api == 'pyqt5':
                    try:
                        from PyQt5.Qt import PYQT_VERSION_STR
                        qt_api += ', PyQt5=%s' % (PYQT_VERSION_STR, )
                    except Exception:
                        pass
                extra = ' {qt_api=%s}%s' % (qt_api, extra)
            out += '%s%s\n' % (mod.__version__, extra)
    print(out, end='', file=fid)
#!/usr/bin/env python
import numpy as np
from mnist_numpy import read_mnist
from nnet_toolkit import nnet
import cluster_select_func as csf
from autoconvert import autoconvert
import sys
import time

#h5py used for saving results to a file
import h5py

print(str(np.show_config()))

#constants
MODE_P1 = 0
MODE_P2 = 1

#Get the parameters file from the command line
#use mnist_train__forget_params.py by default (no argument given)
if(len(sys.argv) > 1):
    params_file = sys.argv[1]
else:
    params_file = 'mnist_train_nonstationary_cluster_subset_params.py'
    
p = {}
execfile(params_file,p)

#grab extra parameters from command line
for i in range(2,len(sys.argv)):
    (k,v) = sys.argv[i].split('=')
Exemplo n.º 25
0
# numpy program to get the numpy version and show numpy build configuration
import numpy as np
print("Numpy version : ", np.__version__)
print("Numpy configuration : ", np.show_config())
'''
Numpy version :  1.18.4
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
    libraries = ['openblas_info']
    language = f77
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
    libraries = ['openblas_info']
    language = f77
    define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
    libraries = ['openblas_lapack_info']
    language = f77
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
    libraries = ['openblas_lapack_info']
    language = f77
Exemplo n.º 26
0
#! usr/bin/env python3
# Filename: 100NumpyExercises.py

__author__ = 'Jerome Yao'
'''

'''

# 1. Import the numpy package under the name np (★☆☆)
import numpy as np

# 2. Print the numpy version and the configuration (★☆☆)
print('#2:\n', np.__version__)
np.show_config()  # other way

# 3. Create a null vector of size 10 (★☆☆)
print('#3:\n', np.zeros(10))

# 4. How to find the memory size of any array (★☆☆)
array = np.zeros((10, 10))
print('#4:\n', '%d bytes' % (array.size * array.itemsize))  # 800bytes

# 待解决5. How to get the documentation of the numpy add function from the command line? (★☆☆)  ##
# %run `python -c "import numpy; numpy.info(numpy.add)"`

# 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)
vector = np.zeros(10)
vector[4] = 1
print('#6:\n', vector)

# 7. Create a vector with values ranging from 10 to 49 (★☆☆)
Exemplo n.º 27
0
def execute(execute=True,
            verbose=True,
            M=2000,
            N=2000,
            K=2000,
            iters=10,
            order='C'):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    a = theano.shared(
        numpy.ones((M, N), dtype=theano.config.floatX, order=order))
    b = theano.shared(
        numpy.ones((N, K), dtype=theano.config.floatX, order=order))
    c = theano.shared(
        numpy.ones((M, K), dtype=theano.config.floatX, order=order))
    f = theano.function([], updates={c: 0.4 * c + .8 * T.dot(a, b)})

    if verbose:
        print 'Some Theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print 'Some environment variables:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print(
            'Numpy config: (used when the Theano flag'
            ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy location:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        print
    t0 = 0
    t1 = -1

    if any([x.op.__class__.__name__ == 'Gemm'
            for x in f.maker.env.toposort()]):
        impl = 'cpu'
    elif any(
        [x.op.__class__.__name__ == 'GpuGemm'
         for x in f.maker.env.toposort()]):
        impl = 'gpu'
    else:
        impl = 'ERROR, unable to tell if Theano used the cpu or the gpu:\n'
        impl += str(f.maker.env.toposort())

    if execute:
        t0 = time.time()
        for i in range(iters):
            f()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 28
0
import numpy as np

print(np.__version__)
np.show_config()  # include openblas atlas etc.

foo = np.zeros((10, 10))  # float64, 8 bytes
print("%d bytes" % (foo.size * foo.itemsize))  # 800

np.info(np.add)

np.arange(10, 50)

nz = np.nonzero([1, 2, 0, 0, 4, 0])
print nz

np.eye(3, 4)
# array([[ 1.,  0.,  0.,  0.],
#        [ 0.,  1.,  0.,  0.],
#        [ 0.,  0.,  1.,  0.]])

foo = np.random.random((3, 3))
foo.min()
foo.max()

foo = np.ones((5, 5))
foo = np.pad(foo, pad_width=1, mode='constant', constant_values=0)
print(foo)

print(0.3 == 3 * 0.1)  # False
# 3*0.1 = 0.30000000000000004
Exemplo n.º 29
0
    if sys.argv[3] == "--preprocess-ref":
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = True;
    elif sys.argv[3] == "--process-query-and-align-videos":
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = False;
    else:
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = "do_all";

    print("config.PREPROCESS_REFERENCE_VIDEO_ONLY = %s" % str(config.PREPROCESS_REFERENCE_VIDEO_ONLY));

    AskFirst();

    # Inspired from https://stackoverflow.com/questions/1520234/how-to-check-which-version-of-numpy-im-using
    print("numpy.version.version = %s" % str(np.version.version));
    print("scipy.version.version = %s" % str(scipy.version.version));
    #scipy.version.version
    np.show_config();
    scipy.show_config();


    # See http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
    # We use 7 digits precision and suppress using scientific notation.
    np.set_printoptions(precision=7, suppress=True, \
                        threshold=70000, linewidth=4000);
                        #threshold=7000000, linewidth=4000);
                        #threshold=7000, linewidth=300);
                        #threshold=1000000, linewidth=3000);


    # Inspired from \OpenCV2-Python-Tutorials-master\source\py_tutorials\py_core\py_optimization

    # normally returns True - relates to using the SIMD extensions of x86: SSX, AVX
    which += [('tables')]

    which += [('contracts')]
    which += [('geometry')]
    which += [('compmake')]
    which += [('reprep')]

    which += [('procgraph')]
    which += [('playerc')]
    which += [('patience')]
    which += [('cjson')]
    which += [('PIL')]
    which += [('Image')]
    which += [('cv')]
    which += [('pyparsing')]
    which += [('decorator')]
    which += [('nose')]
    which += [('cairo')]

for x in which:
    show_version(x)
#show_version('flydra.version', lambda m: m.__version__) #lambda m: m.version.version)

if False:
    try: 
        import numpy;
        numpy.show_config()
    except:
        pass
    
Exemplo n.º 31
0
#! usr/bin/env python3
# Filename: 100NumpyExercises.py

__author__ = 'Jerome Yao'
'''

'''

# 1. Import the numpy package under the name np (★☆☆)
import numpy as np

# 2. Print the numpy version and the configuration (★☆☆)
print('#2:\n', np.__version__)
np.show_config()  # other way

# 3. Create a null vector of size 10 (★☆☆)
print('#3:\n', np.zeros(10))

# 4. How to find the memory size of any array (★☆☆)
array = np.zeros((10, 10))
print('#4:\n', '%d bytes' % (array.size * array.itemsize))  # 800bytes

# 待解决5. How to get the documentation of the numpy add function from the command line? (★☆☆)  ##
# %run `python -c "import numpy; numpy.info(numpy.add)"`

# 6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)
vector = np.zeros(10)
vector[4] = 1
print('#6:\n', vector)

# 7. Create a vector with values ranging from 10 to 49 (★☆☆)
Exemplo n.º 32
0
    if sys.argv[3] == "--preprocess-ref":
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = True;
    elif sys.argv[3] == "--process-query-and-align-videos":
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = False;
    else:
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = "do_all";

    print("config.PREPROCESS_REFERENCE_VIDEO_ONLY = %s" % str(config.PREPROCESS_REFERENCE_VIDEO_ONLY));

    AskFirst();

    # Inspired from https://stackoverflow.com/questions/1520234/how-to-check-which-version-of-numpy-im-using
    print("numpy.version.version = %s" % str(np.version.version));
    print("scipy.version.version = %s" % str(scipy.version.version));
    #scipy.version.version
    np.show_config();
    scipy.show_config();


    # See http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
    # We use 7 digits precision and suppress using scientific notation.
    np.set_printoptions(precision=7, suppress=True, \
                        threshold=70000, linewidth=4000);
                        #threshold=7000000, linewidth=4000);
                        #threshold=7000, linewidth=300);
                        #threshold=1000000, linewidth=3000);


    # Inspired from \OpenCV2-Python-Tutorials-master\source\py_tutorials\py_core\py_optimization

    # normally returns True - relates to using the SIMD extensions of x86: SSX, AVX
Exemplo n.º 33
0
def execute(execute=True,
            verbose=True,
            M=2000,
            N=2000,
            K=2000,
            iters=10,
            order='C'):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    if verbose:
        print 'Some Theano flags:'
        print '    blas.ldflags=', theano.config.blas.ldflags
        print '    compiledir=', theano.config.compiledir
        print '    floatX=', theano.config.floatX
        print '    device=', theano.config.device
        print 'Some OS information:'
        print '    sys.platform=', sys.platform
        print '    sys.version=', sys.version
        print '    sys.prefix=', sys.prefix
        print 'Some environment variables:'
        print '    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS')
        print '    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS')
        print '    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS')
        print
        print(
            'Numpy config: (used when the Theano flag'
            ' "blas.ldflags" is empty)')
        numpy.show_config()
        print 'Numpy dot module:', numpy.dot.__module__
        print 'Numpy location:', numpy.__file__
        print 'Numpy version:', numpy.__version__
        if (theano.config.device.startswith("gpu")
                or theano.config.init_gpu_device.startswith("gpu")):
            print 'nvcc version:'
            subprocess.call(
                (theano.sandbox.cuda.nvcc_compiler.nvcc_path, "--version"))
            print

    a = theano.shared(
        numpy.ones((M, N), dtype=theano.config.floatX, order=order))
    b = theano.shared(
        numpy.ones((N, K), dtype=theano.config.floatX, order=order))
    c = theano.shared(
        numpy.ones((M, K), dtype=theano.config.floatX, order=order))
    f = theano.function([], updates=[(c, 0.4 * c + .8 * T.dot(a, b))])

    if any(
        [x.op.__class__.__name__ == 'Gemm'
         for x in f.maker.fgraph.toposort()]):
        c_impl = [
            hasattr(thunk, 'cthunk')
            for node, thunk in zip(f.fn.nodes, f.fn.thunks)
            if node.op.__class__.__name__ == "Gemm"
        ]
        assert len(c_impl) == 1
        if c_impl[0]:
            impl = 'CPU (with direct Theano binding to blas)'
        else:
            impl = 'CPU (without direct Theano binding to blas but with numpy/scipy binding to blas)'
    elif any([
            x.op.__class__.__name__ == 'GpuGemm'
            for x in f.maker.fgraph.toposort()
    ]):
        impl = 'GPU'
    else:
        impl = 'ERROR, unable to tell if Theano used the cpu or the gpu:\n'
        impl += str(f.maker.fgraph.toposort())

    t0 = 0
    t1 = -1

    if execute:
        sync = (hasattr(theano, "sandbox") and hasattr(theano.sandbox, "cuda")
                and theano.sandbox.cuda.cuda_available)
        t0 = time.time()
        for i in range(iters):
            f()
        if sync:
            theano.sandbox.cuda.synchronize()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 34
0
def execute(execute=True, verbose=True, M=2000, N=2000, K=2000,
            iters=10, order='C'):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    if verbose:
        print('Some Theano flags:')
        print('    blas.ldflags=', theano.config.blas.ldflags)
        print('    compiledir=', theano.config.compiledir)
        print('    floatX=', theano.config.floatX)
        print('    device=', theano.config.device)
        print('Some OS information:')
        print('    sys.platform=', sys.platform)
        print('    sys.version=', sys.version)
        print('    sys.prefix=', sys.prefix)
        print('Some environment variables:')
        print('    MKL_NUM_THREADS=', os.getenv('MKL_NUM_THREADS'))
        print('    OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS'))
        print('    GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS'))
        print()
        print('Numpy config: (used when the Theano flag'
              ' "blas.ldflags" is empty)')
        np.show_config()
        print('Numpy dot module:', np.dot.__module__)
        print('Numpy location:', np.__file__)
        print('Numpy version:', np.__version__)

    a = theano.shared(np.ones((M, N), dtype=theano.config.floatX,
                              order=order))
    b = theano.shared(np.ones((N, K), dtype=theano.config.floatX,
                              order=order))
    c = theano.shared(np.ones((M, K), dtype=theano.config.floatX,
                              order=order))
    f = theano.function([], updates=[(c, 0.4 * c + .8 * T.dot(a, b))])

    if any([x.op.__class__.__name__ == 'Gemm' for x in
            f.maker.fgraph.toposort()]):
        c_impl = [hasattr(thunk, 'cthunk')
                  for node, thunk in zip(f.fn.nodes, f.fn.thunks)
                  if node.op.__class__.__name__ == "Gemm"]
        assert len(c_impl) == 1
        if c_impl[0]:
            impl = 'CPU (with direct Theano binding to blas)'
        else:
            impl = 'CPU (without direct Theano binding to blas but with numpy/scipy binding to blas)'
    elif any([x.op.__class__.__name__ == 'GpuGemm' for x in
              f.maker.fgraph.toposort()]):
        impl = 'GPU'
    else:
        impl = 'ERROR, unable to tell if Theano used the cpu or the gpu:\n'
        impl += str(f.maker.fgraph.toposort())

    t0 = 0
    t1 = -1

    f()  # Ignore first function call to get representative time.
    if execute:
        sync = (hasattr(theano, "gpuarray") and
                isinstance(c, theano.gpuarray.GpuArraySharedVariable))
        if sync:
            # Make sure we don't include the time from the first call
            c.get_value(borrow=True, return_internal_type=True).sync()
        t0 = time.time()
        for i in range(iters):
            f()
        if sync:
            c.get_value(borrow=True, return_internal_type=True).sync()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 35
0
 def task1(self):
     print(np.__version__)
     np.show_config()
Exemplo n.º 36
0
 def cache_info(cls):
     f = io.StringIO()
     with contextlib.redirect_stdout(f):
         np.show_config()
     cls._CACHE = f.getvalue()
Exemplo n.º 37
0
def main(argv):
    assert len(sys.argv) >= 3
    if FLAGS.preprocess_ref:
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = True
    elif FLAGS.process_query_and_align_videos:
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = False
    else:
        config.PREPROCESS_REFERENCE_VIDEO_ONLY = False

    print("config.PREPROCESS_REFERENCE_VIDEO_ONLY = %s" % str(
        config.PREPROCESS_REFERENCE_VIDEO_ONLY))

    ask_first()

    # Inspired from https://stackoverflow.com/questions/1520234/how-to-check-which-version-of-numpy-im-using
    print("numpy.version.version = %s" % str(np.version.version))
    print("scipy.version.version = %s" % str(scipy.version.version))
    np.show_config()
    scipy.show_config()

    # See http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html
    # We use 7 digits precision and suppress using scientific notation.
    np.set_printoptions(precision=7, suppress=True,
                        threshold=70000, linewidth=4000)

    # Inspired from \OpenCV2-Python-Tutorials-master\source\py_tutorials\py_core\py_optimization
    # normally returns True - relates to using the SIMD extensions of x86:
    # SSX, AVX
    common.DebugPrint("cv2.useOptimized() is %s" % str(cv2.useOptimized()))

    """
    From http://docs.opencv.org/modules/core/doc/utility_and_system_functions_and_macros.html#checkhardwaresupport
        CV_CPU_MMX - MMX
        CV_CPU_SSE - SSE
        CV_CPU_SSE2 - SSE 2
        CV_CPU_SSE3 - SSE 3
        CV_CPU_SSSE3 - SSSE 3
        CV_CPU_SSE4_1 - SSE 4.1
        CV_CPU_SSE4_2 - SSE 4.2
        CV_CPU_POPCNT - POPCOUNT
        CV_CPU_AVX - AVX
    """
    # TODO: Figure out the correct way to reference these in OpenCV 3.x
    """
    # Need to setUseOptimized before calling checkHardwareSupport
    cv2.setUseOptimized(True)
    if config.OCV_OLD_PY_BINDINGS == False:
        featDict = {cv2.CpuFeatures.CV_CPU_AVX: "AVX",
                cv2.CPU_MMX: "MMX",
                cv2.CPU_NEON: "NEON",
                cv2.CPU_POPCNT: "POPCNT",
                cv2.CPU_SSE: "SSE",
                cv2.CPU_SSE2: "SSE2",
                cv2.CPU_SSE3: "SSE3",
                cv2.CPU_SSE4_1: "SSE4.1",
                cv2.CPU_SSE4_2: "SSE4.2",
                cv2.CPU_SSSE3: "SSSE3"}

        for feat in featDict:
            res = cv2.checkHardwareSupport(feat)
            print("%s = %d" % (featDict[feat], res))
    """

    # "Returns the number of logical CPUs available for the process."
    common.DebugPrint("cv2.getNumberOfCPUs() (#logical CPUs) is %s" % str(
        cv2.getNumberOfCPUs()))
    common.DebugPrint(
        "cv2.getTickFrequency() is %s" % str(cv2.getTickFrequency()))

    video_file_q = sys.argv[1]  # input/current video
    video_file_r = sys.argv[2]  # reference video

    # TODO: use getopt() to run Evangelidis' or "Alex's" algorithm, etc

    ReadVideo.main(video_file_q, video_file_r)
Exemplo n.º 38
0
def benchmark_2d_ffts(mode='poppy', max_pow=13, verbose=False, savefig=False):
    """Benchmark FFT runtime vs array size, for multiple transform libraries

    Parameters
    ----------
    mode : string, 'poppy' or 'base'
        What to test, either the full poppy usage of the 2D transform, including
        surrounding setup and normalization code, or the basic transform on its own.
    max_pow : int
        Maximum power of 2 array size to test up to
    verbose : bool
        output numpy config info
    savefig : bool
        save plot result to a PDF?

    """

    # modified based on https://github.com/numpy/numpy/issues/17839#issuecomment-733543850


    try:
        from simple_benchmark import benchmark
    except ImportError:
        raise RuntimeError("You must have simple_benchmark installed to run this function")

    threads = multiprocessing.cpu_count()

    if mode == 'base':
        # Functions for benchmarking the low-level FFT functions in each library
        def pocketfft(it):
            np.fft.fft2(it)

        def scipyfft(it):
            scipy.fft.fft2(it)

        def fftw_1thread(it):
            # note, FFTW defaults to 1 thread, unless you override the config,
            # but that's not a fair comparison
            pyfftw.interfaces.numpy_fft.fft2(it, thread=1)

        def fftw(it):
            # explicitly try multithreaded here
            pyfftw.interfaces.numpy_fft.fft2(it, threads=threads)

        def mklfft(it):
            mkl_fft.fft2(it)

        funcs_to_test = [pocketfft, fftw, mklfft, scipyfft, fftw_1thread, ]
        function_aliases = {pocketfft: 'numpy.fft', fftw: 'pyfftw.fft, multithreaded', scipyfft: 'scipy.fft',
                            mklfft: "MKL FFT", fftw_1thread: 'pyfftw.fft, single-thread'}
        title = "Basic 2D FFT only"

    elif mode == 'poppy':
        # Functions for benchmarking poppy transforms using each library

        def poppy_numpyfft(it):
            global _USE_FFTW, _USE_MKL
            _USE_FFTW = False
            _USE_MKL = False

            fft_2d(it, fftshift=False)

        def poppy_fftw(it):
            global _USE_FFTW, _USE_MKL
            _USE_FFTW = True
            _USE_MKL = False

            fft_2d(it, fftshift=False)

        def poppy_mklfft(it):
            global _USE_FFTW, _USE_MKL
            _USE_FFTW = False
            _USE_MKL = True

            fft_2d(it, fftshift=False)

        funcs_to_test = [poppy_numpyfft, poppy_fftw, poppy_mklfft]
        function_aliases = {poppy_numpyfft: 'poppy using numpy.fft', poppy_fftw: 'poppy using pyfftw.fft',
                            poppy_mklfft: "poppy using MKL FFT"}
        title = 'full poppy.accel_math.fft_2d'
    else:
        raise ValueError(f"Unknown/invalid value for 'base' parameter: {base}")

    def shp(len):
        return (len, len)

    if verbose:
        print(np.version)
        np.show_config()

    # Turn on the cache for optimum performance
    pyfftw.interfaces.cache.enable()
    b_array = benchmark(
        funcs_to_test,
        arguments={2 ** i: np.random.uniform(size=shp(2 ** i)) + 1j * np.random.uniform(size=shp(2 ** i)) for i in
                   range(2, max_pow)},
        argument_name='array size',
        function_aliases=function_aliases
    )
    plt.figure(figsize=(12, 8))
    b_array.plot()
    plt.grid(which='both', alpha=0.2)
    plt.grid(which='major', alpha=0.5)
    plt.xlim(1, 2e4)
    plt.ylim(1e-6, 1e1)

    cpu_label = get_processor_name() + f", {get_physical_cpu_count()} cores"
    plt.title(f"Time for 2D complex FFTs: {title}\n{cpu_label}", fontweight='bold')
    if savefig:
        plt.savefig(f"bench_ffts_{mode}.png")
Exemplo n.º 39
0
def execute(execute=True, verbose=True, M=2000, N=2000, K=2000, iters=10, order="C"):
    """
    :param execute: If True, execute a Theano function that should call gemm.
    :param verbose: If True, will print some Theano flags and env variables.
    :param M,N,K: The M,N,K size used by gemm.
    :param iters: The number of calls to gemm to do.

    :return: a tuple (execution time,
                      str that represents the implementation used)
    """

    if verbose:
        print("Some Theano flags:")
        print("    blas.ldflags=", theano.config.blas.ldflags)
        print("    compiledir=", theano.config.compiledir)
        print("    floatX=", theano.config.floatX)
        print("    device=", theano.config.device)
        print("Some OS information:")
        print("    sys.platform=", sys.platform)
        print("    sys.version=", sys.version)
        print("    sys.prefix=", sys.prefix)
        print("Some environment variables:")
        print("    MKL_NUM_THREADS=", os.getenv("MKL_NUM_THREADS"))
        print("    OMP_NUM_THREADS=", os.getenv("OMP_NUM_THREADS"))
        print("    GOTO_NUM_THREADS=", os.getenv("GOTO_NUM_THREADS"))
        print()
        print("Numpy config: (used when the Theano flag" ' "blas.ldflags" is empty)')
        np.show_config()
        print("Numpy dot module:", np.dot.__module__)
        print("Numpy location:", np.__file__)
        print("Numpy version:", np.__version__)

    a = theano.shared(np.ones((M, N), dtype=theano.config.floatX, order=order))
    b = theano.shared(np.ones((N, K), dtype=theano.config.floatX, order=order))
    c = theano.shared(np.ones((M, K), dtype=theano.config.floatX, order=order))
    f = theano.function([], updates=[(c, 0.4 * c + 0.8 * tt.dot(a, b))])

    if any([x.op.__class__.__name__ == "Gemm" for x in f.maker.fgraph.toposort()]):
        c_impl = [
            hasattr(thunk, "cthunk")
            for node, thunk in zip(f.fn.nodes, f.fn.thunks)
            if node.op.__class__.__name__ == "Gemm"
        ]
        assert len(c_impl) == 1
        if c_impl[0]:
            impl = "CPU (with direct Theano binding to blas)"
        else:
            impl = "CPU (without direct Theano binding to blas but with numpy/scipy binding to blas)"
    elif any([x.op.__class__.__name__ == "GpuGemm" for x in f.maker.fgraph.toposort()]):
        impl = "GPU"
    else:
        impl = "ERROR, unable to tell if Theano used the cpu or the gpu:\n"
        impl += str(f.maker.fgraph.toposort())

    t0 = 0
    t1 = -1

    f()  # Ignore first function call to get representative time.
    if execute:
        sync = hasattr(theano, "gpuarray") and isinstance(
            c, theano.gpuarray.GpuArraySharedVariable
        )
        if sync:
            # Make sure we don't include the time from the first call
            c.get_value(borrow=True, return_internal_type=True).sync()
        t0 = time.time()
        for i in range(iters):
            f()
        if sync:
            c.get_value(borrow=True, return_internal_type=True).sync()
        t1 = time.time()
    return t1 - t0, impl
Exemplo n.º 40
0
def sys_info(fid=None, show_paths=False):
    """Print the system information for debugging.

    This function is useful for printing system information
    to help triage bugs.

    Parameters
    ----------
    fid : file-like | None
        The file to write to. Will be passed to :func:`print()`.
        Can be None to use :data:`sys.stdout`.
    show_paths : bool
        If True, print paths for each module.

    Examples
    --------
    Running this function with no arguments prints an output that is
    useful when submitting bug reports::

        >>> import mne
        >>> mne.sys_info() # doctest: +SKIP
        Platform:      Linux-4.2.0-27-generic-x86_64-with-Ubuntu-15.10-wily
        Python:        2.7.10 (default, Oct 14 2015, 16:09:02)  [GCC 5.2.1 20151010]
        Executable:    /usr/bin/python

        mne:           0.12.dev0
        numpy:         1.12.0.dev0+ec5bd81 {lapack=mkl_rt, blas=mkl_rt}
        scipy:         0.18.0.dev0+3deede3
        matplotlib:    1.5.1+1107.g1fa2697

        sklearn:       0.18.dev0
        nibabel:       2.1.0dev
        mayavi:        4.3.1
        cupy:          4.1.0
        pandas:        0.17.1+25.g547750a
        dipy:          0.14.0

    """  # noqa: E501
    ljust = 15
    out = 'Platform:'.ljust(ljust) + platform.platform() + '\n'
    out += 'Python:'.ljust(ljust) + str(sys.version).replace('\n', ' ') + '\n'
    out += 'Executable:'.ljust(ljust) + sys.executable + '\n'
    out += 'CPU:'.ljust(ljust) + ('%s: %s cores\n' %
                                  (platform.processor(),
                                   multiprocessing.cpu_count()))
    out += 'Memory:'.ljust(ljust)
    try:
        import psutil
    except ImportError:
        out += 'Unavailable (requires "psutil" package)'
    else:
        out += '%0.1f GB\n' % (psutil.virtual_memory().total / float(2 ** 30),)
    out += '\n'
    old_stdout = sys.stdout
    capture = StringIO()
    try:
        sys.stdout = capture
        np.show_config()
    finally:
        sys.stdout = old_stdout
    lines = capture.getvalue().split('\n')
    libs = []
    for li, line in enumerate(lines):
        for key in ('lapack', 'blas'):
            if line.startswith('%s_opt_info' % key):
                lib = lines[li + 1]
                if 'NOT AVAILABLE' in lib:
                    lib = 'unknown'
                else:
                    try:
                        lib = lib.split('[')[1].split("'")[1]
                    except IndexError:
                        pass  # keep whatever it was
                libs += ['%s=%s' % (key, lib)]
    libs = ', '.join(libs)
    for mod_name in ('mne', 'numpy', 'scipy', 'matplotlib', '', 'sklearn',
                     'nibabel', 'mayavi', 'cupy', 'pandas', 'dipy'):
        if mod_name == '':
            out += '\n'
            continue
        out += ('%s:' % mod_name).ljust(ljust)
        try:
            mod = __import__(mod_name)
            if mod_name == 'mayavi':
                # the real test
                from mayavi import mlab  # noqa, analysis:ignore
        except Exception:
            out += 'Not found\n'
        else:
            extra = (' (%s)' % op.dirname(mod.__file__)) if show_paths else ''
            if mod_name == 'numpy':
                extra = ' {%s}%s' % (libs, extra)
            elif mod_name == 'matplotlib':
                extra = ' {backend=%s}%s' % (mod.get_backend(), extra)
            elif mod_name == 'mayavi':
                try:
                    from pyface.qt import qt_api
                except Exception:
                    qt_api = 'unknown'
                if qt_api == 'pyqt5':
                    try:
                        from PyQt5.Qt import PYQT_VERSION_STR
                        qt_api += ', PyQt5=%s' % (PYQT_VERSION_STR,)
                    except Exception:
                        pass
                extra = ' {qt_api=%s}%s' % (qt_api, extra)
            out += '%s%s\n' % (mod.__version__, extra)
    print(out, end='', file=fid)
Exemplo n.º 41
0
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 19:05:01 2020

@author: DELL.E5430.SSD
"""

import numpy as np

print(np.__version__)
print()
print(np.show_config())
#1. Import the NUMPY package under the name np.

import numpy as np

#2. Print the NUMPY version and the configuration.

>>>np.__version__
'1.16.2'

>>> np.show_config()
mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/Users/julieG/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/julieG/anaconda3/include']
blas_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/Users/julieG/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/julieG/anaconda3/include']
blas_opt_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/Users/julieG/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/julieG/anaconda3/include']
lapack_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/Users/julieG/anaconda3/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/julieG/anaconda3/include']
lapack_opt_info:
type(val)

# # 6. Print the numpy version and the configuration
#

# In[22]:

np.__version__

# In[28]:

np.__config__

# In[30]:

np.show_config()

# # 7. Print the dimension of the array in question 3

# In[47]:

#by there  no. of ending prhantics we can easily see out this is 1-D ARRAY:
val.ndim

# # 8. Create a boolean array with all the True values

# In[41]:

array = np.array(range(10, 30), dtype=bool)
array
Exemplo n.º 44
0
def main():
	print(np.__version__)
	np.show_config()