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

  • SEARCH
  • Home
  • 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 7539421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:22:37+00:00 2026-05-30T07:22:37+00:00

Another person in my office and I got into a discussion about which complex

  • 0

Another person in my office and I got into a discussion about which complex number matrix array format is more efficient: storing the real and imaginary parts interleaved, as in

struct {
    double real;
    double imag;
} Complex foo[m][n];

or by storing the real and imaginary parts of the matrix separately:

struct {
    double rarray[m][n];
    double iarray[m][n];
} CArray foo;

On the one hand, Complex[][] is more of a straightforward representation of an array of complex numbers, and might be easier to work on elementwise; on the other hand, it seems that CArray could be more efficient in general. For example, matrix multiplication can be done using 4 matrix multiplications of the component arrays using the CArray format, while the Complex[][] format seems as though it might suffer due to interleaving between the elements (since (a+bi)*(c+di) = (ad – bc) + (ac + bd)i). Apparently, MATLAB uses the latter format: enter link description here.

Are there any other sources that treat this question?

  • 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-30T07:22:39+00:00Added an answer on May 30, 2026 at 7:22 am

    This is the age old “array of structures vs structure of arrays” question applied to complex numbers. Like most performance questions, in general the answer is “it depends”, but in this case I would put my money on the array of structures version.

    The key to choosing efficient data structures for numerical computing is to keep data you’re typically going to need at the same time near each other in memory. Going out to main memory to get data is slow; you want to bring in one chunk of data at a time into cache and use all of that cache line as much as possible. Since you’re almost always going to need both the real and imaginary component of a complex number for most meaningful computations, storing them as arrays of (real,imaginary) pairs means that if you’re working on the real component, the imaginary component is almost always going to be sitting there already in cache ready to be computed upon.

    But it depends on access patterns. Just because the operations I imagine are going to benefit from the array of complex numbers, doesn’t mean you’re imagining the same ones; others could benefit from the two-array approach. If you had lots of operations on matricies A and B like Re(A)*Im(B) – what that would mean, I don’t know, but still – then I think that one would likely be significantly faster in the CArray approach, since you wouldn’t have to waste memory bandwidth by loading in data you wouldn’t need (eg, Im(A) and Re(B).)

    Ultimately, this is an empirical question; if you have an idea of what your mix of access patterns is, it’s easy enough to test out the two approaches. But for the patterns I can most easily envision, the first approach would win.

    The fact that Matlab disagrees with me, as per your link, surprises me enough to almost make me doubt my answer. I’m not a huge Matlab fan, but the Matlab people are smart and concerned about making numerical computation fast. But this is one of those decisions which, once made, is incredibly hard to undo – Matlab couldn’t change such a fundamental data layout now without breaking zillions of other things, of their own and third-party – and the decision was probably made decades ago when cache performance was less crucial and compatability with certain libraries probably mattered more. I note that packages like Lapack are based on the other format, array of structures (although only implicitly — in Fortran, complex has been a primitive data type since at least FORTRAN 66).

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

Sidebar

Related Questions

I've got an existing asp.net project written in vb.net. Another person has written a
I have a table Person which contains 2 fields.In my another database i have
I want to pull a specific commit from another person's branch into my own
I have some code given to me by another person in which we have
I have a table User and another Person , a person is an user
I have seen code like this (actually seeing another person type it up): catch
I have a solution that I work on with another person and the solution
This has to be a FAQ, but I can't find it googling. Another person
Suppose one person is using Bazaar 2.3 on Linux, and another is using Bazaar
i want to have my dnn portal send me and another person an email

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.