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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:19:43+00:00 2026-06-02T16:19:43+00:00

I have a library of C functions for scalars, e.g. double f(double x, double

  • 0

I have a library of C functions for scalars, e.g.

double f(double x, double y, double z) {
    result = x + 2*y - 3*z;
    return result;
}

I’d like to use these functions over numpy arrays, but would like to vectorise the operation somehow and avoid several C calls to f for each array element. Most examples that I have found are for functions that already support arrays (f(double *x) or f(double x[])).

What is the right approach here? Rewrite f to support arrays? (There are a lot of functions in the library.) Write a C wrapper, maybe using function pointers? Or do ctypes, cython, etc. offer a simpler alternative?

This has probably been asked hundreds of times, so even just a pointer to the appropriate documentation would be helpful.

  • 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-02T16:19:44+00:00Added an answer on June 2, 2026 at 4:19 pm

    Personally I’d say rewriting the functions to use arrays is the best and cleanest way to go. However, an alternative would be the already mentioned wrapper, but with using the original function as an inline function, e. g.

    // Function
    inline double f(double x, double y, double z) {
        return x + 2*y - 3*z;
    }
    
    // Wrapper
    void fWrapper(double *x, double *y, double *z, double *ret, int N) {
        int i;
    
        for (i = 0; i < N; i++) {
            ret[i] = f(x[i], y[i], z[i]);
        }
    }
    

    Now the compiler should replace the function call with the code of the function.

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

Sidebar

Related Questions

I have a library written in C that I would like to use in
I have a library of common functions that I use in several different projects,
HI all, I would like to call from my C# code, unamanaged library functions
Of course most languages have library functions for this, but suppose I want to
If for example I should not use standard library functions like printf() , putchar()
We have written a large library functions whose prototypes mostly look like: void my_fun(
I have to import library which is called functions.sage . How can I do
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
How can I call these library functions from anywhere in my Yii app? I
The standard C library functions strtof and strtod have the following signatures: float strtof(const

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.