Boost logo

Ublas :

From: Harris, Chris GOSS EXT (Chris.Harris.EXT_at_[hidden])
Date: 2005-12-29 12:28:29


Sorry if my terminology was not clear. Here is text from the boost website on value_init.hpp. I hope this helps clarify what I meant. I want my matrix of doubles to be filled with values of 0.

The C++ standard [1] contains the definitions of zero-initialization and default-initialization. Informally, zero-initialization means that the object is given the initial value 0 (converted to the type) and default-initialization means that POD [2] types are zero-initialized, while class types are initialized with their corresponding default constructors. A declaration can contain an initializer, which specifies the object's initial value. The initializer can be just '()', which states that the object shall be default-initialized (but see below). However, if a declaration has no initializer and it is of a non-const, non-static POD type, the initial value is indeterminate:(see §8.5 for the accurate definitions).

int x ; // no initializer. x value is indeterminate.
std::string s ; // no initializer, s is default-constructed.
int y = int() ;
// y is initialized using copy-initialization
// but the temporary uses an empty set of parentheses as the initializer,
// so it is default-constructed.
// A default constructed POD type is zero-initialized,
// therefore, y == 0.
void foo ( std::string ) ;
foo ( std::string() ) ;
// the temporary string is default constructed
// as indicated by the initializer ()
 

-----Original Message-----
From: ublas-bounces_at_[hidden] [mailto:ublas-bounces_at_[hidden]] On Behalf Of ublas-request_at_[hidden]
Sent: Thursday, December 29, 2005 12:01 PM
To: ublas_at_[hidden]
Subject: ublas Digest, Vol 13, Issue 12

Send ublas mailing list submissions to
        ublas_at_[hidden]

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.boost.org/mailman/listinfo.cgi/ublas
or, via email, send a message with subject or body 'help' to
        ublas-request_at_[hidden]

You can reach the person managing the list at
        ublas-owner_at_[hidden]

When replying, please edit your Subject line so it is more specific than "Re: Contents of ublas digest..."

Today's Topics:

   1. Matrix Initialization (Harris, Chris GOSS EXT)
   2. Re: Matrix Initialization (Dima Sorkin)

----------------------------------------------------------------------

Message: 1
Date: Wed, 28 Dec 2005 11:16:34 -0500
From: "Harris, Chris GOSS EXT"
        <Chris.Harris.EXT_at_[hidden]>
Subject: [ublas] Matrix Initialization
To: <ublas_at_[hidden]>
Message-ID:
        <82468CCD61F4604CBBB5343F078F93052BB365_at_[hidden]>
        
Content-Type: text/plain; charset="us-ascii"

I am just getting started with UBLAS, using VC 7.1 Boost Version 1.32.0. I know there is a newer version version of boost. I tried it, and it exhibits the same behavior.
 
My question is on the class matrix.
 
The documentation for resize and for construction seem to be inconsistent. The constructor specifically states that the matrix values are uninitialized. ( Not default constructed ) The documentation for resize states that it Reallocates a matrix to hold
size1 rows of size2 elements. The existing elements of the matrix are preserved when specified.
 
Under the The Matrix concept
    The sizing constructor does not mention whether values are default initialized or not.
 
    Resize will
    Reallocate the matrix so that it can hold n1 rows and n2 columns.
    Erases or appends elements in order to bring the matrix to the prescribed size. Appended elements are value_type() copies.
    When p == false then existing elements are not preserved and elements will not appended as normal. Instead the matrix is in the same
state as that after an equivalent sizing constructor.
 
So if I use the constructor values are not default initialized. If I use the resize new values may or may not be default initialized, depending on if I wish to preserve old values.
 
Maybe matrix should behave like std::vector and always default initialize its values.
 
 
Thank you
 
Chris Harris
-------------- next part --------------
HTML attachment scrubbed and removed

------------------------------

Message: 2
Date: Thu, 29 Dec 2005 09:57:33 +0200
From: Dima Sorkin <dsorkin_at_[hidden]>
Subject: Re: [ublas] Matrix Initialization
To: ublas mailing list <ublas_at_[hidden]>
Message-ID: <1135843053.43b396ed727e9_at_[hidden]>
Content-Type: text/plain; charset=Windows-1255

Quoting "Harris, Chris GOSS EXT" :
> Maybe matrix should behave like std::vector and always default
> initialize its values.
Hi.
 I don't understand the difference...
 I always thought that in C++ "uninitialized" and "default constructed" is the same, as ( at high level ) for each "unitialized" object default constructor is called anyway, and then the call is simply optimized out if possible.

Regards,
 Dima.

------------------------------

_______________________________________________
ublas mailing list
ublas_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/ublas

End of ublas Digest, Vol 13, Issue 12
*************************************