From: Tuomo Keskitalo <Tuomo.Keskitalo@iki.fi>
To: Gerard Jungman <jungman@lanl.gov>
Cc: GSL Discuss Mailing List <gsl-discuss@sourceware.org>
Subject: Re: new double precision data structure?
Date: Sun, 27 Sep 2009 08:03:00 -0000 [thread overview]
Message-ID: <4ABF1C3C.6070801@iki.fi> (raw)
In-Reply-To: <1253062179.23092.971.camel@manticore.lanl.gov>
[-- Attachment #1: Type: text/plain, Size: 674 bytes --]
On 09/16/2009 03:49 AM, Gerard Jungman wrote:
> It smells like a view, and indeed it is. But it is a notion of
> view which is more central to the design than the current one.
> Everything should be a view.
I think we really need to sort the data structure out now.
I'm not sure what you have in mind, but to get some discussion going on,
I've attached an (incomplete and untested) idea for a general
n-dimensional double precision data structure. Is this anything like
what you pictured?
I'd like to hear people's comments on this. Would something like this be
of use? Feel free to give your full critique.
--
Tuomo.Keskitalo@iki.fi
http://iki.fi/tuomo.keskitalo
[-- Attachment #2: newblock.c --]
[-- Type: text/x-csrc, Size: 4355 bytes --]
/* newblock.c - An idea for n-dimensional double precision data
structure. This is pseudocode to describe the idea, does not
compile.
*/
/* Structure for n-dimensional double precision data storage */
typedef struct
{
size_t dim; /* data structure dimension */
size_t * sizes; /* dimensions of system, e.g. {3,4,5} for real 3*4*5 tensor */
double * data; /* continuous data storage */
size_t layout; /* data layout type - LAST_INDEX_CONTINUOUS =
"column major" for matrices, or
FIRST_INDEX_CONTINUOUS = "row major" (default)
for matrices. Note: It might be possible to
extend this to support other storage schemes,
e.g. diagonal/banded storage
BANDED_INDEX_CONTINUOUS. */
} base_block;
/* Structure for a generic n-dimensional view object to access base
block data. Access to data storage is done via this view
object. There can be multiple views referring to the same data
storage.
*/
typedef struct
{
size_t * firstcell; /* indices to first access cell (minimum indices) */
size_t * lastcell; /* indices to last access cell (maximum indices) */
size_t * stride; /* strides for each dimension for the view */
base_block * block;
double * data; /* pointer to block->data */
size_t owner; /* indicator for view owning the data */
} base_view;
/* vector object based on base block and view */
typedef struct
{
base_view * view;
} vector;
/* matrix object based on base block and view */
typedef struct
{
base_view * view;
} matrix;
matrix * matrix_alloc (size_t n1, size_t n2)
{
/* Allocates matrix object (both view and storage objects) in
row-major layout. */
// 1. allocate base_block with dim=2, sizes={n1,n2}
// 2. allocate base_view with firstcell={1,1},
// lastcell={n1,n2}, stride={0,0} (=whole matrix)
// 3. set view owner=TRUE
// 4. return base_view;
}
matrix * matrix_alloc_with_layout (size_t n1, size_t n2, size_t layout)
{
/* Allocates matrix object (both view and storage objects) in the
specified layout. */
}
int vector_alloc_view_of_matrix (vector * v, matrix * m,
size_t * firstcell, size_t * lastcell,
size_t * stride)
{
/* Creates a new vector view of the matrix m */
// 1. allocate base_view with given firstcell, lastcell and strides
// 2. associate view with the storage
// 3. set owner=FALSE
// 4. return base_view;
}
/* Example code */
int main (void)
{
matrix * a;
matrix * b;
vector * v;
int retval;
/* allocate matrix with 3 rows and 4 columns */
a = matrix_alloc (3, 4);
/* User can change the layout between row- and column-major at any
point. After change to column-major, those GSL functions that
require row-major storage would raise error if the matrix is
passed to them.
*/
retval = matrix_set_layout (a, LAST_INDEX_CONTINUOUS);
{
double temp[] = { 0, 10, 20, 01, 11, 21, 02, 12, 22, 03, 13, 23 };
size_t templen = 12;
retval = matrix_set_doublevec (a, temp, templen);
/* This would initialize matrix
a = [00 01 02 03
10 11 12 13
20 21 22 23] */
}
/* Set up a vector view of the diagonal */
const size_t b0[] = { 1, 1 };
const size_t e0[] = { 3, 3 };
const size_t s0[] = { 1, 1 };
retval = vector_alloc_view_of_matrix (v, a, &b0, &e0, &s0);
/* Access cells in matrix through the vector */
double val;
val = vector_get(v, 1); // returns 00 from matrix a
val = vector_get(v, 2); // returns 11 from matrix a
val = vector_get(v, 3); // returns 22 from matrix a
retval = vector_set(v, 2, 55); // sets value 55 in place of 11 to matrix a
size_t l;
l = vector_length(v); // returns 3;
double diag[3];
retval = vector_get_doublevec (&diag, v); // copies diagonal element values to diag
}
/* complex number matrix (one possible implementation) based on base
block and view */
typedef struct
{
base_view * view;
} complex_matrix;
complex_matrix * complex_matrix_alloc (size_t n1, size_t n2) {
/* Allocates matrix object (both view and storage objects) */
// 1. allocate base_block with dim=3, sizes={n1,n2,2}, so that
// the last dimension spans the real and imaginary parts
// 2. allocate base_view with firstcell={1,1,1} and
// lastcell={n1,n2,2} (=whole matrix)
// 3. set view owner=TRUE
// 4. return base_view;
}
next prev parent reply other threads:[~2009-09-27 8:03 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 17:07 ode-initval implicit solvers and development Tuomo Keskitalo
2008-10-01 18:29 ` Brian Gough
2008-10-09 13:22 ` Brian Gough
2008-11-02 17:35 ` Tuomo Keskitalo
2008-11-03 18:09 ` Brian Gough
2009-01-24 11:52 ` Tuomo Keskitalo
2009-02-01 17:01 ` Brian Gough
2009-02-02 17:05 ` Tuomo Keskitalo
2009-03-01 14:37 ` Tuomo Keskitalo
2009-03-03 16:34 ` Brian Gough
2009-03-05 19:47 ` Tuomo Keskitalo
2009-03-05 19:54 ` Heikki Orsila
2009-03-06 20:03 ` Brian Gough
2009-04-05 12:28 ` Tuomo Keskitalo
2009-05-01 14:05 ` Tuomo Keskitalo
2009-05-04 11:23 ` Brian Gough
2009-05-08 10:51 ` Brian Gough
2009-08-06 13:51 ` GSL 2.0 roadmap Tuomo Keskitalo
2009-08-21 20:42 ` Brian Gough
2009-08-27 11:42 ` Tuomo Keskitalo
2009-08-27 12:51 ` Robert G. Brown
2009-08-28 13:57 ` Jordi Burguet Castell
2009-08-27 17:13 ` Robert G. Brown
2009-08-28 13:58 ` Brian Gough
2009-08-27 23:10 ` Gerard Jungman
2009-08-27 23:13 ` GSL 2.0 roadmap (one man's view) Gerard Jungman
2009-08-28 13:58 ` Brian Gough
2009-09-16 0:43 ` Gerard Jungman
2009-09-03 19:37 ` Brian Gough
2009-09-16 0:44 ` Gerard Jungman
2009-09-07 15:10 ` Brian Gough
2009-09-07 15:34 ` Rhys Ulerich
2009-09-07 18:21 ` Robert G. Brown
2009-09-16 0:47 ` Gerard Jungman
2009-09-18 3:51 ` column-major Z F
2009-09-21 12:08 ` column-major Brian Gough
2009-09-07 15:10 ` GSL 2.0 roadmap (one man's view) Brian Gough
2009-09-16 0:45 ` Gerard Jungman
2009-09-20 9:36 ` Tuomo Keskitalo
2009-09-20 13:23 ` Robert G. Brown
2009-09-20 15:31 ` Rhys Ulerich
2009-09-20 16:19 ` Robert G. Brown
2009-09-21 15:13 ` Brian Gough
2009-09-20 15:08 ` Rhys Ulerich
2009-09-21 12:08 ` Brian Gough
2009-09-07 15:10 ` Brian Gough
2009-09-16 0:46 ` Gerard Jungman
2009-09-17 20:12 ` Brian Gough
2009-09-07 15:10 ` Brian Gough
2009-09-16 0:47 ` Gerard Jungman
2009-09-27 8:03 ` Tuomo Keskitalo [this message]
2009-09-28 8:44 ` new double precision data structure? James Bergstra
2009-09-28 15:48 ` Tuomo Keskitalo
2009-10-16 13:59 ` Brian Gough
2009-09-29 18:38 ` Gerard Jungman
2009-09-07 15:10 ` GSL 2.0 roadmap (one man's view) Brian Gough
2009-09-16 0:46 ` Gerard Jungman
2009-09-16 2:48 ` Robert G. Brown
2009-09-17 19:14 ` Brian Gough
2009-09-07 15:10 ` Brian Gough
2009-09-16 0:44 ` Gerard Jungman
2009-09-17 20:12 ` Brian Gough
[not found] ` <645d17210909090818u474f32f0q19a6334578b9f02c@mail.gmail.com>
2009-09-17 19:14 ` Brian Gough
2009-08-28 13:58 ` GSL 2.0 roadmap Brian Gough
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ABF1C3C.6070801@iki.fi \
--to=tuomo.keskitalo@iki.fi \
--cc=gsl-discuss@sourceware.org \
--cc=jungman@lanl.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).