473,412 Members | 2,067 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,412 software developers and data experts.

std::valarray vs. blitz::Array

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
read is that he questions the worth of the valarray.

http://www.cs.bsu.edu/homepages/peb/...s/valarray.htm

He explains it may not be as well implemented, efficient, nor as versitile
as the offerings from blitz.

http://www.oonumerics.org/blitz/manual/blitz02.html#l30

Now, looking things over, it appears the blitz Array is more versitile than
the std::valarray. My immediate task is to convert a C-style 25x3 array of
float into someting that is a bit smarter, for example, I want to be able
to determine the size by asking it, rather than by using a global #define,
or a global const. I'm doing this for 3D graphics, and expect to have a lot
of use for multivariable mathematical functionality.

What do others think of the choice between these options?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
6 4302
Steven T. Hatton wrote:
I bought Josuttis's book

http://www.josuttis.com/libbook/

on the repeated recommendations of people in this newsgroup.
One of the first things I looked up was the std::valarray<>.
And what I read is that he questions the worth of the valarray.

http://www.cs.bsu.edu/homepages/peb/...s/valarray.htm

He explains [that] it may not be as well implemented,
efficient, nor as versatile as the offerings from blitz.

http://www.oonumerics.org/blitz/manual/blitz02.html#l30

Now, looking things over, it appears the blitz Array is more versatile than
the std::valarray. My immediate task is to convert a C-style 25x3 array of
float into something that is a bit smarter, for example, I want to be able
to determine the size by asking it, rather than by using a global #define,
or a global const. I'm doing this for 3D graphics, and expect to have a lot
of use for multivariable mathematical functionality.

What do others think of the choice between these options?


You can read what Kent Budge has to say about valarray:

http://www.oonumerics.org/oon/oonstd/archive/0018.html

You and Josuttis are wrong.
You can't compare Blitz++ to valarray.
You might use valarray to implement something like Blitz++
but you wouldn't substitute one for the other.

The standard valarray templates were introduced, I believe,
because Kent Budge thought that
it might encourage C++ compiler developers for vector processors
to implement them as built-in types so that the compiler could
emit code to optimize use of the vector pipeline.
But C++ compiler developers weren't interested in investing
in optimizing C++ compilers that Fortran programmers wouldn't use.
Then vector processor technology very quickly became obsolete
and interest wained.

It is very difficult to realize an advantage over ordinary arrays
with valarray implementations and almost nobody uses them
so it is difficult to convince compiler developers that
they should invest in implementing and maintaining
high performance valarray templates.

Jul 22 '05 #2
E. Robert Tisdale wrote:
Steven T. Hatton wrote:
I bought Josuttis's book

http://www.josuttis.com/libbook/ http://www.cs.bsu.edu/homepages/peb/...s/valarray.htm

He explains [that] it may not be as well implemented,
efficient, nor as versatile as the offerings from blitz.

http://www.oonumerics.org/blitz/manual/blitz02.html#l30

Now, looking things over, it appears the blitz Array is more versatile
than the std::valarray. My immediate task is to convert a C-style 25x3
array of float into something that is a bit smarter, for example, I want
to be able to determine the size by asking it, rather than by using a
global #define, or a global const. I'm doing this for 3D graphics, and
expect to have a lot of use for multivariable mathematical functionality.

What do others think of the choice between these options?
You can read what Kent Budge has to say about valarray:

http://www.oonumerics.org/oon/oonstd/archive/0018.html


I'm not sure of all the feature valarray offers, nor what the ones I read
about really mean. It does appear to do some things I have done by hand.
The discussion of the boost::multi_array addresses one problematic issue
with traditional C-style arrays. That is the loss of information at
function call boundaries. I don't know if valarray overcomes that
limitation or not. It's my understanding that a valarray can grow
dynamically and rotate cylindrically. There have been times when such
functionality would have been nice, 'out of the box'.

