Skip to content

Commit

Permalink
fix requirement python>=3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Ion committed Dec 14, 2024
1 parent 29e7ce9 commit 495b8e3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
buildandtest:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest]
# os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Some routines are implemented in C++ for an increased execution speed.
### Requirements
Following requirements are needed:

- `python>=3.6`
- `python>=3.8`
- `torch>=1.7.0`
- `numpy>=1.18`
- [`opt_einsum`](https://pypi.org/project/opt-einsum/)
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Requirements

The requirements are the following:

- ``python>=3.6``
- ``python>=3.8``
- ``torch>=1.7.0``
- ``numpy>=1.18``
- ``opt_einsum`` (https://pypi.org/project/opt-einsum/)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = "torchTT"
version = "0.3"
description = "Tensor-Train decomposition in pytorch."
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
dependencies = [
"torch>=1.7",
"numpy>=1.18",
Expand Down
36 changes: 29 additions & 7 deletions torchtt/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def _LU(M):
def _max_matrix(M):

values, indices = M.flatten().topk(1)
indices = [tn.unravel_index(i, M.shape) for i in indices]
try:
indices = [tn.unravel_index(i, M.shape) for i in indices]
except:
indices = [np.unravel_index(i, M.shape) for i in indices]

return values, indices


Expand Down Expand Up @@ -166,7 +170,10 @@ def function_interpolate(function, x, eps=1e-9, start_tens=None, nswp=20, kick=2
rnew = min(N[k]*rank[k+1], rank[k])
Jk = _maxvol(core)
# print(Jk)
tmp = tn.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
try:
tmp = tn.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
except:
tmp = np.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
# if k==d-1:
# idx_new = tn.tensor(tmp[1].reshape([1,-1]))
# else:
Expand Down Expand Up @@ -305,7 +312,10 @@ def function_interpolate(function, x, eps=1e-9, start_tens=None, nswp=20, kick=2
_, Ps[k+1] = QR(tn.reshape(tmp, [rank[k]*N[k], rank[k+1]]))

# calc Idx
tmp = tn.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
try:
tmp = tn.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
except:
tmp = np.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
idx_new = tn.tensor(
np.hstack((Idx[k][tmp[0], :], tmp[1].reshape([-1, 1]))))
Idx[k+1] = idx_new+0
Expand Down Expand Up @@ -423,7 +433,10 @@ def function_interpolate(function, x, eps=1e-9, start_tens=None, nswp=20, kick=2
_, tmp = QR(tn.reshape(tmp, [rank[k+1], -1]).t())
Ps[k+1] = tmp
# calc Idx
tmp = tn.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
try:
tmp = tn.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
except:
tmp = np.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
idx_new = tn.tensor(
np.vstack((tmp[0].reshape([1, -1]), Idx[k+2][:, tmp[1]])))
Idx[k+1] = idx_new+0
Expand Down Expand Up @@ -511,7 +524,10 @@ def dmrg_cross(function, N, eps=1e-9, nswp=10, x_start=None, kick=2, dtype=tn.fl
rnew = min(N[k]*rank[k+1], rank[k])
Jk = _maxvol(core)
# print(Jk)
tmp = tn.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
try:
tmp = tn.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
except:
tmp = np.unravel_index(Jk[:rnew], (rank[k+1], N[k]))
# if k==d-1:
# idx_new = tn.tensor(tmp[1].reshape([1,-1]))
# else:
Expand Down Expand Up @@ -639,7 +655,10 @@ def dmrg_cross(function, N, eps=1e-9, nswp=10, x_start=None, kick=2, dtype=tn.fl
_, Ps[k+1] = QR(tn.reshape(tmp, [rank[k]*N[k], rank[k+1]]))

# calc Idx
tmp = tn.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
try:
tmp = tn.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
except:
tmp = np.unravel_index(idx[:rank[k+1]], (rank[k], N[k]))
idx_new = tn.tensor(
np.hstack((Idx[k][tmp[0], :], tmp[1].reshape([-1, 1]))))
Idx[k+1] = idx_new+0
Expand Down Expand Up @@ -741,7 +760,10 @@ def dmrg_cross(function, N, eps=1e-9, nswp=10, x_start=None, kick=2, dtype=tn.fl
_, tmp = QR(tn.reshape(tmp, [rank[k+1], -1]).t())
Ps[k+1] = tmp
# calc Idx
tmp = tn.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
try:
tmp = tn.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
except:
tmp = np.unravel_index(idx[:rank[k+1]], (N[k+1], rank[k+2]))
idx_new = tn.tensor(
np.vstack((tmp[0].reshape([1, -1]), Idx[k+2][:, tmp[1]])))
Idx[k+1] = idx_new+0
Expand Down

0 comments on commit 495b8e3

Please sign in to comment.