Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incompatibility with numpy > 2 #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
106 changes: 58 additions & 48 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@
#
import os
import sys

# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'SecML'
project = "SecML"
import datetime
copyright = '{:}, PRALab - Pattern Recognition and Applications Lab & ' \
'Pluribus One s.r.l.'.format(datetime.datetime.now().year)
author = 'PRALab'

copyright = (
"{:}, PRALab - Pattern Recognition and Applications Lab & "
"Pluribus One s.r.l.".format(datetime.datetime.now().year)
)
author = "PRALab"

# The full version, including alpha/beta/rc tags
import secml

release = version = secml.__version__


Expand All @@ -34,62 +39,67 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'sphinx.ext.imgmath',
'matplotlib.sphinxext.plot_directive',
'numpydoc',
'm2r',
'nbsphinx',
'nbsphinx_link'
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"sphinx.ext.imgmath",
"matplotlib.sphinxext.plot_directive",
"numpydoc",
"m2r",
"nbsphinx",
"nbsphinx_link",
]

autodoc_default_options = {
# 'members': True,
'member-order': 'alphabetical',
"member-order": "alphabetical",
# 'undoc-members': True,
# 'show-inheritance': True,
'exclude-members': ''
"exclude-members": "",
}

# The following modules should be faked by sphinx (e.g. extras)
autodoc_mock_imports = [
"pytest", "torch", "torchvision", "cleverhans", "tensorflow",
"foolbox", "eagerpy"]
"pytest",
"torch",
"torchvision",
"cleverhans",
"tensorflow",
"foolbox",
"eagerpy",
]

# Autosummary pages will be generated by sphinx-autogen instead of sphinx-build
# autosummary_generate = True

numpydoc_class_members_toctree = False

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints']
exclude_patterns = ["build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]

# Always show the source code that generates a plot
plot_include_source = True
plot_formats = ['png']
plot_formats = ["png"]

source_suffix = ['.rst', '.md']
source_suffix = [".rst", ".md"]

img_latex_preamble = r'\\usepackage{amsmath}'
img_latex_preamble = r"\\usepackage{amsmath}"

intersphinx_mapping = {
'python': ('https://docs.python.org/{.major}'.format(
sys.version_info), None),
'numpy': ('https://numpy.org/doc/stable/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
'sklearn': ("https://scikit-learn.org/stable/", None),
'matplotlib': ('https://matplotlib.org/', None),
'pytorch': ('https://pytorch.org/docs/stable/', None),
'cleverhans': ('https://cleverhans.readthedocs.io/en/latest/', None),
'foolbox': ('https://foolbox.readthedocs.io/en/stable/', None),
"python": ("https://docs.python.org/{.major}".format(sys.version_info), None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
"matplotlib": ("https://matplotlib.org/", None),
"pytorch": ("https://pytorch.org/docs/stable/", None),
"cleverhans": ("https://cleverhans.readthedocs.io/en/latest/", None),
"foolbox": ("https://foolbox.readthedocs.io/en/stable/", None),
}

# -- Options for HTML output -------------------------------------------------
Expand All @@ -102,38 +112,38 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# html_logo = '_static/secml.png'
# html_favicon = '_static/favicon.png'

html_theme_options = {
'canonical_url': '',
'analytics_id': 'UA-145155489-1',
'logo_only': False,
'display_version': True,
'prev_next_buttons_location': 'bottom',
'style_external_links': False,
'style_nav_header_background': '#2980B9',
"canonical_url": "",
"analytics_id": "UA-145155489-1",
"logo_only": False,
"display_version": True,
"prev_next_buttons_location": "bottom",
"style_external_links": False,
"style_nav_header_background": "#2980B9",
# Toc options
'collapse_navigation': False,
'sticky_navigation': True,
'navigation_depth': 5,
'includehidden': True,
'titles_only': False
"collapse_navigation": False,
"sticky_navigation": True,
"navigation_depth": 5,
"includehidden": True,
"titles_only": False,
}

html_context = {
"display_gitlab": True,
"gitlab_host": "gitlab.com",
"gitlab_user": "secml",
"gitlab_repo": 'secml',
"gitlab_repo": "secml",
"gitlab_version": "HEAD",
"conf_py_path": "/docs/source/",
"source_suffix": '.rst'
"source_suffix": ".rst",
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
10 changes: 5 additions & 5 deletions docs/source/pyplots/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
Y2 = (1 - X / float(n)) * (1.0 - 0.5) * CArray.rand((n,)) + 0.5

fig.sp.xticks([0.025, 0.025, 0.95, 0.95])
fig.sp.bar(X, Y1, facecolor='#9999ff', edgecolor='white')
fig.sp.bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
fig.sp.bar(X, Y1, facecolor="#9999ff", edgecolor="white")
fig.sp.bar(X, -Y2, facecolor="#ff9999", edgecolor="white")

for x, y in zip(X, Y1):
fig.sp.text(x, y, '%.2f' % y, ha='center', va='bottom')
fig.sp.text(x, y, "%.2f" % y, ha="center", va="bottom")

for x, y in zip(X, Y2):
fig.sp.text(x, -y - 0.02, '%.2f' % y, ha='center', va='top')
fig.sp.text(x, -y - 0.02, "%.2f" % y, ha="center", va="top")

fig.sp.xlim(-.5, n-.5)
fig.sp.xlim(-0.5, n - 0.5)
fig.sp.xticks(())
fig.sp.ylim(-1.25, 1.25)
fig.sp.yticks(())
Expand Down
4 changes: 2 additions & 2 deletions docs/source/pyplots/clabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * (-x ** 2 - y ** 2).exp()
return (1 - x / 2 + x**5 + y**3) * (-(x**2) - y**2).exp()


fig = CFigure()
Expand All @@ -13,7 +13,7 @@ def f(x, y):

X, Y = CArray.meshgrid((x_linspace, y_linspace))

C = fig.sp.contour(X, Y, f(X, Y), linewidths=.5, cmap='hot')
C = fig.sp.contour(X, Y, f(X, Y), linewidths=0.5, cmap="hot")
fig.sp.clabel(C, inline=1, fontsize=10)

fig.sp.xticks(())
Expand Down
8 changes: 4 additions & 4 deletions docs/source/pyplots/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * (-x ** 2 - y ** 2).exp()
return (1 - x / 2 + x**5 + y**3) * (-(x**2) - y**2).exp()


fig = CFigure(width=10, title="Colorbar Example")
fig.subplot(1, 2, 1)
Expand All @@ -12,18 +13,17 @@ def f(x, y):
y_linspace = CArray.linspace(-3, 3, 256)

X, Y = CArray.meshgrid((x_linspace, y_linspace))
c = fig.sp.contourf(X, Y, f(X, Y), 8, alpha=.75, cmap='hot')
c = fig.sp.contourf(X, Y, f(X, Y), 8, alpha=0.75, cmap="hot")
fig.sp.colorbar(c)
fig.sp.title("Hot Contourf")
fig.sp.xticks(())
fig.sp.yticks(())

fig.subplot(1, 2, 2)
c = fig.sp.contourf(X, Y, f(X, Y), 8, alpha=.75, cmap='winter')
c = fig.sp.contourf(X, Y, f(X, Y), 8, alpha=0.75, cmap="winter")
fig.sp.colorbar(c)
fig.sp.title("Cold Contourf")
fig.sp.xticks(())
fig.sp.yticks(())

fig.show()

6 changes: 3 additions & 3 deletions docs/source/pyplots/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * (-x ** 2 - y ** 2).exp()
return (1 - x / 2 + x**5 + y**3) * (-(x**2) - y**2).exp()


fig = CFigure()

Expand All @@ -12,10 +13,9 @@ def f(x, y):

X, Y = CArray.meshgrid((x_linspace, y_linspace))

C = fig.sp.contour(X, Y, f(X, Y), linewidths=.5, cmap='hot')
C = fig.sp.contour(X, Y, f(X, Y), linewidths=0.5, cmap="hot")

fig.sp.xticks(())
fig.sp.yticks(())

fig.show()

5 changes: 3 additions & 2 deletions docs/source/pyplots/contourf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@


def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * (-x ** 2 - y ** 2).exp()
return (1 - x / 2 + x**5 + y**3) * (-(x**2) - y**2).exp()


fig = CFigure()

x_linspace = CArray.linspace(-3, 3, 256)
y_linspace = CArray.linspace(-3, 3, 256)

X, Y = CArray.meshgrid((x_linspace, y_linspace))
fig.sp.contourf(X, Y, f(X, Y), 8, alpha=.75, cmap='hot')
fig.sp.contourf(X, Y, f(X, Y), 8, alpha=0.75, cmap="hot")

fig.sp.xticks(())
fig.sp.yticks(())
Expand Down
8 changes: 4 additions & 4 deletions docs/source/pyplots/errorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from secml.figure import CFigure

fig = CFigure(fontsize=16)
fig.title('Errorbars can go negative!')
fig.title("Errorbars can go negative!")

fig.sp.xscale("symlog", nonposx='clip')
fig.sp.yscale("symlog", nonposy='clip')
fig.sp.xscale("symlog", nonposx="clip")
fig.sp.yscale("symlog", nonposy="clip")

x = CArray(10.0).pow(CArray.linspace(0.0, 2.0, 20))
y = x ** 2.0
y = x**2.0

fig.sp.errorbar(x, y, xerr=0.1 * x, yerr=5.0 + 0.75 * y)

Expand Down
3 changes: 1 addition & 2 deletions docs/source/pyplots/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

fig = CFigure(fontsize=14)

fig.sp.plot(X, C, color='red', alpha=0.5, linewidth=1.0, linestyle='-', label="cosine")
fig.sp.plot(X, C, color="red", alpha=0.5, linewidth=1.0, linestyle="-", label="cosine")
fig.sp.plot(X, S, label="sine")

fig.sp.xticks(CArray([-3.14, -3.14 / 2, 0, 3.14 / 2, 3.14]))
Expand All @@ -15,4 +15,3 @@
fig.sp.legend(loc=0)

fig.show()

10 changes: 5 additions & 5 deletions docs/source/pyplots/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
x = mu + sigma * CArray.randn((10000,))
num_bins = 50
# the histogram of the data
n, bins, patches = fig.sp.hist(x, num_bins, density=1, facecolor='green', alpha=0.5)
n, bins, patches = fig.sp.hist(x, num_bins, density=1, facecolor="green", alpha=0.5)
# add a 'best fit' line
y = bins.normpdf(mu, sigma)
fig.sp.plot(bins, y, 'r--')
fig.sp.xlabel('Smarts')
fig.sp.ylabel('Probability')
fig.title(r'Histogram of IQ: $\mu=100$, $\sigma=15$')
fig.sp.plot(bins, y, "r--")
fig.sp.xlabel("Smarts")
fig.sp.ylabel("Probability")
fig.title(r"Histogram of IQ: $\mu=100$, $\sigma=15$")

# Tweak spacing to prevent clipping of ylabel
fig.subplots_adjust(left=0.15)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyplots/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
C, S = X.cos(), X.sin()

fig = CFigure(fontsize=14)
fig.sp.plot(X, C, color='red', alpha=0.5, linewidth=1.0, linestyle='-', label="cosine")
fig.sp.plot(X, C, color="red", alpha=0.5, linewidth=1.0, linestyle="-", label="cosine")
fig.sp.plot(X, S, label="sine")

fig.sp.grid()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyplots/loglog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from secml.figure import CFigure

fig = CFigure(fontsize=14)
fig.title('loglog base 4 on x')
fig.title("loglog base 4 on x")

t = CArray.arange(0.01, 20.0, 0.01)
fig.sp.loglog(t, 20 * (-t / 10.0).exp(), basex=2)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/pyplots/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

fig = CFigure(fontsize=14)

fig.sp.plot(X, C, color='red', alpha=0.5, linewidth=1.0, linestyle='-')
fig.sp.plot(X, C, color="red", alpha=0.5, linewidth=1.0, linestyle="-")
fig.sp.plot(X, S)

fig.show()
2 changes: 1 addition & 1 deletion docs/source/pyplots/plot_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def f(array):

fig = CFigure()

fig.sp.plot_fun(f, levels=[.5, 1, 1.5])
fig.sp.plot_fun(f, levels=[0.5, 1, 1.5])

fig.sp.grid()
fig.show()
1 change: 0 additions & 1 deletion docs/source/pyplots/plot_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
fig.sp.ylim(1, 8)

fig.show()

6 changes: 3 additions & 3 deletions docs/source/pyplots/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
dataset = CDLRandom().load()

fig = CFigure(fontsize=14)
fig.sp.scatter(dataset.X[:, 0].ravel(),
dataset.X[:, 1].ravel(),
s=75, c=dataset.Y, alpha=.7)
fig.sp.scatter(
dataset.X[:, 0].ravel(), dataset.X[:, 1].ravel(), s=75, c=dataset.Y, alpha=0.7
)

fig.show()
Loading
Loading