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

2d array slicing in comprehension fails, array of arrays not supported #807

Closed
CervEdin opened this issue Apr 18, 2024 · 4 comments
Closed
Labels
bug resolved Issue is resolved and the feature or fix will be part of next release

Comments

@CervEdin
Copy link

I thought I could assign a slice of a 2d array in a list comprehension, but it seems to fail.

playground.mzn

array[int, int] of int: foos = [| 1, 0 |];

array[int] of int: bar = [
  r[1] | i in index_set_1of2(foos), r=foos[i, ..]
];
Playground.mzn:3.1-22
  in
variable declaration for 'bar'
  in
array comprehension expression
Playground.mzn:4.15-34
    with
i = 1
    with
r = <expression>
  in
array access
MiniZinc:
evaluation error: arrays of arrays not supported
Process finished with non-zero exit code 1.

Seen in latest.

@CervEdin
Copy link
Author

This is fine

array[int] of int: bar = [ foos[i, ..][1] | i in index_set_1of2(foos) ];

but not what I want 😞

@CervEdin
Copy link
Author

What I would really want is to be able to iterate over rows in a 2d array, like in other languages with comprehensions

[ r[1] | r in foos where r[2] == 0 ]

but just being able to assign r=ReallyLongTableNameTableThingy[i, ..] would go along way

@CervEdin
Copy link
Author

Apparently I can do

array[int] of int: bar = [ r[1] | i in 1..1, r=[1,2] ];

so I'm guessing this is a bug?

@cyderize cyderize added the bug label Apr 19, 2024
@cyderize
Copy link
Member

Yes it seems the slice is somehow not being type checked correctly.

As a workaround for now, this seems to work:

array[int] of int: bar = [
  r[1] | i in index_set_1of2(foos), r=array1d(foos[i, ..])
];

@cyderize cyderize added the resolved Issue is resolved and the feature or fix will be part of next release label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug resolved Issue is resolved and the feature or fix will be part of next release
Projects
None yet
Development

No branches or pull requests

2 participants