Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Column slices |
| Date | 2015-05-06 10:30 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <micmuc$jde$1@dont-email.me> (permalink) |
| References | <3f240d60-031e-4605-a07d-a9d20bed581b@googlegroups.com> |
On 06/05/2015 07:18, luser droog wrote:
> A dynamic array object is defined by its rank, list of dimension sizes,
> a pointer to the start of the data, AND a weighting vector which for
> simple uses merely caches the multiplications from the array-access
> formula but it affords us much greater flexibility as (I hope) we
> shall see...
>
> typedef struct arr {
> int rank;
> int *dims;
> int *weight;
> int *data;
> } *parr;
>
> All of the pointer members can be assigned locations within the
> same allocated block of memory as the struct itself (which we will
> call the header). But by replacing the earlier use of offsets
> and struct-hackery, the implementation of algorithms can be made
> independent of that actual memory layout within (or without) the
> block.
>
> The basic memory layout for a self-contained array object is
>
> rank dims weight data
> dims[0] dims[1] ... dims[rank-1]
> weight[0] weight[1] ... weight[rank-1]
> data[0] data[1] ... data[ product(dims)-1 ]
So for a 3x4x5 array it would be:
3 4 5
W0 W1 W2
D0 D1 ..... D59 ?
If the last index (the 0 to 4 one) varies more quickly, the data
consists of 3x4 rows of 5, or 3 blocks of (4 rows of 5). And the data
will be more like:
D(0,0,0) D(0,0,1),... D(0,0,4) D(0,1,0) .... D(2,3,3) D(2,3,4)
Presumably the W vector might be W0=12 W1=4 W2=1, to help locate
D[i][j][k], with the last W not really needed.
But where does the column slice come into it? To access any slice other
than a row, would need the ability to deal with an 'array' that has a
stride, or offset between elements, the stride being W0, W1 (or W2 for a
row).
>
> An indirect array sharing data (whole array or 1 or more row-slices)
> will have the following memory layout
>
> rank dims weight data
> dims[0] dims[1] ... dims[rank-1]
> weight[0] weight[1] ... weight[rank-1]
> //no data! it's somewhere else!
>
> And an indirect array containing an orthogonal slice along
> another axis will have the same layout as a basic indirect array,
> but with dims and weight suitably modified.
Don't forget 2D, 3D and N-dimensional slices, where the slice (for a 3D
array) might be rectangular 2D array (in, I think, 3 possible
orientations), or a cuboid, which is a 3D subarray (and might also come
in different orientations, although you can't tell apart from the
indexing order).
> Nothing implemented yet.
> typedef struct arr {
> int rank;
> int *dims;
> int *weight;
> int *data;
> } *parr;
Does it need a different struct depending on the array element type?
This also seems inefficient for small dimensions, for 2D for example
which perhaps is as high as is usually needed.
And for 1D, although I guess a different method is used for those,
unless it is possible for the number of dimensions to be variable? Ie.
be itself a (1D) vector, requiring a similarly sized vector of indices.
(I suppose an N-dimensional array of dimensions is a possibility but I
can't get my head around that!)
(I guess these arrays form part of a different language (APL?), and C is
used to implement it. For such purposes, I don't bother with
N-dimensional arrays at all, just have arrays of arrays to any degree.
It's probably not quite as efficient, but it's simpler. And there are no
multiplications involved.)
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Column slices luser droog <luser.droog@gmail.com> - 2015-05-05 23:18 -0700
Column slices asetofsymbols@gmail.com - 2015-05-06 00:26 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-06 02:33 -0700
Re: Column slices Bartc <bc@freeuk.com> - 2015-05-06 10:46 +0100
Re: Column slices asetofsymbols@gmail.com - 2015-05-07 11:02 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-07 14:05 -0700
Re: Column slices Nobody <nobody@nowhere.invalid> - 2015-05-06 08:29 +0100
Re: Column slices Bartc <bc@freeuk.com> - 2015-05-06 10:30 +0100
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-06 03:11 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-08 09:05 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-11 16:50 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-11 17:24 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-11 19:01 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 09:56 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-19 10:43 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-19 11:16 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-19 11:27 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 21:28 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:05 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 21:20 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:55 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:58 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-21 01:22 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-21 01:34 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-26 19:17 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-31 13:56 -0700
Re: Column slices Keith Thompson <kst-u@mib.org> - 2015-05-31 14:23 -0700
Re: Column slices Ian Collins <ian-news@hotmail.com> - 2015-06-01 09:37 +1200
Re: Column slices asetofsymbols@gmail.com - 2015-06-01 01:23 -0700
Re: Column slices Ian Collins <ian-news@hotmail.com> - 2015-06-01 20:35 +1200
Re: Column slices mark.bluemel@gmail.com - 2015-06-01 03:50 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-01 18:04 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-01 18:16 -0700
Re: Column slices "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-06-01 19:57 -0700
Re: Column slices Rosario19 <Ros@invalid.invalid> - 2015-06-02 08:30 +0200
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-02 00:22 -0700
Re: Column slices Ike Naar <ike@iceland.freeshell.org> - 2015-05-12 06:06 +0000
Re: Column slices Ike Naar <ike@iceland.freeshell.org> - 2015-05-12 21:15 +0000
Re: Column slices asetofsymbols@gmail.com - 2015-05-13 20:49 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-13 23:43 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-13 23:44 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-14 01:02 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-15 23:06 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-16 03:46 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-23 00:17 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-23 07:59 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-23 21:25 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-24 18:29 -0700
Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-24 18:08 -0700
Re: Column slices asetofsymbols@gmail.com - 2015-05-25 00:13 -0700
csiph-web