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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:14:03+00:00 2026-06-07T21:14:03+00:00

In GSL a real n * m matrix M is represented internally as an

  • 0

In GSL a real n * m matrix M is represented internally as an array of size n*m. To access the (i,j) element of M, internally GSL has to access the (i-1) * n + j - 1 location of the array, which involves integer multiplications and additions.

In Numerical Recipes for C, they recommend the alternative method of declaring an array of n pointers, each pointing to an array of m numbers. Then to access the (i,j) element, one puts M[i-1][j-1]. They claim that this is more efficient because it avoids the integer multiplication. The downside is that one has to initialize each pointer separately.

I am wondering, what are the advantages/disadvantages of each approach?

  • 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-07T21:14:07+00:00Added an answer on June 7, 2026 at 9:14 pm

    In C:

    #define n 2
    #define m 3
    
    int M[n*m];
    

    is the same as

    int M[n][m];
    

    in C matrices are said to be stored in row-major order

    http://en.wikipedia.org/wiki/Row-major_order

    In C,

    M[1][2]
    

    is the same as

    *(M + 1*m + 2) // if M is define as M[n][m]
    

    You could define M as an array of n pointers, but you still have to put the data somewhere and the best place is probably a 2D array. I would suggest:

    int M[n][m];
    
    int* Mrows[n] = {M[0], M[1]};
    

    You can then do a direct offset into rows to get to the row you want. Then:

    Mrows[1][2]
    

    is the same as

    *((*(Mrows + 1)) + 2)
    

    Its more work for the programmer and probably only worth it if you want to go really fast. In that case you may want to look into more optimizations such as specific machine instructions. Also, depending on your algorithm, you may be able to just use + operations (like if you are iterating over the matrix)

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

Sidebar

Related Questions

Kindly tell me the function of matrix multiplication in GSL library. I have searched
I have a code deeply embedded with GNU Scientific Library (GSL) matrix arithmetic, the
I need to statically link my application which uses libraries like csparse, gsl, pthread,
I have a module ( Alien::GSL ) which I am working on. Currently it
Is there a means to do element-wise vector-vector multiplication with BLAS, GSL or any
I have a array X that has M*N elements, I'm trying to create a
Based on the documents http://www.gnu.org/software/gsl/manual/html_node/Householder-Transformations.html and http://en.wikipedia.org/wiki/Householder_transformation I figured the following code would successfully
Is there a way in C++ to effectively create a closure which will be
I am trying to use the GNU Scientific Library (GSL) http://www.gnu.org/software/gsl/ in QtCreator. How
I am reading the standard (Numerical Recipes and GSL C versions are identical) implementation

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.