473,395 Members | 1,987 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,395 software developers and data experts.

valarray or vector ?

Hi,
I am using vector and similar containers extensively for my project,
as well as boost circular_buffer_space_optimized (and adobe
circular_queue which is built over vector ). They all work with
iterator based concept.
As I need to refer a portion of the vector (or circular buffer )
from within a class , I need to store index (not iterators, as
container elements are movable ) or a pair of index within the class
(using std::distance to get index from iterator, all of my containers
are random access ). now from index , I create boost sub_range and use
it.
For arbitrary access, I store a vector<size_t>, and use boost
permutation_iterator with the index.
One point here, iterator is not very cheap when it is circular_buffer
(and space optimized version) , as it is not merely a pointer , and it
need to know container (i.e. store a ref to container) or store 3
pointers, one current pos, one for begin of buffer, one end of buffer
(boost uses former version).

But after that I came to a different concept , a concept of view,
which is used by boost uBLAS containers Blitz array and the STL low
profile container valarray. Now it seems slice_view , range_view are
cheaper for circular buffer, as only one reference to container is
stored (esp when using permutation_iterator or arbitrary sequence
access). Also seems cross referencing from one valarray to another is
easier due to slice concept which can be directly stored. and it also
provides some numeric operations.
In my case all of the arrays are one dimensional, and they are array
of some small struct (like point, tangent etc) most of them have some
geometric meaning. And mostly I want to have some numeric operations
on them (my original test implementation is in matlab and the array in
matlab is just like Blitz array with little more overhead)
I am little confused at this stage, which one to use. and if I use
valarray kind of thing , how to use stl algorithm's with it (i.e how
to get a iterator from it ? valarray is continuous so getting iterator
is not a problem, but not sure whether I can sort a slice) .

Can anyone help in this regard?

abir

Mar 22 '07 #1
1 4669
toton wrote:
Hi,
I am using vector and similar containers extensively for my project,
as well as boost circular_buffer_space_optimized (and adobe
circular_queue which is built over vector ). They all work with
iterator based concept.
As I need to refer a portion of the vector (or circular buffer )
from within a class , I need to store index (not iterators, as
container elements are movable ) or a pair of index within the class
(using std::distance to get index from iterator, all of my containers
are random access ). now from index , I create boost sub_range and use
it.
For arbitrary access, I store a vector<size_t>, and use boost
permutation_iterator with the index.
One point here, iterator is not very cheap when it is circular_buffer
(and space optimized version) , as it is not merely a pointer , and it
need to know container (i.e. store a ref to container) or store 3
pointers, one current pos, one for begin of buffer, one end of buffer
(boost uses former version).

But after that I came to a different concept , a concept of view,
which is used by boost uBLAS containers Blitz array and the STL low
profile container valarray. Now it seems slice_view , range_view are
cheaper for circular buffer, as only one reference to container is
stored (esp when using permutation_iterator or arbitrary sequence
access). Also seems cross referencing from one valarray to another is
easier due to slice concept which can be directly stored. and it also
provides some numeric operations.
In my case all of the arrays are one dimensional, and they are array
of some small struct (like point, tangent etc) most of them have some
geometric meaning. And mostly I want to have some numeric operations
on them (my original test implementation is in matlab and the array in
matlab is just like Blitz array with little more overhead)
I am little confused at this stage, which one to use. and if I use
valarray kind of thing , how to use stl algorithm's with it (i.e how
to get a iterator from it ? valarray is continuous so getting iterator
is not a problem, but not sure whether I can sort a slice) .

Can anyone help in this regard?

abir
Since they are all one dimensional, I would recommend using vector.

Fei
Mar 22 '07 #2

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...
2
by: Boris Sargos | last post by:
Hi, I wrote the Matrix class suggested by Stroustrup in his reference book, and in this aim, wrote too the following member function, which returns the ith row of the Matrix : ...
4
by: Daniel Brewer | last post by:
Hi there, I would like to define a general operator>> function for valarrays that allows the input of an arbitary sized array from a file. An example data file would be like: 0 1 2 3 4 5 6 4 5...
1
by: ES Kim | last post by:
comp.std.c++ would be a better place for this question. Forgive me, but I can't post anything on moderated newsgroups for some reason. valarray doesn't have iterators of its own, which makes...
2
by: Sanyi | last post by:
Hello, I've did some some numerical programs in C/C++ before, but decided to use STL to write neater code. Then again I don't want to give up speed so I have a couple of questions. Apparently...
10
by: Chris Forone | last post by:
Hello Group, there is some memberfunc for std::valarray to return a pointer to the first element in the array. How do i use this? Thanx a lot. HAND Chris
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: Daniel Pitts | last post by:
Please excuse my ramblings here. For a hobby project, I'm working on a simple ray-tracer. I've gone through a few iterations, and I wanted some opinions on my next idea for an iteration... My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.