Closed pcaillou closed 9 years ago
You should not use the operator "as_matrix" as you use it.
If you want to create a matrix of {2,2}, you should use: matrix testMat <- 0 as_matrix
({2, 2});
Otherwise, GAMA don't know what to put in the matrix and build a empty matrix.
But it is true I do not know the good way to create a matrix composed of empty lists:
[];[]
[];[]
Original issue reported on code.google.com by patrick.taillandier
on 2014-03-15 15:25:44
(No text was entered with this change)
Original issue reported on code.google.com by patrick.taillandier
on 2014-03-15 19:33:23
There are many ways to create and fill matrices, but I think you have uncovered a bug
due to the ambiguity of the 'as_matrix' operator.
If you declare an attribute of a species, you would not have this problem, because
you could use the handy 'size:' and 'fill_with:' facets:
global {
matrix<list> m size: {10,10} fill_with: [];
…
}
However, when declaring a temporary variable, these options are not (yet) available.
And your intuition was good in using the 'as_matrix' operator, but its operational
semantics is definitely flawed: when the left-side argument is a container, 'as_matrix'
tries to convert this container to a matrix of the given size, but when you have something
else than a container it uses this left-side value to fill the matrix. So there is
no way to make it create a matrix of list, for instance, with this method.
You then have two workarounds :
1) (provided you update your code base, as I've been forced to fix some issues pertaining
to this construct):
matrix<list> m2 <- nil as_matrix {10,10};
m2[] <- [];
2)
list<list> lists <- [];
loop times: 100 {lists <+ [];}
matrix<list> m2 <- lists as_matrix {10, 10};
====
Finally, in order to remove the ambiguity present in 'as_matrix', I've also added a
new operator called 'matrix_with', which uses the same arguments (but in a different
order), and makes it clear that the second argument is used to fill the matrix (and
not to be casted into a matrix).
So, in your case, it would be, for instance :
matrix<list> m2 <- {10,10} matrix_with [];
I have committed all the changes.
Original issue reported on code.google.com by alexis.drogoul
on 2014-03-15 19:36:48
Original issue reported on code.google.com by
lvminh2k
on 2014-03-15 11:34:19