Differences between revisions 4 and 5
Revision 4 as of 2006-11-30 13:57:05
Size: 1333
Editor: Michael
Comment:
Revision 5 as of 2006-11-30 14:07:07
Size: 1339
Editor: Michael
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
row2 = table[2]; // returns the whole row. Only a pointer has to be referenced and thus it is damn fast! int[] row2 = table[2]; // returns the whole row. Only a pointer has to be referenced and thus it is damn fast!

We had a long and hard discussion about how java looks at 2 dimensional data. The result of this discussion is that - influenced by ia.numeric - throughout the whole system the first dimension of an array is counted as row, the second dimension as column (I don't remember the reasons why this should be the only and the right way to look at it).

This leads to

d = Double2d(row, column).

On the other hand we all organize (and think) in columns. Our data of one type for example is written in a column of a 2 dimensional table.

BUT: Java (and other languages) make it very easy to access a ROW from a 2 dimensional array.

Thus:

int[][] table = new int[rows][columns];
int[] row2 =  table[2]; // returns the whole row. Only a pointer has to be referenced and thus it is damn fast! 

How do we access a column?

int[] column2 = new int[table[0].length];
for(int i = 0; i< colunm2.length; i++){
    column2[i] = table[i][2];
}

From this it is immediately clear why it is an advantage to treat 2 dimensional arrays as d = Double2d(column, row) instead. The whole array manipulation algorithms suffer from this mistake. Either internally we have to handle the arrays upside down or every column access is incredibly slow and allocates unnecessary amounts of memory (the new column2 variable).

Herschel: PACS/LessonsLearned/Row/Column (last edited 2009-07-15 14:32:38 by localhost)