Boost logo

Ublas :

Subject: [ublas] Manipulating submatrices
From: Filip Jeremic (jeremic_dd_at_[hidden])
Date: 2011-08-03 23:23:52


This has been puzzling me for a few hours, so maybe someone here can help. I am
trying to translate the following simple Matlab program into C++ using uBLAS:

>> R = eye(4);
>> R(:,3) = R(:,4);
>> R

R =

     1 0 0 0
     0 1 0 0
     0 0 0 0
     0 0 1 1

This is my attempt, yet it is not working:

#include <iostream>

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

using namespace boost::numeric::ublas;

int main ()
{
    matrix<double> Idmx = identity_matrix<double> (4);
    project (Idmx, range (0, 4), range (2, 3)) = project (Idmx, range (0, 4),
range (3, 4));

    std::cout << Idmx << std::endl;

    int temp;
    std::cin >> temp;
}

The output produced is:

[4,4]((1,0,0,0),(0,1,0,0),(0,0,0,0),(0,0,1,1))

I don't understand why the third row is now all zeroes. Can someone point me to
a solution?

Thank you!