PDA

View Full Version : Row order in matrix filling



ErosOlmi
03-07-2010, 11:59
Usually thinBasic matrix filling follows column order.
Next thinBasic beta preview will have the possibility to fill matrix with row order.
Also:

it will not be mandatory to indicate starting index during filling. If missing, 1 or 1,1 will be assumed
it will not be mandatory to add line continuation. When indicating data, if rows ends with a comma(,) it will be automatically considered as line continuation

How: just using ( and ) before and after data.
Example:

Dim a(MaxX, MaxY) As Double

a() = ( 1, 2, 3,
4, 5, 6,
7, 8, 9 )

When using () syntax, data will be entered in the matrix in row order and now column order.

Petr Schreiber
04-07-2010, 09:35
Thanks Eros,

this is very much appreciated!


Petr

Charles Pegge
05-07-2010, 02:56
Just to clarify,Eros.

array(x,y) ?

matrix(column,row) ?

The x is the minor step and the y is the major step?


Charles

ErosOlmi
05-07-2010, 06:47
a() = 1, 2, 3,
4, 5, 6,
7, 8, 9

in memory would be filled following COLUMN order: 1, 4, 7, 2, 5, 8, 3, 6, 9
Column order is the standard way used by thinBasic



a() = ( 1, 2, 3,
4, 5, 6,
7, 8, 9 )
in memory would be filled following ROW order: 1, 2, 3, 4, 5, 6, 7, 8, 9

So () will influence the sequence in which data is entered in memory.

Charles Pegge
05-07-2010, 18:49
Thanks Eros,

As I understand it your first ( default order) follows the PB convention whereas your second way of entering data follows the C convention.

FORTRAN MATLAB & PB: array(minor index,major index) : column major order

C and most others: array(major index,minor index) : row major order


http://en.wikipedia.org/wiki/Row-major_order

I lose hours of sleep worrying about how matrices and other arrays are organised in memory :D

Charles

ErosOlmi
05-07-2010, 18:52
I lose hours of sleep worrying about how matrices and other arrays are organised in memory :D


Me too and still to come ;D

Petr Schreiber
26-08-2011, 08:51
To make things clear for newcomers to the forum, the syntax with () has been replaced with square brackets later in 2010 (such a changes are done because we are still in Beta stage).

Please see newer discussion on the topic here:
http://www.thinbasic.com/community/showthread.php?11327-Row-major-order&p=84409#post84409


Petr

kryton9
01-09-2011, 02:04
How do you guys keep track of this stuff? Got my head spinning :)