As for tensors. There are two worlds. The world of mathematics says (IMHO):

A scalar is a zero-index (or one index if you like) geometric object with
one component whose associated value is a function of its position, and is
invariant under a group of transformations defined for an n-dimensionall
space. Its value can be determined in a particular coordinate system using
a specified system of measurement.

A vector is an n-index geometric object with n components whose associated
value is invariant under a group of transformations. Its value can be
expressed as an n value function of n arguments where n is the number of
dimensions in the space where the vector is defined.

A tensor is an m-index geometric object with n^m components, invarian under
a group of transformations in the n-dimensional space in which it is
defined. Its components can be expressed in terms of n^m functions of an
n-tuple defined by a coordinate system assigned to the space where the
tensor is defined.

A scalar is a tensor. (IMHO)
A vector is a tensor.

The things called scalar, vector, and tensor in the computer field, are not.
You and Josuttis are wrong.
You can't compare Blitz++ to valarray.
You might use valarray to implement something like Blitz++
but you wouldn't substitute one for the other.
From a quick comparison, it looked as if the blitz++ Array types provide a
superset of what valarray offers. But I will freely admit, such
appearances can be deceptive.

I did a google for / Blitz++ Array valarray / and found a boost this:

http://www.boost.org/libs/multi_array/doc/user.html

To use Boost.MultiArray, you must include the header boost/multi_array.hpp
in your source. This file brings the following declarations into scope:

namespace boost {

namespace multi_array_types {
typedef *implementation-defined* index;
typedef *implementation-defined* size_type;
typedef *implementation-defined* difference_type;
typedef *implementation-defined* index_range;
typedef *implementation-defined* extent_range;
typedef *implementation-defined* index_gen;
typedef *implementation-defined* extent_gen;
}

template <typename ValueType,
std::size_t NumDims,
typename Allocator = std::allocator<ValueType> >
class multi_array;

template <typename ValueType,
std::size_t NumDims>
class multi_array_ref;

template <typename ValueType,
std::size_t NumDims>
class const_multi_array_ref;

multi_array_types::extent_gen extents;
multi_array_types::index_gen indices;

template <typename Array, int N> class subarray_gen;
template <typename Array, int N> class const_subarray_gen;
template <typename Array, int N> class array_view_gen;
template <typename Array, int N> class const_array_view_gen;

class c_storage_order;
class fortran_storage_order;
template <std::size_t NumDims> class general_storage_order;

}

Then vector processor technology very quickly became obsolete
and interest wained.
I'm more interested in the ability to map the same collection of values in
different way by changing the indexing and stride.
It is very difficult to realize an advantage over ordinary arrays
with valarray implementations and almost nobody uses them
so it is difficult to convince compiler developers that
they should invest in implementing and maintaining
high performance valarray templates.


I suspect all the functionality I would want from such a thing will be
available in boost, blitz, MTL, or similar.

I'm very interested in exploring the different C++ libraries and comparing
them to what Mathematica does. As far as manipulating multipli-indexed
collections of values, Mathematica is incredible.

--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #3

Steven T. Hatton wrote:
Now, looking things over, it appears the blitz Array is more versitile than
the std::valarray. My immediate task is to convert a C-style 25x3 array of
float into someting that is a bit smarter, for example, I want to be able
to determine the size by asking it, rather than by using a global #define,
or a global const. I'm doing this for 3D graphics, and expect to have a lot
of use for multivariable mathematical functionality.


If you're doing what I think you're doing, you're going about it in a
roundabout way. Are you talking about a 25 member array of 3 element
vectors? In that case, make a 3d vector class and then use vector<vector3d>.

Even if not, consider a matrix<25,3> class.

If you're doing multi-dimensional matrix math, C++ can still sport
effeciency approaching Fortran's via the use of some kind of expression
templates to defer element by element calculation until all operations
are queued. All this even without requiring valarray or Blitz::array.

