Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ repos:
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
- id: ruff-format

- repo: https://github.com/pycqa/isort
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3 # frozen: 5.13.2
hooks:
- id: isort

- repo: https://github.com/codespell-project/codespell
rev: "6e41aba91fb32e9feb741a6258eefeb9c6e4a482" # frozen: v2.2.6
hooks:
Expand Down
7 changes: 2 additions & 5 deletions advanced/advanced_numpy/examples/mandel-answer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ cdef void mandel_single_point(double complex *z_in,
# Pulls definitions from the NumPy C headers.
# -------------------------------------------

from numpy cimport import_array, import_ufunc
from numpy cimport (PyUFunc_FromFuncAndData,
PyUFuncGenericFunction)
from numpy cimport NPY_CDOUBLE
from numpy cimport PyUFunc_DD_D
from numpy cimport (NPY_CDOUBLE, PyUFunc_DD_D, PyUFunc_FromFuncAndData,
PyUFuncGenericFunction, import_array, import_ufunc)

# Required module initialization
# ------------------------------
Expand Down
28 changes: 7 additions & 21 deletions advanced/advanced_numpy/examples/mandel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,17 @@ cdef void mandel_single_point(double complex *z_in,
# Pulls definitions from the NumPy C headers.
# -------------------------------------------

from numpy cimport import_array, import_ufunc
from numpy cimport (PyUFunc_FromFuncAndData,
PyUFuncGenericFunction)
from numpy cimport NPY_CDOUBLE, NP_DOUBLE, NPY_LONG
from numpy cimport (NP_DOUBLE, NPY_CDOUBLE, NPY_LONG, PyUFunc_d_d, PyUFunc_D_D,
PyUFunc_dd_d, PyUFunc_DD_D, PyUFunc_f_f, PyUFunc_F_F,
PyUFunc_f_f_As_d_d, PyUFunc_F_F_As_D_D, PyUFunc_ff_f,
PyUFunc_FF_F, PyUFunc_ff_f_As_dd_d, PyUFunc_FF_F_As_DD_D,
PyUFunc_FromFuncAndData, PyUFunc_g_g, PyUFunc_G_G,
PyUFunc_gg_g, PyUFunc_GG_G, PyUFuncGenericFunction,
import_array, import_ufunc)

# Import all pre-defined loop functions
# you won't need all of them - keep the relevant ones

from numpy cimport (
PyUFunc_f_f_As_d_d,
PyUFunc_d_d,
PyUFunc_f_f,
PyUFunc_g_g,
PyUFunc_F_F_As_D_D,
PyUFunc_F_F,
PyUFunc_D_D,
PyUFunc_G_G,
PyUFunc_ff_f_As_dd_d,
PyUFunc_ff_f,
PyUFunc_dd_d,
PyUFunc_gg_g,
PyUFunc_FF_F_As_DD_D,
PyUFunc_DD_D,
PyUFunc_FF_F,
PyUFunc_GG_G)


# Required module initialization
Expand Down
3 changes: 2 additions & 1 deletion advanced/advanced_numpy/examples/mandelplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

"""

import numpy as np
import mandel

import numpy as np

x = np.linspace(-1.7, 0.6, 1000)
y = np.linspace(-1.4, 1.4, 1000)
c = x[None, :] + 1j * y[:, None]
Expand Down
3 changes: 2 additions & 1 deletion advanced/advanced_numpy/examples/pilbuffer-answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
the buffer interface.
"""

import numpy as np
import Image

import numpy as np

# Let's make a sample image, RGBA format

x = np.zeros((200, 200, 4), dtype=np.int8)
Expand Down
3 changes: 2 additions & 1 deletion advanced/advanced_numpy/examples/pilbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Skeletton of the code to do an exercise using the buffer protocole.
"""

import numpy as np
import Image

import numpy as np

# Let's make a sample image, RGBA format

x = np.zeros((200, 200, 4), dtype=np.int8)
Expand Down
5 changes: 3 additions & 2 deletions advanced/advanced_numpy/examples/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
C sources.
"""

from distutils.sysconfig import get_python_inc
import os
import sys
from os.path import join
from distutils.sysconfig import get_python_inc
import sys

import numpy
from numpy.distutils.misc_util import get_numpy_include_dirs

Expand Down
2 changes: 1 addition & 1 deletion advanced/advanced_numpy/examples/setup_myobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from distutils.core import setup, Extension
from distutils.core import Extension, setup

setup(
name="myobject",
Expand Down
1 change: 1 addition & 0 deletions advanced/advanced_numpy/examples/wavreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import sys

import numpy as np

wav_header_dtype = np.dtype(
Expand Down
3 changes: 2 additions & 1 deletion advanced/image_processing/examples/plot_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
Small example to plot a raccoon face.
"""

import scipy as sp
import imageio.v3 as iio

import scipy as sp

f = sp.datasets.face()
iio.imwrite("face.png", f) # uses the Image module (PIL)

Expand Down
1 change: 0 additions & 1 deletion advanced/image_processing/examples/plot_face_tv_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt

from skimage.restoration import denoise_tv_chambolle

rng = np.random.default_rng(27446968)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import numpy as np
import matplotlib.pyplot as plt

from sklearn.feature_extraction import image
from sklearn.cluster import spectral_clustering
from sklearn.feature_extraction import image

################################################################################
l = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""

import numpy as np
from skimage.segmentation import watershed
from skimage.feature import peak_local_max
import matplotlib.pyplot as plt
import scipy as sp
import matplotlib.pyplot as plt
from skimage.feature import peak_local_max
from skimage.segmentation import watershed

# Generate an initial image with two overlapping circles
x, y = np.indices((80, 80))
Expand Down
4 changes: 2 additions & 2 deletions advanced/interfacing_with_c/ctypes/cos_module.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Example of wrapping cos function from math.h using ctypes."""

import ctypes
# OSX or linux
from ctypes.util import find_library

# find and load the library

# OSX or linux
from ctypes.util import find_library

libm = ctypes.cdll.LoadLibrary(find_library("m"))

Expand Down
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/ctypes_numpy/cos_doubles.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Example of wrapping a C library function that accepts a C double array as
input using the numpy.ctypeslib."""

from ctypes import c_int

import numpy as np
import numpy.ctypeslib as npct
from ctypes import c_int

# input type for the cos_doubles function
# must be a double array, with single dimension that is contiguous
Expand Down
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/cython/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

from Cython.Distutils import build_ext

setup(
Expand Down
6 changes: 4 additions & 2 deletions advanced/interfacing_with_c/cython_numpy/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from distutils.core import setup, Extension
import numpy
from distutils.core import Extension, setup

from Cython.Distutils import build_ext

import numpy

setup(
cmdclass={"build_ext": build_ext},
ext_modules=[
Expand Down
1 change: 1 addition & 0 deletions advanced/interfacing_with_c/cython_simple/cos_module.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

from libc.math cimport cos


def cos_func(arg):
return cos(arg)
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/cython_simple/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

from Cython.Distutils import build_ext

setup(
Expand Down
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/numpy_c_api/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

import numpy

# define the extension module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cos_module_np

import numpy as np
import matplotlib.pyplot as plt

Expand Down
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/numpy_shared/test_cos_doubles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cos_doubles

import numpy as np
import matplotlib.pyplot as plt
import cos_doubles

x = np.arange(0, 2 * np.pi, 0.1)
y = np.empty_like(x)
Expand Down
2 changes: 1 addition & 1 deletion advanced/interfacing_with_c/python_c_api/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

# define the extension module
cos_module = Extension("cos_module", sources=["cos_module.c"])
Expand Down
2 changes: 1 addition & 1 deletion advanced/interfacing_with_c/swig/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

setup(ext_modules=[Extension("_cos_module", sources=["cos_module.c", "cos_module.i"])])
3 changes: 2 additions & 1 deletion advanced/interfacing_with_c/swig_numpy/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup, Extension
from distutils.core import Extension, setup

import numpy

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
import pickle
import sys

from cost_functions import (CountingFunction, LoggingFunction, mk_gauss,
mk_quad, rosenbrock, rosenbrock_hessian,
rosenbrock_prime)

import numpy as np
import scipy as sp
from joblib import Memory

from cost_functions import (
mk_quad,
mk_gauss,
rosenbrock,
rosenbrock_prime,
rosenbrock_hessian,
LoggingFunction,
CountingFunction,
)


def my_partial(**kwargs):
function = sp.optimize.minimize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
import matplotlib.pyplot as plt

x = np.linspace(-1, 3, 100)
x_0 = np.exp(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"""

import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
import matplotlib.pyplot as plt

x, y = np.mgrid[-2.9:5.8:0.05, -2.5:5:0.05]
x = x.T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
evolution of the optimizer.
"""

import os
import sys

import numpy as np
import matplotlib.pyplot as plt
import scipy as sp

import sys
import os
import matplotlib.pyplot as plt

sys.path.append(os.path.abspath("helper"))
from cost_functions import (
mk_quad,
mk_gauss,
rosenbrock,
rosenbrock_prime,
rosenbrock_hessian,
LoggingFunction,
CountingFunction,
)
from cost_functions import (CountingFunction, LoggingFunction, mk_gauss,
mk_quad, rosenbrock, rosenbrock_hessian,
rosenbrock_prime)

x_min, x_max = -1, 2
y_min, y_max = 2.25 / 3 * x_min - 0.2, 2.25 / 3 * x_max - 0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""

import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
import matplotlib.pyplot as plt

x, y = np.mgrid[-2.03:4.2:0.04, -1.6:3.2:0.04]
x = x.T
Expand Down
4 changes: 2 additions & 2 deletions advanced/optimizing/demo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# For this example to run, you also need the 'ica.py' file

from ica import fastica

import numpy as np
import scipy as sp

from ica import fastica


# @profile # uncomment this line to run with line_profiler
def test():
Expand Down
4 changes: 2 additions & 2 deletions advanced/optimizing/demo_opt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# For this example to run, you also need the 'ica.py' file

from ica import fastica

import numpy as np
import scipy as sp

from ica import fastica


def test():
rng = np.random.default_rng()
Expand Down
2 changes: 1 addition & 1 deletion advanced/optimizing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# License: GPL unless permission obtained otherwise
# Look at algorithms in Tables 8.3 and 8.4 page 196 in the book: Independent Component Analysis, by Aapo et al.

import numpy as np
import types

import numpy as np

__all__ = ["fastica"]

Expand Down
Loading