C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: valarray resize

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Harald Grossauer
Guest





PostPosted: Mon Jul 28, 2003 12:42 pm    Post subject: Re: valarray resize Reply with quote



Marc Schellens wrote:

Quote:
I learned (the hard way) that a valarray does not
copy its elements upont relocation when resize() is used.
At least for gcc 3.2 this is true. Is that standard conform?

Yes.

Quote:
And: If I make the valarray smaller with resize(), can I be sure
that at least then no data is lost?

No.

Quote:
thanks,
marc


Back to top
Marc Schellens
Guest





PostPosted: Tue Jul 29, 2003 6:24 am    Post subject: Re: valarray resize Reply with quote



Quote:
Marc Schellens wrote:

I learned (the hard way) that a valarray does not
copy its elements upon relocation when resize() is used.
Is that standard conform?


Yes.

And: If I make the valarray smaller with resize(),
can I be sure that at least then no data is lost?


No. In fact, it will almost certainly be lost.

A valarray is a *rigid* array [of numbers].
You aren't supposed to resize a valarray
except in very special circumstances.
For example, suppose that you want to create an array of valarray's

valarray<double> A[m]; // m is a positive constant

The C++ compiler calls the default constructor
to initialize each of the m valarray's
then you can use the resize operator
to give each valarray its appropriate size.

If you find that you need to resize a valarray
that you have already initialized consider the possibility
that you may have chosen the wrong type of container.
Consider, for example, vector class templates instead.

A valarray is conveninet for me because of the mathematical operaions.

I have two valarray<double>, l and r
r is equal size OR SMALLER than l.
Can I say in the latter case:

l=pow( l, r);

If not, any suggestions?
thanks,
marc


Back to top
Marc Schellens
Guest





PostPosted: Tue Jul 29, 2003 6:31 am    Post subject: Re: valarray resize Reply with quote



Quote:
A valarray is conveninet for me because of the mathematical operaions.
I have two valarray<double>, l and r
r is equal size OR SMALLER than l.

Sorry, I meant: ... OR LARGER ...

Quote:
Can I say in the latter case:

l=pow( l, r);

If not, any suggestions?
thanks,
marc



Back to top
John Harrison
Guest





PostPosted: Tue Jul 29, 2003 6:39 am    Post subject: Re: valarray resize Reply with quote


"Marc Schellens" <m_schellens (AT) hotmail (DOT) com> wrote

Quote:
A valarray is conveninet for me because of the mathematical operaions.
I have two valarray<double>, l and r
r is equal size OR SMALLER than l.

Sorry, I meant: ... OR LARGER ...

Can I say in the latter case:

l=pow( l, r);

If not, any suggestions?
thanks,
marc


It would not be hard to use vectors, and write simple functions to perform
the mathematical operations.

john



Back to top
Marc Schellens
Guest





PostPosted: Tue Jul 29, 2003 1:58 pm    Post subject: Re: valarray resize Reply with quote

Quote:
"Marc Schellens" <m_schellens (AT) hotmail (DOT) com> wrote in message
news:3F2614DD.7030603 (AT) hotmail (DOT) com...

A valarray is conveninet for me because of the mathematical operaions.
I have two valarray<double>, l and r
r is equal size OR SMALLER than l.

Sorry, I meant: ... OR LARGER ...


Can I say in the latter case:

l=pow( l, r);

If not, any suggestions?
thanks,
marc


It would not be hard to use vectors, and write simple functions to perform
the mathematical operations.

So does this mean, that for any function both valarray operands
must have the same size?
Of course I could write simple functions, but on the other hand,
exactly that is what valarrays are for, isn't it?
The performance might be also much better with valarrays.

Apart from that I don't see any reason why a valarray should loose its
contents when shrinking. Why is this (or can be) so?

thanks,
marc



Back to top
E. Robert Tisdale
Guest





PostPosted: Tue Jul 29, 2003 3:00 pm    Post subject: Re: valarray resize Reply with quote

Marc Schellens wrote:

Quote:
A valarray is conveninet for me because of the mathematical operaions.
I have two valarray<double>, l and r where l.size() <= r.size().
r is equal size OR SMALLER than l.
Can I say in the latter case:

l = pow(l, r);

If not, any suggestions?

First, you need to tell us what you mean by pow(l, r).



Back to top
Marc Schellens
Guest





PostPosted: Wed Jul 30, 2003 7:06 am    Post subject: Re: valarray resize Reply with quote

E. Robert Tisdale wrote:
Quote:
Marc Schellens wrote:

A valarray is conveninet for me because of the mathematical operaions.
I have two valarray<double>, l and r where l.size() <= r.size().
r is equal size OR SMALLER than l.
Can I say in the latter case:

l = pow(l, r);

If not, any suggestions?


First, you need to tell us what you mean by pow(l, r).


I meant the valarray pow function:


template valarray<Ty> pow(const valarray<Ty>& left,
const valarray<Ty>& right);

but this was just an example. Basically my question
was about all arithmetic valarray functions.
thanks,
marc



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.