473,320 Members | 2,161 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.

slice_iter and valarray

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 :

std::valarray<double> MyMatrix::Row ( int i) const {
return ( ValArarray [slice ( (i-1) * nbCols, nbCols,
1) ] ) ;
}

where ValArray is of type std::valarray<double>.

No problem with the compilation, but while running, it crashes when the
destructor of the valarray is called. I don't understand

1) why it crashes
2) why Stroustrup advises to return a Slice_iter object instead of a
valarray ?
Mathematically, MyMatrix::Row(int) returns a vector. How would I create a
class MyVector compatible with this function MyMatrix::Row(int) ?
Thanks,
Boris.
Jul 22 '05 #1
2 3801
Boris Sargos wrote:
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 i'th row of the Matrix:

std::valarray<double> MyMatrix::Row(int i) const {
return ValArarray[slice((i-1) * nbCols, nbCols, 1)];
}

where ValArray is of type std::valarray<double>.

No problem with the compilation but, while running,
it crashes when the destructor of the valarray is called.
I don't understand

1) why it crashes
2) why Stroustrup advises to return a Slice_iter object
instead of a valarray ?

Mathematically, MyMatrix::Row(int) returns a vector.
How would I create a class MyVector
compatible with this function MyMatrix::Row(int)?


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

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

Also, visit
The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/

Jul 22 '05 #2
I included a valarray in my code and when trying to compile, Visual
Studio 6.0 gave these errors:

c:\program files\microsoft visual studio\vc98\include\valarray(104) :
warning
C4003: not enough actual parameters for macro 'min'
c:\program files\microsoft visual studio\vc98\include\valarray(110) :
warning
C4003: not enough actual parameters for macro 'max'

followed by 30 more, all in the code for valarray. After some advice and
googling I found out that the problems stems from the fact that in
windef.h there are two macros defined named min and max.

Now in a message to this group from 2002 the solution offered was to put
#undef min and #undef max just before including valarry. While this
works I also found another solution: One can disable those
Windows-specific macros with the preprocessor define NOMINMAX, as is
also described in Microsoft Knowledge Base Article - 143208,
http://support.microsoft.com/default...b;en-us;143208

I hope this is not too trivial a problem but I wanted to spare others
the hour or so I spent looking for a solution to this problem.

Best regards,

Sebastian
Jul 22 '05 #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: ...
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: 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: 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...
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...
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:
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.