Default constructor for uninitialized StaticMatrix and StaticVector

Issue #245 resolved
Radu Serban created an issue

Currently, the default constructors for StaticMatrix and StaticVector initialize the objects with the default value (0 for integral types). It would be very useful to have an option for creating uninitialized matrices and vectors by default (an option that could be controlled through an argument to the compiler).

--Radu

Comments (6)

  1. Klaus Iglberger

    Hi Radu!

    Thanks a lot for creating this issue. We agree, being able to create an uninitialized StaticVector or StaticMatrix could be valuable for many Blaze users.

    An alternative to a command line parameter would be a separate constructor with a special flag parameter:

    blaze::StaticMatrix<double> A( blaze::uninitialized );  // Pass the 'blaze::uninitialized' flag to create skip the initialization with default values
    

    Would this approach be reasonable/possible for your application?

    Best regards,

    Klaus!

  2. Radu Serban reporter

    Hi Klaus,

    First of all, thank you for considering this proposal.

    Your suggestion would work, although it would require quite a bit of refactoring in our project (we have many classes with a large number of matrix member variables which would now have to be explicitly included in the constructor initializer lists).

    While acknowledging that I am biased on this issue, the ideal solution to me would be to have the default constructor create an uninitialized matrix and have a constructor with a flag to construct a matrix initialized to 0. ;-) But I certainly understand this would break other people's code. This is why I suggested the command line parameter solution (although that is not as flexible and is very likely a more involved change to Blaze).

    But I can certainly make it work with your suggestion as well.

    Thanks! Radu

  3. Klaus Iglberger

    Currently, the default constructors for StaticMatrix and StaticVector initialize the objects with the default value (0 for integral types). It would be very useful to have an option for creating uninitialized matrices and vectors by default (an option that could be controlled through an argument to the compiler).

    --Radu

  4. Klaus Iglberger

    Hi Radu!

    I have just pushed the three commits that enable the configuration of the default initialization of instances of StaticVector and StaticMatrix. I apologize for the delay, but hope that this is exactly what you need. Please feel free to report any problem you experience with the new feature.

    Best regards,

    Klaus!

  5. Klaus Iglberger

    Summary

    The feature has been implemented, tested, and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.6.

    BLAZE_USE_DEFAULT_INITIALIZATION

    The BLAZE_USE_DEFAULT_INITIALIZATION configuration switch enables/disables the element initialization in the default constructors of the StaticVector and StaticMatrix class templates (see the configuration file <blaze/config/Optimizations.h>). In case the switch is set to 1 all elements are initialized to their respective default. In case the switch is set to 0 the default initialization is skipped and the elements are not initialized. Please note that this switch is only effective in case the elements are of fundamental type (i.e. integral or floating point). In case the elements are of class type, this switch has no effect.

    Possible settings for the default initialization:

    • Disabled: 0
    • Enabled : 1

    Note: It is possible to (de-)activate the default initialization via command line or by defining this symbol manually before including any Blaze header file:

    #define BLAZE_USE_DEFAULT_INITIALIZATION 1
    #include <blaze/Blaze.h>
    
  6. Log in to comment