diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 099799f..7cfa22c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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 }} diff --git a/README.md b/README.md index 1425bee..cf72772 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/docs/install.rst b/docs/install.rst index 614256b..fb16a91 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -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/) diff --git a/pyproject.toml b/pyproject.toml index 7a06418..a54347b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/torchtt/interpolate.py b/torchtt/interpolate.py index 37fe382..f818e35 100644 --- a/torchtt/interpolate.py +++ b/torchtt/interpolate.py @@ -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 @@ -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: @@ -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 @@ -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 @@ -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: @@ -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 @@ -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