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

{IndexError}index 2048 is out of bounds for dimension 1 with size 2048 #3

Open
zfhxi opened this issue Aug 27, 2021 · 3 comments
Open

Comments

@zfhxi
Copy link

zfhxi commented Aug 27, 2021

Hello, my test code is as follow:

X1 = torch.randn([10, 2048]).cuda()
X_emb = TorchTSNE(n_components=2, perplexity=100., n_iter=1000).fit_transform(X1)

Sometimes, it will occur '{IndexError}index 2048 is out of bounds for dimension 1 with size 2048', I find the reason is that as 121 line in the tsne_pytorch.py, there may be out of bounds:

119 for i in range(d):
120     if l[i, 1] != 0:
121         M[:, i+1] = M[:, i]
122         i += 1

Concretely, i may equal to d-1 in 121 line which causes M[:,i+1] will be out of bounds(we know M is dxd).

I wonder if the modified code as follow is right?

for i in range(d-1):
    if l[i, 1] != 0:
        M[:, i+1] = M[:, i]
        i += 1
@mxl1990
Copy link
Owner

mxl1990 commented Dec 10, 2021

Hello, my test code is as follow:

X1 = torch.randn([10, 2048]).cuda()
X_emb = TorchTSNE(n_components=2, perplexity=100., n_iter=1000).fit_transform(X1)

Sometimes, it will occur '{IndexError}index 2048 is out of bounds for dimension 1 with size 2048', I find the reason is that as 121 line in the tsne_pytorch.py, there may be out of bounds:

119 for i in range(d):
120     if l[i, 1] != 0:
121         M[:, i+1] = M[:, i]
122         i += 1

Concretely, i may equal to d-1 in 121 line which causes M[:,i+1] will be out of bounds(we know M is dxd).

I wonder if the modified code as follow is right?

for i in range(d-1):
    if l[i, 1] != 0:
        M[:, i+1] = M[:, i]
        i += 1

rang(d) function do not cover the index d, and d is get from (n, d) = X.shape
so may be something else wrong not here

@zfhxi
Copy link
Author

zfhxi commented Dec 17, 2021

Hello, my test code is as follow:

X1 = torch.randn([10, 2048]).cuda()
X_emb = TorchTSNE(n_components=2, perplexity=100., n_iter=1000).fit_transform(X1)

Sometimes, it will occur '{IndexError}index 2048 is out of bounds for dimension 1 with size 2048', I find the reason is that as 121 line in the tsne_pytorch.py, there may be out of bounds:

119 for i in range(d):
120     if l[i, 1] != 0:
121         M[:, i+1] = M[:, i]
122         i += 1

Concretely, i may equal to d-1 in 121 line which causes M[:,i+1] will be out of bounds(we know M is dxd).
I wonder if the modified code as follow is right?

for i in range(d-1):
    if l[i, 1] != 0:
        M[:, i+1] = M[:, i]
        i += 1

rang(d) function do not cover the index d, and d is get from (n, d) = X.shape so may be something else wrong not here

You are right, but i may equal to d-1, then M[:,i+1] actually is M[:,d] which will occur errors.

@mxl1990
Copy link
Owner

mxl1990 commented Jan 4, 2022

Hello, my test code is as follow:

X1 = torch.randn([10, 2048]).cuda()
X_emb = TorchTSNE(n_components=2, perplexity=100., n_iter=1000).fit_transform(X1)

Sometimes, it will occur '{IndexError}index 2048 is out of bounds for dimension 1 with size 2048', I find the reason is that as 121 line in the tsne_pytorch.py, there may be out of bounds:

119 for i in range(d):
120     if l[i, 1] != 0:
121         M[:, i+1] = M[:, i]
122         i += 1

Concretely, i may equal to d-1 in 121 line which causes M[:,i+1] will be out of bounds(we know M is dxd).
I wonder if the modified code as follow is right?

for i in range(d-1):
    if l[i, 1] != 0:
        M[:, i+1] = M[:, i]
        i += 1

rang(d) function do not cover the index d, and d is get from (n, d) = X.shape so may be something else wrong not here

You are right, but i may equal to d-1, then M[:,i+1] actually is M[:,d] which will occur errors.

I got it. The matrix M is a dxd matrix which contains n eigenvectors in X.t() * X matrix
I changed the iteration function to avoid this error, thank you for your reminder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants