It is very straight forward to use this code in Julia, if you know how to 
compile a shared library.

Unfortunately it is not straightforward to create a shared library, if you 
do not know C/gcc/os basics, and if the C code is deliberately written in a 
way that is not compatible with a shared library approach, you will have to 
modify the source.

If I have not missed anything tricky, the implementation seems trivial to 
translate to Julia, so I would spend my time on that, instead of trying to 
create and distribute a shared library for this kind of simple function. 
After all, dependency management in C is tricky and Julia has not done 
anything to make it simpler. Maybe julia could include a C compiler for 
inline C code, but I'm not sure anyone with the knowhow have that high on 
their todo list.

kl. 21:41:09 UTC+1 onsdag 19. februar 2014 skrev Bob Quazar følgende:
>
> Hi Ivar, 
>
> Thanks for the reply. I'm interested in that particular header file 
> because it contains a fast implementation of the "digamma" function. Julia 
> has a built-in digamma function, but I suspect it's orders of magnitude 
> slower than the one implemented in this header file---Julia's digamma is 
> probably much more accurate than I need. (My program's run time is 
> currently dominate by the calls to the digamma function, and there's no 
> easy way to call digamma less often, such as through caching, etc. I'm 
> implementing an optimization procedure for learning parameters a Bayesian 
> model, using stochastic variational inference.)
>
> Indeed, I'm already using a version of Julia that I've compiled. I'm not 
> sure yet whether I'll ultimately distribute my code---it would be nice to 
> have the option to do so though. It sounds like it might be easier for me 
> to port the fast digamma function from C to Julia, though I'm a bit 
> disappointed it isn't more straightforward to call this C code from Julia. 
> If there's another way, I'd love to hear it!
>
> Bob
>
>
>
> On Wednesday, February 19, 2014 11:49:50 AM UTC-8, Ivar Nesje wrote:
>>
>> I do not think you can use that C code (as is) from Julia. All the 
>> functions are declared "static inline", and thus they need to be compiled 
>> together with the code that calls them.
>>
>> I do not have a deep knowledge of C, linking, and shared libraries, but I 
>> will attempt to give an outline on what steps you will need to google for.
>>
>>    1. Make the functions externally callable. This means that you will 
>>    at least remove `static`, but likely you want to remove `inline also`. 
>> Just 
>>    search for `static inline ` and replace by empty string
>>    2. Compile the c code and link it into the julia process. If you are 
>>    on windows you might need to specially mark the symbols as exported. If 
>> you 
>>    compile julia yourself, and do not plan to distribute the code, you might 
>>    have success with just #include <fastonebigheader.h>, but ideally you 
>>    should compile it as a shared library.
>>    3. Use the functions with `ccall` as normal. If you include the 
>>    header in a julia, you will not need to specify a library.
>>
>> You ask a fairly open question that could actually be the basis of a 
>> book. It would be easier to answer more specifically if you included a 
>> paragraph about your project and why you want to use this code. If it is 
>> not just curiosity about whether it is possible, you might instead get a 
>> better suggestion for how to solve your problem.
>>
>> Ivar
>>
>> kl. 19:22:56 UTC+1 onsdag 19. februar 2014 skrev Bob Quazar følgende:
>>>
>>> I'm trying to call C code from Julia. The C code is just a big header 
>>> file: 
>>> http://fastapprox.googlecode.com/svn/trunk/fastapprox/src/fastonebigheader.h
>>> (There's no  corresponding .c file.) I've installed this header file in 
>>> my "/usr/include/" directory, but according to the Julia web site, Julia 
>>> only accesses C shared objects. I'm not sure what to do---wish I understood 
>>> C/gcc better. I'd greatly appreciate any help.
>>>
>>> Thanks, Bob
>>>
>>

Reply via email to