Monday, December 3, 2012

2D Array: is it array of rows or columns?

Is 2D array an array of rows or columns? I think neither.

Due to symmetry, there is no more reason to think 2-D table is array of rows than it is an array of columns.

Similarly, multivariable functions can be composed out of singlevariate ones. That is F(x,y) can be represented by f(x) that, applied to x, returns f(y). This is what happens when you restrict (aka partially evaluate) the F(x,y) to specific value of x. Function is simplified. Similarly, you can have f(y) that returns F(x,y=fixed). Representing 2D arrays as arrays of arrays is known as currying.

Now, I have realized there are true multidimentional arrays in VHDL, array[1 to a, 1 to b] of Type in addition to array [1 to a] of array [1 to b], which I always used.

Though, VHDL FAQ 4.2.34  says that VHDL is "row major". Might be because you define an array constant (does not matter 2d-array or array of arrays) like

        constant resTable2: resolveTableType2 :=
                ( -- 'X' '0' '1' 'Z'
                    ('X','X','X','X'), -- 'X'
                    ('X','0','X','0'), -- '0'
                    ('X','X','1','1'), -- '1'
                    ('X','0','1','Z') -- 'Z'
and outermost index accesses the rows.  

No comments: