470,833 Members | 1,345 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

valarray/slice_array

hello group,

is there a technical reason why slice_array do not have an
index-operator? is it complicated to extend slice_array with such an
index-operator?

cheers, chris
Jun 27 '08 #1
2 1644
Alf P. Steinbach schrieb:
* Chris Forone:
>>
is there a technical reason why slice_array do not have an
index-operator?

First, disclaimer: I'm not familiar with valarray.

But much of the reason that I'm not familiar with it is that valarray is
essentially an unfinished class.

One that isn't used in practice, the Most Useless part of the standard
library.

Who knows what the author had in mind?

That said, it looks like much of the purpose was to provide a class
where operations could be optimized by certain processors, performing
element operations in parallel, and that /could/ be easier for the
processor to do if direct modifictions of single elements was
prohibited. However, valarray itself allows modification of single
elements. So, it seems like something half-baked, with the design not
fully flushed out, but beware of the disclaimer above!

>is it complicated to extend slice_array with such an index-operator?

Yes, don't do it.

To avoid gross inefficiency you'd have to delve into your particular
implementation, i.e. non-portable code.

Otherwise you could always copy that subset to a new valarray, change a
single element, and copy the whole shebang back... :-)
Cheers, & hth.,

- Alf
thanks, chris
Jun 27 '08 #2
MiB
On 16 Jun., 07:03, "Alf P. Steinbach" <al...@start.nowrote:
* Chris Forone:
But much of the reason that I'm not familiar with it is that valarray is
essentially an unfinished class.

One that isn't used in practice, the Most Useless part of the standard library.

Who knows what the author had in mind?
Valarrays have been designed with linear algebra and numeric
computation in mind.
The internal memory layout is a one dimensional array (quick
operations on all elements and on two equally sized valarrays).
The slice_arrays allow elegant access e.g. to row/column vectors in
matrices, or for example the diagonal vector.

Tensor math also comes to mind as an area where valarrays can be
efficient as containers.

If you have to deal with big matrices, you learn to like the class.
Its not a very frequent task for most developers, though.

best,

Michael.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Christian Brechbühler | last post: by
6 posts views Thread by Steven T. Hatton | last post: by
3 posts views Thread by Peter | last post: by
2 posts views Thread by Michael Hopkins | last post: by
1 post views Thread by Oliver Block | last post: by
1 post views Thread by Dack | last post: by
1 post views Thread by holmescn | last post: by
43 posts views Thread by john | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.