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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:31:31+00:00 2026-06-09T09:31:31+00:00

Okay, so I had working code written in all objective c (yes, I know

  • 0

Okay, so I had working code written in all objective c (yes, I know that objc is technically just C. But i mean I had it written with messages and stuff. I only have a java background and do not know much about plain old C) but it ran incredibly slow. So I wrote out (what i thought) was the same code, but now this set of loops produces different values (for only some of the numbers) and I cannot, for the life of me, figure out whats different. What I am doing is looping 10 times and doing 1 multiplication and 1 addition between matricies. I’m hoping someone with more background with the two languages can pick out the part of code that I transcribed incorrectly. I did not change anything beforehand for any of the arrays (those were hardcoded in and uneffected) so A1, A2, etc have the same values in both parts of code.

Current code in C:

    for (int m = 0; m < 10; m++) {

    //Do matrix multiplication between A1 and A2.  Store in temporary B1
    for( int i = 0; i < 13; i++ )
        for( int j = 0; j < 43; j++ ) {
            double tempTotal = 0;
            for( int k = 0; k < 43; k++){
                tempTotal = tempTotal + A1[i][k] * A2[k][j];
            }
            B1[i][j] = tempTotal;
        }

    //Assign B1 data back into A1 after the multiplication is finished
    for(int i = 0; i < 13; i++)
        for(int j = 0; j<43; j++)
            A1[i][j] = B1[i][j];

    //Add C1 and A1.  Store into C1.
    for (int l = 0; l < 13; l++) 
        for (int n = 0; n < 43; n++) 
            C1[l][n] = C1[l][n] + A1[l][n];

}//end m for loop

This was the old Obj c code:

 for (int m = 0; m < 10; m++) {
    //multiply A1 and A2.  Store into A1
    A1 = [LCA_Computation multiply:A1 withArray:A2];    //LCA_Computation is the name of the .m class file in which this all happens.  

    //Add C1 and A1.  Store into C1
    for (int i = 0; i < 13; i++) 
        for (int j = 0; j < 43; j++) 
            [[C1 objectAtIndex:i] replaceObjectAtIndex:j withObject:[NSNumber numberWithDouble: [[[C1 objectAtIndex: i] objectAtIndex: j] doubleValue] + [[[A1 objectAtIndex: i] objectAtIndex: j] doubleValue]]];

}//end m for loop

//multiply method
   + (NSMutableArray*)multiply:(NSMutableArray*)a1 withArray:(NSMutableArray*)a2
{
    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;
            }
            //the String format is intentional.  I convert them all to strings later.  I just put it in the method here where as it is done later in the C code
            [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-09T09:31:32+00:00Added an answer on June 9, 2026 at 9:31 am

    This issue had to do with prior memory management issues causing 0’s to be used in some calculations.

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

Sidebar

Related Questions

Okay, so I've had this code that used to work just fine. I recently
Okay, it appeared that I had an answer for this question, but I was
Okay, I know that I've not been the best at accept rate...and I will
okay, I understand the basics of jQuery, and I know that in some instances
Possible Duplicate: Randomize a List<T> in C# I thought I had my code working
After researching all day and night, I have something that is currently working. However,
Okay, so I'm working on an AppWidget that checks the battery level and displays
Okay so I had originally been attempting to use some headers that were supposedly
Okay so heres the situation. I have just had to move servers due to
Okay, I know how to do the rest but how to I create the

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.