comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Structure of arrays or arrays of structures?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Structure of arrays or arrays of structures? [message #64830] Fri, 23 January 2009 09:27
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> My $0.02: I reckon it depends on the problem you're dealing with, or how your data is
> assembled, or how you interact with your data. IMO, neither approach is suitable as an
> "always do it this way" method.

Wow! I guess there *has* been a change in Washington! ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Structure of arrays or arrays of structures? [message #64831 is a reply to message #64830] Fri, 23 January 2009 09:25 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Brian Larsen wrote:
> Thanks all,
>
> Some good points were raised, the statements about "...can quite easy
> create slices of your data set" and "...groups sets of data into
> consistent structures" resonated with me. I will play with array of
> structures for a while and see what I think. I have a feeling it will
> remedy a lot of annoying where() statements that occur since you cant
> "drop" array elements from a structure of arrays.

My $0.02: I reckon it depends on the problem you're dealing with, or how your data is
assembled, or how you interact with your data. IMO, neither approach is suitable as an
"always do it this way" method.

cheers,

paulv
Re: Structure of arrays or arrays of structures? [message #64837 is a reply to message #64831] Fri, 23 January 2009 07:23 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
Thanks all,

Some good points were raised, the statements about "...can quite easy
create slices of your data set" and "...groups sets of data into
consistent structures" resonated with me. I will play with array of
structures for a while and see what I think. I have a feeling it will
remedy a lot of annoying where() statements that occur since you cant
"drop" array elements from a structure of arrays.


Brian

------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
Re: Structure of arrays or arrays of structures? [message #64841 is a reply to message #64837] Fri, 23 January 2009 00:11 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Brian Larsen schrieb:
> All,
>
> this may be philosophy but I have fought with both today and I am
> wondering if there are pros and cons to the different
> implementations.
>
> My example is that when I read in text files I build a structure of
> arrays:
> IDL> help, data
> DATA STRUCT = -> <Anonymous> Array[1]
> IDL> help, data, /str
> ** Structure <1a07a08>, 5 tags, length=212480, data length=212480,
> refs=1:
> JD DOUBLE Array[5312]
> PAS0 DOUBLE Array[5312]
> PAS90 DOUBLE Array[5312]
> MEP0E3 DOUBLE Array[5312]
> MEP90E3 DOUBLE Array[5312]
>
> and when I read cdf data (at least from ACE) I get arrays of
> structures
> IDL> help, data
> DATA STRUCT = -> <Anonymous> Array[36451]
> IDL> help, data, /str
> ** Structure <19cf008>, 45 tags, length=200, data length=196, refs=1:
> DNUM DOUBLE 0.0000000
> YEAR LONG 2007
> DAY LONG 165
> HR LONG 0
> MIN LONG 0
> SEC FLOAT 8.98560
>
> Are there memory issues with one way or the other? Other things I
> haven't thought about?
>
> I prefer the feel of the structure of arrays since I like typing
> tmp = data.jd[0:10]
> more than I like typing
> tmp = data[0:10].jd

Hi

well with the last one you can quite easy create slices of your data set
by result = data[ix]. It also could be used with table widgets or for an
example by xvaredit.

Your prefered solution is easy to use for all kind of tag manipulation,
e.g. removing, renaming, adding another tag into the same structure.

Long time ago we have added reform_struct to our library.
http://www.fz-juelich.de/zb/datapool/page/439/00322_Bauer.pd f page 57
(text in german, examples in idl)

cheers
Reimar





>
>
> Cheers,
>
> Brian
>
> ------------------------------------------------------------ --------------
> Brian Larsen
> Boston University
> Center for Space Physics
> http://people.bu.edu/balarsen/Home/IDL
Re: Structure of arrays or arrays of structures? [message #64845 is a reply to message #64841] Thu, 22 January 2009 16:15 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Jan 22, 3:52 pm, Brian Larsen <balar...@gmail.com> wrote:
> All,
>
> this may be philosophy but I have fought with both today and I am
> wondering if there are pros and cons to the different
> implementations.
>
> My example is that when I read in text files I build a structure of
> arrays:
> IDL> help, data
> DATA            STRUCT    = -> <Anonymous> Array[1]
> IDL> help, data, /str
> ** Structure <1a07a08>, 5 tags, length=212480, data length=212480,
> refs=1:
>    JD              DOUBLE    Array[5312]
>    PAS0            DOUBLE    Array[5312]
>    PAS90           DOUBLE    Array[5312]
>    MEP0E3          DOUBLE    Array[5312]
>    MEP90E3         DOUBLE    Array[5312]
>
> and when I read cdf data (at least from ACE) I get arrays of
> structures
> IDL> help, data
> DATA            STRUCT    = -> <Anonymous> Array[36451]
> IDL> help, data, /str
> ** Structure <19cf008>, 45 tags, length=200, data length=196, refs=1:
>    DNUM            DOUBLE           0.0000000
>    YEAR            LONG              2007
>    DAY             LONG               165
>    HR              LONG                 0
>    MIN             LONG                 0
>    SEC             FLOAT           8.98560
>
> Are there memory issues with one way or the other? Other things I
> haven't thought about?
>
> I prefer the feel of the structure of arrays since I like typing
>    tmp = data.jd[0:10]
> more than I like typing
>    tmp = data[0:10].jd

My thoughts:

Both methods will be slower than pure arrays.

I believe the array-of-structures approach will be the slowest,
because every time you need to fetch a field (as your second example),
IDL has to assemble the array from structure parts. That's been my
experience anyway.

However, the array-of-structures approach is natural if you can think
of your data as a database, and you can add or remove more entries at
a later time. You can do this easily by filtering the array of
structures and/or appending, without destroying the existing entries.
For a structure of arrays you basically need to tear apart the
structure and re-build it if you want to change any of the contents.

The structure-of-arrays approach is natural when you will be passing
it as an _EXTRA argument, since for that you need all of your data
bundled into a single structure.

Craig
Re: Structure of arrays or arrays of structures? [message #64846 is a reply to message #64845] Thu, 22 January 2009 14:57 Go to previous message
TonyL is currently offline  TonyL
Messages: 14
Registered: November 2008
Junior Member
I think the array of structures is a preferable method because it
groups sets of data into consistent structures. When i store variables
into sav files for later deployment, i like to see where the sets
occur when i restore them.

Tony
Re: Structure of arrays or arrays of structures? [message #64847 is a reply to message #64846] Thu, 22 January 2009 14:32 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Jan 22, 1:52 pm, Brian Larsen <balar...@gmail.com> wrote:
> I prefer the feel of the structure of arrays since I like typing
>    tmp = data.jd[0:10]
> more than I like typing
>    tmp = data[0:10].jd

You can use either notation with an array of structures:

IDL> s = replicate({ a: 0, b: 0 }, 10)
IDL> s.a = findgen(10)
IDL> s.b = 3
IDL> print, s.a
0 1 2 3 4 5 6 7
8 9
IDL> print, s.b
3 3 3 3 3 3 3 3
3 3
IDL> print, s[7]
{ 7 3}

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Associate Research Scientist
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: BAR_PLOT with pairs of bars
Next Topic: A new version of GRAFFER

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:43:49 PDT 2025

Total time taken to generate the page: 0.00743 seconds