Fmin_tnc written in C, but fmin_ncg written in Python?

Hello everyone,

I’m a new contributor trying to get involved and was curious with reasoning as to why certain functions are wrappings of C implementations and some are written purely in Python.

My understanding is that C is used for faster computing. Given this I’m unsure why some implementations are written in Python. Perhaps due to simply not being implemented yet or as it is easier to maintain

Would like some clarification on reasoning for this. I’m just trying to understand the current landscape.

Just a quirk of history: fmin_tnc wraps an existing C code whereas fmin_ncg was written from scratch in Python.

C is obviously faster than Python but if the users Python callable dominates then the trade off is not so straight forwards

Thanks for the response. That all makes sense.

I suppose my main question is why wouldn’t everything be wrapped in C code if it is obviously faster. If the Python callable dominates then wouldn’t the C code simply be as bad as the Python implementation. Or does passing a large python function into C cause delays that I am unaware of?

He meant that C is obviously faster for the parts that are C. It doesn’t make the system as a whole (including the calls to the Python function being minimized) practically faster when the Python function call overhead dominates. It doesn’t make the C+Python slower than Python+Python. It just doesn’t make it faster enough to pay for the reduced maintainability of C code.

And that’s the real answer why more parts of scipy aren’t written in C. We’re mostly Python programmers who want to program in Python wherever we can. We use C when we must and where it provides the benefits to do so.

Cheers for the clarification, makes sense to me now.