The Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kaba

Posts: 289
Registered: 5/23/11
Re: matrices as vectors
Posted: Feb 22, 2013 12:43 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.