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 7072733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:50:41+00:00 2026-05-28T05:50:41+00:00

Is there a way to implement using eigen something like (pseudocode): A = BooleanExpr(X)

  • 0

Is there a way to implement using eigen something like (pseudocode):

A = BooleanExpr(X) ? ExprTrue : ExprFalse;

where all variables are Eigen::Array’s. That is for each component of X, if BooleanExpr on that component is true, the corresponding component of A is computed as ExprTrue, otherwise it’s ExprFalse.

I implement it at the moment like:

COND = BooleanExpr(X).cast<double>();
A = COND * ExprTrue + (1-COND) * ExprFalse;

But this computes both Expr* on each component, which doesn’t feel right when Expr’s are expensive.

In fact I would like to generalize this to a piecewise-defined function of X, so I can compute something like (pseudocode):

A = PieceExpr[ IntExpr(X) ] ( B );

that is the result of an integer expression on component of X determines expression used to compute the corresponding component of A.

May be I’m just going the wrong way about it and there is a way to achieve the same result in eigen already, I just can’t figure it out.

  • 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-05-28T05:50:42+00:00Added an answer on May 28, 2026 at 5:50 am

    It looks like you need .select() as documented at http://eigen.tuxfamily.org/dox-devel/classEigen_1_1DenseBase.html#a7c7f8804e216885f49b70f61c7ae3bbb (I think that this works on arrays and matrices, contrary to what the documentation suggests).

    For the more general situation, I don’t know a nice way to achieve this other than nested selects.

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

Sidebar

Related Questions

Is there any way to implement something similar to Chatroulette without using Flash or
Is there a way to implement RESTful WebService using Spring 3 (or not) that
Is there a way to implement a singleton object in C++ that is: Lazily
Is there any way to implement a URL mechanisim in asp.net like it has
Is there a way to implement/use lambda functions in bash? I'm thinking of something
Is there a way to implement a CHECK constraint that checks a value against
Without using boost::thread and boost::bind directly, is there a way to implement the equivalent
Is there some way to implement Django like contains or icontains filters with Google
I would like to know if there is a way of using the notication
using MVC3, Code First (DbContext) Is there a way to implement (ideally) a facade

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.