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

Add support for nested list comprehension #142

Open
tohrnii opened this issue Feb 10, 2023 · 3 comments
Open

Add support for nested list comprehension #142

tohrnii opened this issue Feb 10, 2023 · 3 comments
Assignees

Comments

@tohrnii
Copy link
Contributor

tohrnii commented Feb 10, 2023

We should allow users to define nested list comprehension like:

let transpose = [[row[i] for row in matrix] for i in 0..5]

Related issue: #132

@tohrnii tohrnii added the v0.2 label Feb 13, 2023
@tohrnii tohrnii assigned Fumuran and tohrnii and unassigned Fumuran Feb 13, 2023
@tohrnii tohrnii removed the v0.2 label Feb 16, 2023
@bobbinth
Copy link
Contributor

bobbinth commented Jul 2, 2023

@tohrnii, @bitwalker - is this still relevant or has it been addressed with the new structure?

@bitwalker
Copy link
Contributor

We currently restrict comprehension bodies to scalar expressions, but we could easily relax that. I was under the impression we didn't want to support nested comprehensions, but there's no reason why we can't.

@bobbinth
Copy link
Contributor

bobbinth commented Jul 3, 2023

Yes, I think one place where this would be useful is in computing MDS matrix multiplication for RPO constraints, which would look something like this:

const MDS = [
    [7, 23, 8, 26, 13, 10, 9, 7, 6, 22, 21, 8],
    [8, 7, 23, 8, 26, 13, 10, 9, 7, 6, 22, 21],
    [21, 8, 7, 23, 8, 26, 13, 10, 9, 7, 6, 22],
    [22, 21, 8, 7, 23, 8, 26, 13, 10, 9, 7, 6],
    [6, 22, 21, 8, 7, 23, 8, 26, 13, 10, 9, 7],
    [7, 6, 22, 21, 8, 7, 23, 8, 26, 13, 10, 9],
    [9, 7, 6, 22, 21, 8, 7, 23, 8, 26, 13, 10],
    [10, 9, 7, 6, 22, 21, 8, 7, 23, 8, 26, 13],
    [13, 10, 9, 7, 6, 22, 21, 8, 7, 23, 8, 26],
    [26, 13, 10, 9, 7, 6, 22, 21, 8, 7, 23, 8],
    [8, 26, 13, 10, 9, 7, 6, 22, 21, 8, 7, 23],
    [23, 8, 26, 13, 10, 9, 7, 6, 22, 21, 8, 7]
]

fn apply_mds(state: vector[12]) -> vector[12]:
    return [sum([s * m for (s, m) in (state, mds_row)]) for mds_row in MDS]

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

4 participants