Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: matrices as vectors
Replies: 4   Last Post: Feb 22, 2013 12:43 PM

 Messages: [ Previous | Next ]
 Kaba Posts: 289 Registered: 5/23/11
Re: matrices as vectors
Posted: Feb 22, 2013 12:43 PM

20.2.2013 4:01, leonard14279@gmail.com wrote:
> The question is, are there already existing formulas for matrix operations,
> where the matrix is represented as a 1d-vector?

This isn't actually a math question; it's more about software
engineering. You wish to implement algorithms to compute with matrices.
How you store the matrix in the memory is a separate concern from what
the abstract algorithms do. What you need to do is to abstract this
detail away, so that you can implement things in the same abstraction
level as they are presented in mathematics, but also change the way the
matrix is stored, if you wish.

As noted in the book Matrix Computations, there are several ways to
organize computations, all of which are equivalent in mathematics, but
some of which perform faster because they utilize the cache of modern
computer more efficiently.

Most of the implementations of (dense) matrices use a contiguous block
of memory, as you describe, storing row-by-row (row-major), or
column-by-column (column-major). This localizes the memory better than,
say, allocating each row separately.

A scheme which strikes a good balance between performance and
flexibility is to precompute for each n-dimensional array an element
H in Z^n (n integers) such that given a coordinate x in Z^n you can
compute the linearized index I in Z as

I = sum_{i = 1}^n x_i H_i,

i.e. the dot product. For example, for a 2-dimensional array of width
100 and height 200, you would compute the index as (row-major)

I = y * 100 + x.

so that H = [1, 100].

--
http://kaba.hilvi.org

Date Subject Author
2/20/13 William Elliot
2/20/13 Michael Stemper
2/21/13 J.B. Wood
2/22/13 Kaba