Generalisation of the use of lists in the IDL language [message #88602] |
Fri, 16 May 2014 08:09  |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
Folks,
I really appreciate the recent efforts from IDL to become more modern
(should I say "python-like"?) which made programming and data-exploring
much more fun. Lists, ordered-hashes and dictionaries (which made hashes
obsolete from my point of view) have replaced arrays, pointers and
structures in much of my recent code.
However, in addition to the performance problems raised by Tom
Grydeland, I also noticed that while my Input&Analysis workflow was made
more "elegant" thanks to the new features, it became a bit more tedious
when I arrived to the "output" (i.e. plotting or writing). Unlike NumPy,
where "everything is a list", IDL built-in routines still require arrays
as parameters.
I'll make an example:
IDL> data = list(indgen(10), /EXTRACT)
IDL> print, data[2:4] ; behaves like an array (almost)
2
3
4
IDL> data[2:4] = data[4:6] ; also like an array
IDL> data[2:4] = data[2:4]^2 ; this won't work
% Unable to convert variable to type object reference.
% Execution halted at: $MAIN$
IDL> p = plot(data[2:4]) ; this won't work either
% PLOT: REFORM: New subscripts must not change the number elements in
<OBJREF Array[1]>.
% Execution halted at: $MAIN$
IDL> p = plot(data[2:4]->toArray()) ; the ->toArray() is necessary
Mathematical operations on lists are not possible. I guess this wont
change because the "+" operator is already overloaded and "adds" the
elements to the list.
However, I was wondering if it would be theoretically possible that the
built-in routines like mean(), plot() etc. also accept lists as
arguments. I guess that the syntax would allow it, but at what costs?
I've already programmed several wrappers for IDL routines which made my
life easier (e.g. wrappers for read_csv and write_csv now accepting
dictionaries) and I know that others did (histogram returning lists from
Paulo: http://www.ppenteado.net/idl/histogram_pp-code.html )
Any thoughts about this, or is asking for more integration of lists an
impossible idea?
Fabien
|
|
|