473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1755
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian Brechbühler | last post by:
The template std::valarray behaves pretty much like a mathematical vector. Arithmetic operators apply elementwise. Now I'd like to extend this to a user-defined type, e.g., complex. ...
6
by: Steven T. Hatton | last post by:
I bought Josuttis's book on the repeated recommendations of people in this newsgroup. http://www.josuttis.com/libbook/ One of the first things I looked up was the std::valarray<>. And what I...
3
by: Peter | last post by:
Hi everybody, I am unfortunately stuck with a probably very simple problem. I made a class called Particle with a valarray (STL) as a class member. The code for the class goes like this: ...
2
by: Michael Hopkins | last post by:
Hi all I have a subclass of valarray<T> thus template <typename T> class uo_val : public std::valarray<T> { public: uo_val ( ) : std::valarray<T>() {} uo_val (const int sz ) :...
1
by: Oliver Block | last post by:
I have a (9x9) valarray std::valarray<int> va(81); va = 0; // fil all elements with zeros I am taking row slices like that: std::slice_array<int> slr = va; // r = row; a value between 1...
1
by: Dack | last post by:
Hi, I want to track memory leaks in my application (that is using <valarray>). I used the following code: #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> But then, when I...
1
by: holmescn | last post by:
I wrote the code below: #include <valarray> using namespace std; int main() { valarray<doublev0(10); valarray<doublev1 = v0; } I compiled it with mingw 3.4.5 .but i have got an error said
2
by: john | last post by:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is mentioned: "valarray operator-() const; // result= -v for every element // similarly: +, ~, !" I checked the web and...
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.