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

Indexing Lie elements by Lie keys does not work as expected #88

Open
PeterKoepernik opened this issue Mar 8, 2024 · 2 comments
Open

Comments

@PeterKoepernik
Copy link

It seems that indexing a Lie with a LieKey does not yield the expected result. Example:

import roughpy as rp
lie = rp.Lie([1,2,3,4,5], width=2, depth=3, dtype=rp.DPReal)

print(f'lie = {lie}')

ctx = rp.get_context(2,3,rp.DPReal)
for key in ctx.lie_basis:
    print(f'lie[{key}] = {lie[key]}')

gives the following output.

lie = { 1(1) 2(2) 3([1,2]) 4([1,[1,2]]) 5([2,[1,2]]) }
lie[1] = 1
lie[2] = 2
lie[[1,2]] = 1
lie[[1,[1,2]]] = 1
lie[[2,[1,2]]] = 2

The first three lines are as expected, but, if I understand correctly, lines 4 to 6 should have given 3, 4, and 5, instead of 1, 1, and 2. At least judging by this and similar examples, it looks like the key is first converted to an integer i by replacing it with the first integer that appears in the representation of the key (for example [2,[1,2]] is replaced with 2), and then lie[i] is returned, which is the (i-1)'th element in the flattened underlying data array (indeed in the above example, lie[i] returns i for i=1,...,5).

Desktop:

  • OS: Ubuntu 22.04
  • roughpy version 0.1.1
@inakleinbottle
Copy link
Contributor

inakleinbottle commented Mar 14, 2024

OK so it seems there is a bug in the conversion from the Python Lie key into indices. For now the only solution I can offer is to index with integers instead:

import roughpy as rp
lie = rp.Lie([1,2,3,4,5], width=2, depth=3, dtype=rp.DPReal)

print(f'lie = {lie}')

ctx = rp.get_context(2,3,rp.DPReal)
for i, key in enumerate(ctx.lie_basis, 1):
    print(f'lie[{key}] = {lie[i]}')

This will give the expected:

lie[1] = 1
lie[2] = 2
lie[[1,2]] = 3
lie[[1,[1,2]]] = 4
lie[[2,[1,2]]] = 5

Notice that we have to start from 1, the integers are being seen as the internal representation of Lie keys and not as indices which is also a bug. This will be fixed later to meet expectations.

@PeterKoepernik
Copy link
Author

Yes that's what I've been doing, thanks!

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