Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.9"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ authors = [
]
license = { text="BSD 2-Clause License" }
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"

dependencies = [
"numpy < 2",
"numpy",
"numpy_groupies",
"scipy",
"matplotlib",
Expand Down
20 changes: 12 additions & 8 deletions pyttb/ktensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import matplotlib.pyplot as plt
import numpy as np
import scipy.sparse.linalg
from matplotlib.axes import Axes
from matplotlib.figure import Figure

import pyttb as ttb
from pyttb.pyttb_utils import (
Expand Down Expand Up @@ -2241,7 +2243,7 @@ def vis( # noqa: PLR0912, PLR0913
bot_space: Optional[float] = None,
mode_titles: Optional[Union[tuple, list]] = None,
title=None,
):
) -> Tuple[Figure, Axes]:
"""
Visualize factors for :class:`pyttb.ktensor`.

Expand Down Expand Up @@ -2281,6 +2283,8 @@ def vis( # noqa: PLR0912, PLR0913

Returns
-------
fig:
:class:`matplotlib.figure.Figure' handle for the generated figure
axs:
:class:`matplotlib.axes.Axes' for the generated figure

Expand All @@ -2293,8 +2297,8 @@ def vis( # noqa: PLR0912, PLR0913

Use plot K using default behavior K.vis()

>>> K.vis() # doctest: +ELLIPSIS
array([[<Axes: ...
>>> fig, axs = K.vis() # doctest: +ELLIPSIS
>>> plt.close(fig)

Define a more realistic plot fuctions with x labels,
control relative widths of each plot,
Expand All @@ -2310,11 +2314,11 @@ def vis( # noqa: PLR0912, PLR0913
... ax.semilogx(np.logspace(-2,2,v.shape[0]),v)
... ax.set_xlabel('$E$, [kJ]')
>>> plots = [mode_1_plot, mode_2_plot, mode_3_plot]
>>> K.vis(plots=plots,
>>> fig, axs = K.vis(plots=plots,
... rel_widths=[1,2,3],horz_space=0.4,
... left_space=0.2,bot_space=0.2,
... mode_titles=['Particle','Velocity','Energy']) # doctest: +ELLIPSIS
array([[<Axes: ...
>>> plt.close(fig)
"""

def line_plot(v, ax):
Expand Down Expand Up @@ -2389,7 +2393,7 @@ def line_plot(v, ax):
fig.suptitle(title)

# tune layout
plt.subplots_adjust(
fig.subplots_adjust(
wspace=horz_space,
hspace=vert_space,
left=left_space,
Expand All @@ -2399,8 +2403,8 @@ def line_plot(v, ax):
)

if show_figure:
plt.show()
return axs
fig.show()
return fig, axs

def __add__(self, other):
"""
Expand Down
12 changes: 6 additions & 6 deletions pyttb/sptenmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from scipy import sparse

import pyttb as ttb
from pyttb.pyttb_utils import gather_wrap_dims, tt_ind2sub
from pyttb.pyttb_utils import gather_wrap_dims, np_to_python, tt_ind2sub


class sptenmat:
Expand Down Expand Up @@ -307,7 +307,7 @@ def shape(self) -> Tuple[int, ...]:
else:
m = np.prod(np.array(self.tshape)[self.rdims])
n = np.prod(np.array(self.tshape)[self.cdims])
return m, n
return int(m), int(n)

def double(self) -> sparse.coo_matrix:
"""
Expand Down Expand Up @@ -371,7 +371,7 @@ def nnz(self) -> int:
"""
return len(self.vals)

def norm(self) -> np.floating:
def norm(self) -> float:
"""
Compute the norm (i.e., Frobenius norm, or square root of the sum of
squares of entries) of the :class:`pyttb.sptenmat`.
Expand All @@ -384,7 +384,7 @@ def norm(self) -> np.floating:
>>> ST1.norm()
1.0
"""
return np.linalg.norm(self.vals)
return np.linalg.norm(self.vals).item()

def isequal(self, other: sptenmat) -> bool:
"""
Expand Down Expand Up @@ -569,9 +569,9 @@ def __repr__(self):
s = ""
s += "sptenmat corresponding to a sptensor of shape "
if self.vals.size == 0:
s += str(self.shape)
s += str(np_to_python(self.shape))
else:
s += f"{self.tshape!r}"
s += f"{np_to_python(self.tshape)!r}"
s += " with " + str(self.vals.size) + " nonzeros"
s += "\n"

Expand Down
2 changes: 1 addition & 1 deletion pyttb/sptensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def from_function(
subs = np.unique(subs, axis=0)
cnt += 1

nonzeros = min(nonzeros, subs.shape[0])
nonzeros = int(min(nonzeros, subs.shape[0]))
subs = subs[0:nonzeros, :]
vals = function_handle((nonzeros, 1))

Expand Down
6 changes: 3 additions & 3 deletions pyttb/tenmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np

import pyttb as ttb
from pyttb.pyttb_utils import gather_wrap_dims
from pyttb.pyttb_utils import gather_wrap_dims, np_to_python


class tenmat:
Expand Down Expand Up @@ -430,7 +430,7 @@ def __getitem__(self, item):
Examples
--------
>>> TM = ttb.tenones((2,2,2)).to_tenmat(np.array([0]))
>>> TM[0, 0]
>>> print(TM[0, 0])
1.0

Returns
Expand Down Expand Up @@ -761,7 +761,7 @@ def __repr__(self):
"""
s = ""
s += "matrix corresponding to a tensor of shape "
s += str(self.tshape)
s += str(np_to_python(self.tshape))
s += "\n"

s += "rindices = "
Expand Down
Loading