Topic: add array math functions to C++?


Author: gdr@cs.tamu.edu (Gabriel Dos Reis)
Date: Sat, 14 Aug 2004 19:13:29 GMT
Raw View
beliavsky@aol.com writes:

| v.Abazarov@comAcast.net (Victor Bazarov) wrote in message news:<ikULc.53$191.9@newsread1.dllstx09.us.to.verio.net>...
| > beliavsky@aol.com wrote:
| > > More math functions are going to be added to the C++ language.
| >
| > Are they?
| >
| >  > I think
| > > it would be beneficial to scientific programmers to make math
| > > functions "elemental" (in Fortran parlance) whenever possible.
| > > [...]
| >
| > Doesn't std::valarray already has some functionality similar to what
| > you're asking about?
|
| It does, but only for 1-dimensional arrays. Fortran arrays can have up
| to 7 dimensions, and I use up to 3-D arrays frequently. It would also
| be nice if slices could be designated with syntax such as x[1:7:3],
| referring to x[1], x[4], x[7], instead of using the 'slice' function.

Yes, but what is multidimensional for one C++ programmer is just
1-dimensional for another C++ programmer, with proper glasses.
Consequently, the valarray component provids slice and generalized
slice mechanism to create (the illusion of) multidimensional arrays
(or tensors in Physics/maths parlance).

| It's my impression that valarray is not very widely used, for some
| reason.

I suspect mostly for lack of explanation from those who understand and
use valarray, and parly because of some perpetual myths.

--
                                                        Gabriel Dos Reis
                                                         gdr@cs.tamu.edu
  Texas A&M University -- Computer Science Department
 301, Bright Building -- College Station, TX 77843-3112

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: beliavsky@aol.com
Date: Sun, 25 Jul 2004 02:06:19 GMT
Raw View
v.Abazarov@comAcast.net (Victor Bazarov) wrote in message news:<ikULc.53$191.9@newsread1.dllstx09.us.to.verio.net>...
> beliavsky@aol.com wrote:
> > More math functions are going to be added to the C++ language.
>
> Are they?
>
>  > I think
> > it would be beneficial to scientific programmers to make math
> > functions "elemental" (in Fortran parlance) whenever possible.
> > [...]
>
> Doesn't std::valarray already has some functionality similar to what
> you're asking about?

It does, but only for 1-dimensional arrays. Fortran arrays can have up
to 7 dimensions, and I use up to 3-D arrays frequently. It would also
be nice if slices could be designated with syntax such as x[1:7:3],
referring to x[1], x[4], x[7], instead of using the 'slice' function.

It's my impression that valarray is not very widely used, for some
reason.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: beliavsky@aol.com
Date: Thu, 22 Jul 2004 18:53:57 GMT
Raw View
More math functions are going to be added to the C++ language. I think
it would be beneficial to scientific programmers to make math
functions "elemental" (in Fortran parlance) whenever possible.

To explain, one change in the Fortran 90 standard is that built-in
functions like sin(x) can act on arrays of any dimension, as well as
scalars, returning an array of the same shape. Such functions are
called elemental. Fortran 95 introduced user-defined elemental
functions. Matlab also has this functionality, as does Python with the
Numeric or Numarray modules. Such array functionality makes it
possible to write shorter and clearer code, and it may make it easier
to port a code to a parallel machine, since many explicit loops can be
avoided.

Obviously, to do this, C++ needs a multidimensional array container.

One argument against this is "if programmers want this, they can use
Fortran". For both technical reasons (C++ has many features Fortran
does not) and political ones, this often is not possible.

On a related note, I think the restriction that random number
generators return a single value will reduce their usefulness. Usually
I want to generate a large vector or matrix of random variates. The
Intel Math Kernel Library provides vector RNGs callable from C or
Fortran -- see http://www.intel.com/software/products/mkl/features/vsf.htm
. Maybe this library should be adopted as a model. I wonder how well a
compiler will optimize a loop containing a call to a RNG.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@comAcast.net (Victor Bazarov)
Date: Thu, 22 Jul 2004 19:46:24 GMT
Raw View
beliavsky@aol.com wrote:
> More math functions are going to be added to the C++ language.

Are they?

 > I think
> it would be beneficial to scientific programmers to make math
> functions "elemental" (in Fortran parlance) whenever possible.
> [...]

Doesn't std::valarray already has some functionality similar to what
you're asking about?

The problem, I believe, is in the fact that C++'s arrays are rather
rudimentary (or so I heard).  And another question I have: why add
those functions to the language when they can easily be contained
within another library?...

V

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: loic.actarus.joly@wanadoo.fr (=?ISO-8859-1?Q?Lo=EFc_Joly?=)
Date: Thu, 22 Jul 2004 23:47:30 GMT
Raw View
Victor Bazarov wrote:

> beliavsky@aol.com wrote:
>=20
>> More math functions are going to be added to the C++ language.
>=20
>=20
> Are they?
>=20
>  > I think
>=20
>> it would be beneficial to scientific programmers to make math
>> functions "elemental" (in Fortran parlance) whenever possible.
>> [...]
>=20
>=20
> Doesn't std::valarray already has some functionality similar to what
> you're asking about?
>=20
> The problem, I believe, is in the fact that C++'s arrays are rather
> rudimentary (or so I heard).  And another question I have: why add
> those functions to the language when they can easily be contained
> within another library?...

Because if they are standard, they will enable better interoperability=20
betwee libraries ?

--=20
Lo=EFc

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]