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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:00:32+00:00 2026-05-24T05:00:32+00:00

I just have started using vecLib framework to make a program doing intensive matrix-vector

  • 0

I just have started using vecLib framework to make a program doing intensive matrix-vector multiplications on Mac OS X 10.7. I made a simple program like this; multiply the matrix a with the vector x and add the result on the vector y.

#include <vecLib/vectorOps.h>
#include <stdio.h>

float a[8][4] =     // the matrix to be multiplied
{
    {1.0f, 0.0f, 0.0f, 0.0f},
    {0.0f, 1.0f, 0.0f, 0.0f},
    {1.0f, 1.0f, 0.0f, 0.0f},
    {0.0f, 0.0f, 1.0f, 1.0f},
    {1.0f, 0.0f, 1.0f, 0.0f},
    {1.0f, 0.0f, 1.0f, 0.0f},
    {1.0f, 1.0f, 1.0f, 0.0f},
    {0.0f, 0.0f, 0.0f, 1.0f},
};

float x[4] = {1.0f, 2.0f, 4.0f, 8.0f};  // the vector to be multiplied
float y[8] = {0.f, 0.f, 0.f, 0.f,       // the result vector
              0.f, 0.f, 0.f, 0.f};


int main() {
    int i;
    vSgemv('n', 8, 4, 1.0f, (const vFloat *)a, (const vFloat *)x, 1.0f, (vFloat *)y);

    for (i = 0; i < 8; i++) {
        printf("%.4f\n", y[i]);
    }

    return 0;
}

I compiled and ran the program on the console

gcc -framework vecLib -o test test.c && ./test

But the result was like this; the operation did not happen and the result vector was still empty.

0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000

Am I missing some initialization to run the matrix and vector functions in the vecLib framework?

  • 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-24T05:00:34+00:00Added an answer on May 24, 2026 at 5:00 am

    First off, the actual bug is very simple, but you would have had no way to know; you’re passing 'n' for the first argument, but you actually need to pass 'N' (despite what’s written in the header). With that fix, your code works.

    Now, that said, you’re doing a couple more subtle things “wrong”(ish).

    First, please don’t use vecLib. It was replaced by the Accelerate.framework (in 10.4!). vecLib.framework has only been kept around for legacy support. Any new development should link against Accelerate instead.

    Second, please don’t use the v* functions defined in vectorOps.h. They too have been replaced, with the industry-standard BLAS functions defined in cblas.h. Since they’re standard, there is lots of public documentation on how to use them, and they’re backed by much faster implementations as well; the vectorOps functions are maintained only for legacy support. cblas.h also supports many more operations and data types. If that all wasn’t enough, if you decide to port your code to iOS, you will find that the vectorOps functions are not available at all. Use the cblas.h functions.

    Re-writing your example as suggested:

    #include <Accelerate/Accelerate.h>
    #include <stdio.h>
    
    float a[8][4] =     // the matrix to be multiplied
    {
        {1.0f, 0.0f, 0.0f, 0.0f},
        {0.0f, 1.0f, 0.0f, 0.0f},
        {1.0f, 1.0f, 0.0f, 0.0f},
        {0.0f, 0.0f, 1.0f, 1.0f},
        {1.0f, 0.0f, 1.0f, 0.0f},
        {1.0f, 0.0f, 1.0f, 0.0f},
        {1.0f, 1.0f, 1.0f, 0.0f},
        {0.0f, 0.0f, 0.0f, 1.0f},
    };
    
    float x[4] = {1.0f, 2.0f, 4.0f, 8.0f};  // the vector to be multiplied
    float y[8] = {0.f, 0.f, 0.f, 0.f,       // the result vector
        0.f, 0.f, 0.f, 0.f};
    
    
    int main() {
        int i;
        cblas_sgemv(CblasRowMajor, CblasNoTrans, 8, 4, 1.0f, (float*)a, 4, x, 1, 1.0f, y, 1);
    
        for (i = 0; i < 8; i++) {
            printf("%.4f\n", y[i]);
        }
    
        return 0;
    }
    

    and running it gives:

    scanon$ gcc test.c -framework Accelerate -o test
    scanon$ ./test
    1.0000
    2.0000
    3.0000
    12.0000
    5.0000
    5.0000
    7.0000
    8.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
I just started using SVN, and I have a cache directory that I don't
Just getting started using MVC in ASP.NET, I'm going to have it so users
I've just started using Java's enums in my own projects (I have to use
I’ve only just started using ASP.NET MVC, and I have a somewhat trivial question:
I have been looking at using TDD and implementing proper testing (only just started
I have just started using MVC 2 , I have got a couple of

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.