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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:01:08+00:00 2026-06-04T09:01:08+00:00

I have 2 2-D NSMutableArrays and I am trying to do some basic matrix

  • 0

I have 2 2-D NSMutableArrays and I am trying to do some basic matrix multiplication. I have my generic formula code below, but its performance is exceptionally slow (as expected). I have done lots of googling and have not found any easy nor easy to understand formulas to change up the code for performance enhancement. Can anyone point me in the right direction of a straightforward formula/tutorial/example of how to get better performance than 0(n^3) with matrix multiplication in Objective C.

+ (NSMutableArray*)multiply:(NSMutableArray*)a1 withArray:(NSMutableArray*)a2
{
    if([[a1 objectAtIndex: 0] count] != [a2 count])
    {
        NSLog(@"Multiplicaton error!");
        return NULL;
    }

    int a1_rowNum = [a1 count];
    int a2_rowNum = [a2 count];
    int a2_colNum = [[a2 objectAtIndex:0] count];
    NSMutableArray *result = [NSMutableArray arrayWithCapacity:a1_rowNum];
    for (int i = 0; i < a1_rowNum; i++) {
        NSMutableArray *tempRow = [NSMutableArray arrayWithCapacity:a2_colNum];
        for (int j = 0; j < a2_colNum; j++) {
            double tempTotal = 0;
            for (int k = 0; k < a2_rowNum; k++) {
                double temp1 = [[[a1 objectAtIndex:i] objectAtIndex:k] doubleValue];
                double temp2 = [[[a2 objectAtIndex:k] objectAtIndex:j] doubleValue];
                tempTotal += temp1 * temp2;
            }
             //Stored as a string because I upload it to an online database for storage.
            [tempRow addObject:[NSString stringWithFormat:@"%f",tempTotal]];
        }
        [result addObject:tempRow];
    }
    return result;
}
  • 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-04T09:01:09+00:00Added an answer on June 4, 2026 at 9:01 am

    It will be much faster if you Write it in C.


    double[] will be ridiculously fast compared to an NSArray of NSNumbers for this task. you’ll have good cache coherency, minimal instructions, no need to go through the runtime or allocate in order to write or read an element. no need to perform reference count cycling on each element…

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

Sidebar

Related Questions

I'm rewriting some code to improve tableview performance. I'm trying to implement the dequeueReusableCellWithIdentifier
I have an NSMutableArray that I'm trying to store and access some structs. How
I've been trudging through some code for two days trying to figure out why
I'm trying to select data from the database and I have the following code
I'm trying to create then retrieve an array of CLLocationCoordinate2D objects, but for some
I am trying to make my UITableView Editable but I'm having some trouble with
I have been trying for hours to figure this out. I have some JSON
I'm posting a lot of code, but the question is relatively simple: I'm trying
I am trying to do some basic table retrieval from sqlite and I keep
I am trying to learn how to code a UITableView and is having some

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.