static L matrixToList(Matrix m) {
if (m == null) null;
int w = m.getWidth(), h = m.getHeight(), n = w*h;
ret new RandomAccessAbstractList() {
public int size() { ret n; }
public A get(int i) {
ret m.get(i % w, i / w);
}
public A set(int i, A val) {
A old = m.get(i % w, i % h);
m.set(i % w, i / w, val);
ret old;
}
};
}