Boost logo

Boost Users :

Subject: [Boost-users] newbie: initializing a matrix
From: Pete (null_geodesic_at_[hidden])
Date: 2008-09-05 13:09:58


The examples I've seen construct matrices using for loops, like:

    matrix<double> m (3, 3);
    for (unsigned i = 0; i < m.size1 (); ++ i)
        for (unsigned j = 0; j < m.size2 (); ++ j)
            m (i, j) = 3 * i + j;

but that's inconvenient. I have a matrix in mind, say:

double foo[3][3] = { { 1.0, 2.0, 3.0 }, { 2.0, 9.3, 8.1 }, { 3.0, 5.0, 2.3 } };
Is it possible to initialize a matrix<double> from a double[][]? How does one create a matrix without resorting to for loops or via n^2 assignments in the code?

Thanks!

      


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net