I see no benefits whatsoever to keeping 3d vectors as naked 3 element
arrays.

mark

Jul 22 '05 #4
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:sK********************@speakeasy.net...
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
read is that he questions the worth of the valarray.

http://www.cs.bsu.edu/homepages/peb/...s/valarray.htm

He explains it may not be as well implemented, efficient, nor as versitile
as the offerings from blitz.

http://www.oonumerics.org/blitz/manual/blitz02.html#l30

Now, looking things over, it appears the blitz Array is more versitile than the std::valarray. My immediate task is to convert a C-style 25x3 array of
float into someting that is a bit smarter, for example, I want to be able
to determine the size by asking it, rather than by using a global #define,
or a global const. I'm doing this for 3D graphics, and expect to have a lot of use for multivariable mathematical functionality.

What do others think of the choice between these options?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org


I have no experience with Blitz but I inherited some code which used
valarray and it caused me a lot of trouble. Aside from being poorly designed
it appears to me that valarray is poorly implemented in some libraries.

I would never use valarray if I had a choice. I think the committee made a
big mistake including it in the 98 standard.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #5
Steven T. Hatton wrote:
I'm more interested in the ability
to map the same collection of values in different ways
by changing the indexing and stride.


Take a look at
The Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

and the Vector, Signal and Image Processing Library

http://www.vsipl.org/

and the High Performance Embedded Computing Software Initiative

http://www.hpec-si.org/
What would help you most right now is to forget about the libraries
and concentrate upon the Abstract Data Type (ADT).

Pick up a good book on Fortran 90 and study Fortran 90 arrays.
That's the basic model for Blitz++.

MATLAB is often cited but, as convenient as MATLAB is,
it is difficult to write large, reliable programs in MATLAB.

BEWARE of class template implementations.
They can produce fast, efficient codes
but even short programs take a long time to compile
so the test/debug development cycle slows to a crawl.

Jul 22 '05 #6
In message <de********************@speakeasy.net>, Steven T. Hatton
<su******@setidava.kushan.aa> writes

[...]
I'm not sure of all the feature valarray offers, nor what the ones I read
about really mean. It does appear to do some things I have done by hand.
The discussion of the boost::multi_array addresses one problematic issue
with traditional C-style arrays. That is the loss of information at
function call boundaries. I don't know if valarray overcomes that
limitation or not. It's my understanding that a valarray can grow
dynamically and rotate cylindrically. There have been times when such
functionality would have been nice, 'out of the box'.


Unfortunately, valarray *doesn't* possess it. Unlike std::vector,
valarray's resize() doesn't "grow" the array, it completely clears the
existing contents.

--
Richard Herring
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim West | last post by:
The following compiles with g++ 3.3.2, but fails with Intel icc 7.1 with the error: asdf.cc(6): error: expression must be an lvalue or a function designator f1(&arr); Is this undefined...
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...
10
by: Tony Young | last post by:
Hi, I have an array of integer. I need to find the max of the 0th, 3th, 6th , 9th, ... elements in the array. I wonder if STL (standard template library) provides a way to manipulate only part...
3
by: klucar | last post by:
I'll start off differently by showing what I know how to do: valarray<float> va(100, 0.0f); float* fp; fp = &va; some_c_function( fp, va.size() ); What I want to do though is quite the...
10
by: The Cool Giraffe | last post by:
I got a hint recently (guess where, hehe) and was directly pointed to the vector class. Now, i have no issues using that way but i'm concerned about the performance issue. Which is fastest...
9
by: Jim | last post by:
Hi, I want to declare that that a valarray of a certain name exist at the beginning of some code, but I can't instatiate it until I've read in some parameters later on in a for loop i.e. int...
3
by: Alex Howlett | last post by:
Stroustrup page 663 says this: valarray<floatv1 (1000); // 1000 elements with value float()==0.0F But when I run this program: -------------------------------------- #include <valarray>...
1
by: toton | last post by:
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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.