Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:24:02+00:00 2026-06-15T12:24:02+00:00

I am trying to return a block of a matrix as an lvalue of

  • 0

I am trying to return a block of a matrix as an lvalue of a function. Let’s say my function looks like this:

Block<Derived> getBlock(MatrixXd & m, int i, int j, int row, int column)
{
    return m.block(i,j,row,column);
}

As it turns out, it seems that C++ compiler understands that block() operator gives only temporary value and so returning it as an lvalue is prohibited by the compiler. However, in Eigen documentation there is some example that we can use Eigen as an lvalue (http://eigen.tuxfamily.org/dox/TutorialBlockOperations.html#TutorialBlockOperationsUsing) so I am wondering how we couldn’t do the same with function return.

a.block(0,0,2,3) = a.block(2,1,2,3);

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:24:04+00:00Added an answer on June 15, 2026 at 12:24 pm

    I want to put what I found myself so it might be helpful to someone else:

    My basic solution is to know what derived type you want the block to be. In this case:

    Block<MatrixXd> getBlock(MatrixXd & m, int i, int j, int row, int column)
    {
        return m.block(i,j,row,column);
    }
    

    It is interesting to me to notice that this method will return the reference to the content of matrix m by default. So if we do:

    MatrixXd m = MatrixXd::Zero(10,10);
    Block<MatrixXd> myBlock = getBlock(m, 1, 1, 3, 3);
    myBlock << 1, 0, 0, 
               0, 1, 0, 
               0, 0, 1;
    

    The content in matrix m will be modified as well. Note that, however,

    MatrixXd m = MatrixXd::Zero(10,10);
    MatrixXd myBlock = getBlock(m, 1, 1, 3, 3);
    myBlock << 1, 0, 0, 
               0, 1, 0, 
               0, 0, 1;
    

    will not work. My understanding is that once we convert the block to another type Eigen makes a copy of the data before conversion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to return the value that a $ajax call returns, from a function
I am trying to return the value by using unix_timestamp function but it behaves
I'm trying to block all non-localhost attempts to access a Webrick process. This is
I'm trying to create a continuous block of memory in one function call that
I'm trying to return a value in a method that contains an animation block.
I'm trying to return a NSMutableArray from my block in my method, but when
So I am trying to correctly and fully javadoc comment this block of code
Possible Duplicate: returning UIImage from block Hi I'm trying to return dictionary of json
I am trying to get this return: Google API Into a Python iterable object
I am using Code Block with GNU GCC Compiler. And I am trying this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.