Re: [julia-users] Embedding Julia in C++ - Determining returned array types
e.g. http://half.sourceforge.net/ But if you aren't sure you need to support this, then just throw an error (Float16 is relatively new and AFAICT only useful in specialized applications because of the precision limit, which is why support is rare) If you are sure you (a) need it but (b) only need to up- and down-convert, see the routines in `base/float.jl`. They should be straightforward to port to C++. On Wed, Oct 19, 2016 at 1:00 PM, Yichao Yuwrote: > > > On Wed, Oct 19, 2016 at 12:54 PM, Kyle Kotowick wrote: > >> Aha, that fixed it! >> >> I'm running into one issue though. What do I do with the data when it's a >> "Float16" type? C++ has no way to represent a 16-bit float, so I'm having >> difficulty converting it to a regular 32-bit float. >> > > Find a compiler / library that supports it? ;-p > > I'm only half joking. You can always just keep a pointer to the value or > store it in a int16_t as long as you don't need to do any operation on it. > If you want to operate on them in C++ natively you would have to find a > C/C++ compiler/library (or write the necessary operations yourself) that > supports __fp16. > > >> >> jl_value_t *ret = jl_eval_string(code_string); >> jl_array_t *ret_array = (jl_array_t*)ret; >> >> if (jl_array_eltype(ret) == jl_float16_type) { >> >> /* now I need to convert the 'ret_array' to a C++ array of floats, but >> how do I do that when they're given in Float16? */ >> >> } >> >> >> On Tuesday, 18 October 2016 20:57:10 UTC-4, Isaiah wrote: >>> >>> The issue here is that `jl_array_eltype` is already returning a type. >>> >>> `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: >>> >>> jl_typeof(array_type) == jl_int64_type >>> >>> But >>> >>> jl_typeof(array_type) -> DataType >>> >>> Instead, either do the equality check directly: >>> >>> array_type == jl_int64_type >>> >>> Or use the exported API only (jlapi.c): >>> >>> strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) >>> >>> On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowick >>> wrote: >>> I apologize for the formatting, that should be: jl_value_t *ret = jl_eval_string(code_string); void* array_type = jl_array_eltype(ret); jl_array_t *ret_array = (jl_array_t*)ret; if (jl_typeis(array_type, jl_int64_type)) { long *data = (long*) jl_array_data(ret_array); } else if (jl_typeis(array_type, jl_float64_type)) { double *data = (double*) jl_array_data(ret_array); } And the issue is that even if it is an Int64 or Float64, neither of those IF statements will return true. On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: > > Awesome, thanks. Could you show how to use it in a minimal code > example? Here's what I'm currently trying, but it does not appear to be > working: > > jl_value_t *ret = jl_eval_string(code_string); > void* array_type = jl_array_eltype(ret); > jl_array_t *ret_array = (jl_array_t*)ret; > > > > if (jl_typeis(array_type, jl_int64_type)) { > long *data = (long*) jl_array_data(ret_array); > } > else if (jl_typeis(array_type, jl_float64_type)) { double *data = ( > double*) jl_array_data(ret_array); > } > > > On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: >> >> On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick >> wrote: >>> >>> >>> After determining that an array was returned, how would you >>> determine what the inner type of the array is (i.e. the type of the >>> objects >>> it contains)? >>> >> >> `jl_array_eltype` >> >> >>> >>> And furthermore, if it returns an array of type "Any", would there >>> be any way to tell what the type is of any arbitrary element in that >>> array? >>> >> >> `jl_typeof`, after retrieving the element (which will be boxed) >> >> >>> >>> Thanks! >>> >> >> >>> >
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
You can pull the significant bits and the exponent values out of a Float16 and then use those to compute the value as a Float32: https://en.wikipedia.org/wiki/Half-precision_floating-point_format On Wed, Oct 19, 2016 at 1:00 PM, Yichao Yuwrote: > > > On Wed, Oct 19, 2016 at 12:54 PM, Kyle Kotowick wrote: > >> Aha, that fixed it! >> >> I'm running into one issue though. What do I do with the data when it's a >> "Float16" type? C++ has no way to represent a 16-bit float, so I'm having >> difficulty converting it to a regular 32-bit float. >> > > Find a compiler / library that supports it? ;-p > > I'm only half joking. You can always just keep a pointer to the value or > store it in a int16_t as long as you don't need to do any operation on it. > If you want to operate on them in C++ natively you would have to find a > C/C++ compiler/library (or write the necessary operations yourself) that > supports __fp16. > > >> >> jl_value_t *ret = jl_eval_string(code_string); >> jl_array_t *ret_array = (jl_array_t*)ret; >> >> if (jl_array_eltype(ret) == jl_float16_type) { >> >> /* now I need to convert the 'ret_array' to a C++ array of floats, but >> how do I do that when they're given in Float16? */ >> >> } >> >> >> On Tuesday, 18 October 2016 20:57:10 UTC-4, Isaiah wrote: >>> >>> The issue here is that `jl_array_eltype` is already returning a type. >>> >>> `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: >>> >>> jl_typeof(array_type) == jl_int64_type >>> >>> But >>> >>> jl_typeof(array_type) -> DataType >>> >>> Instead, either do the equality check directly: >>> >>> array_type == jl_int64_type >>> >>> Or use the exported API only (jlapi.c): >>> >>> strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) >>> >>> On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowick >>> wrote: >>> I apologize for the formatting, that should be: jl_value_t *ret = jl_eval_string(code_string); void* array_type = jl_array_eltype(ret); jl_array_t *ret_array = (jl_array_t*)ret; if (jl_typeis(array_type, jl_int64_type)) { long *data = (long*) jl_array_data(ret_array); } else if (jl_typeis(array_type, jl_float64_type)) { double *data = (double*) jl_array_data(ret_array); } And the issue is that even if it is an Int64 or Float64, neither of those IF statements will return true. On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: > > Awesome, thanks. Could you show how to use it in a minimal code > example? Here's what I'm currently trying, but it does not appear to be > working: > > jl_value_t *ret = jl_eval_string(code_string); > void* array_type = jl_array_eltype(ret); > jl_array_t *ret_array = (jl_array_t*)ret; > > > > if (jl_typeis(array_type, jl_int64_type)) { > long *data = (long*) jl_array_data(ret_array); > } > else if (jl_typeis(array_type, jl_float64_type)) { double *data = ( > double*) jl_array_data(ret_array); > } > > > On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: >> >> On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick >> wrote: >>> >>> >>> After determining that an array was returned, how would you >>> determine what the inner type of the array is (i.e. the type of the >>> objects >>> it contains)? >>> >> >> `jl_array_eltype` >> >> >>> >>> And furthermore, if it returns an array of type "Any", would there >>> be any way to tell what the type is of any arbitrary element in that >>> array? >>> >> >> `jl_typeof`, after retrieving the element (which will be boxed) >> >> >>> >>> Thanks! >>> >> >> >>> >
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
On Wed, Oct 19, 2016 at 12:54 PM, Kyle Kotowickwrote: > Aha, that fixed it! > > I'm running into one issue though. What do I do with the data when it's a > "Float16" type? C++ has no way to represent a 16-bit float, so I'm having > difficulty converting it to a regular 32-bit float. > Find a compiler / library that supports it? ;-p I'm only half joking. You can always just keep a pointer to the value or store it in a int16_t as long as you don't need to do any operation on it. If you want to operate on them in C++ natively you would have to find a C/C++ compiler/library (or write the necessary operations yourself) that supports __fp16. > > jl_value_t *ret = jl_eval_string(code_string); > jl_array_t *ret_array = (jl_array_t*)ret; > > if (jl_array_eltype(ret) == jl_float16_type) { > > /* now I need to convert the 'ret_array' to a C++ array of floats, but > how do I do that when they're given in Float16? */ > > } > > > On Tuesday, 18 October 2016 20:57:10 UTC-4, Isaiah wrote: >> >> The issue here is that `jl_array_eltype` is already returning a type. >> >> `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: >> >> jl_typeof(array_type) == jl_int64_type >> >> But >> >> jl_typeof(array_type) -> DataType >> >> Instead, either do the equality check directly: >> >> array_type == jl_int64_type >> >> Or use the exported API only (jlapi.c): >> >> strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) >> >> On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowick wrote: >> >>> I apologize for the formatting, that should be: >>> >>> jl_value_t *ret = jl_eval_string(code_string); >>> void* array_type = jl_array_eltype(ret); >>> jl_array_t *ret_array = (jl_array_t*)ret; >>> >>> if (jl_typeis(array_type, jl_int64_type)) { >>> long *data = (long*) jl_array_data(ret_array); >>> } >>> else if (jl_typeis(array_type, jl_float64_type)) { >>> double *data = (double*) jl_array_data(ret_array); >>> } >>> >>> >>> And the issue is that even if it is an Int64 or Float64, neither of >>> those IF statements will return true. >>> >>> >>> >>> On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: Awesome, thanks. Could you show how to use it in a minimal code example? Here's what I'm currently trying, but it does not appear to be working: jl_value_t *ret = jl_eval_string(code_string); void* array_type = jl_array_eltype(ret); jl_array_t *ret_array = (jl_array_t*)ret; if (jl_typeis(array_type, jl_int64_type)) { long *data = (long*) jl_array_data(ret_array); } else if (jl_typeis(array_type, jl_float64_type)) { double *data = ( double*) jl_array_data(ret_array); } On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: > > On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick > wrote: >> >> >> After determining that an array was returned, how would you determine >> what the inner type of the array is (i.e. the type of the objects it >> contains)? >> > > `jl_array_eltype` > > >> >> And furthermore, if it returns an array of type "Any", would there be >> any way to tell what the type is of any arbitrary element in that array? >> > > `jl_typeof`, after retrieving the element (which will be boxed) > > >> >> Thanks! >> > > >>
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
Aha, that fixed it! I'm running into one issue though. What do I do with the data when it's a "Float16" type? C++ has no way to represent a 16-bit float, so I'm having difficulty converting it to a regular 32-bit float. jl_value_t *ret = jl_eval_string(code_string); jl_array_t *ret_array = (jl_array_t*)ret; if (jl_array_eltype(ret) == jl_float16_type) { /* now I need to convert the 'ret_array' to a C++ array of floats, but how do I do that when they're given in Float16? */ } On Tuesday, 18 October 2016 20:57:10 UTC-4, Isaiah wrote: > > The issue here is that `jl_array_eltype` is already returning a type. > > `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: > > jl_typeof(array_type) == jl_int64_type > > But > > jl_typeof(array_type) -> DataType > > Instead, either do the equality check directly: > > array_type == jl_int64_type > > Or use the exported API only (jlapi.c): > > strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) > > On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowick> wrote: > >> I apologize for the formatting, that should be: >> >> jl_value_t *ret = jl_eval_string(code_string); >> void* array_type = jl_array_eltype(ret); >> jl_array_t *ret_array = (jl_array_t*)ret; >> >> if (jl_typeis(array_type, jl_int64_type)) { >> long *data = (long*) jl_array_data(ret_array); >> } >> else if (jl_typeis(array_type, jl_float64_type)) { >> double *data = (double*) jl_array_data(ret_array); >> } >> >> >> And the issue is that even if it is an Int64 or Float64, neither of those >> IF statements will return true. >> >> >> >> On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: >>> >>> Awesome, thanks. Could you show how to use it in a minimal code example? >>> Here's what I'm currently trying, but it does not appear to be working: >>> >>> jl_value_t *ret = jl_eval_string(code_string); >>> void* array_type = jl_array_eltype(ret); >>> jl_array_t *ret_array = (jl_array_t*)ret; >>> >>> >>> >>> if (jl_typeis(array_type, jl_int64_type)) { >>> long *data = (long*) jl_array_data(ret_array); >>> } >>> else if (jl_typeis(array_type, jl_float64_type)) { double *data = ( >>> double*) jl_array_data(ret_array); >>> } >>> >>> >>> On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick wrote: > > > After determining that an array was returned, how would you determine > what the inner type of the array is (i.e. the type of the objects it > contains)? > `jl_array_eltype` > > And furthermore, if it returns an array of type "Any", would there be > any way to tell what the type is of any arbitrary element in that array? > `jl_typeof`, after retrieving the element (which will be boxed) > > Thanks! > >
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
On Tue, Oct 18, 2016 at 8:57 PM, Isaiah Nortonwrote: > The issue here is that `jl_array_eltype` is already returning a type. > > `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: > > jl_typeof(array_type) == jl_int64_type > > But > > jl_typeof(array_type) -> DataType > > Instead, either do the equality check directly: > > array_type == jl_int64_type > > Or use the exported API only (jlapi.c): > > strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) > Just to be clear, this does not guarantee that the two types are equal. Directly comparing the pointer for types is also "exported API". > > On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowick wrote: > >> I apologize for the formatting, that should be: >> >> jl_value_t *ret = jl_eval_string(code_string); >> void* array_type = jl_array_eltype(ret); >> jl_array_t *ret_array = (jl_array_t*)ret; >> >> if (jl_typeis(array_type, jl_int64_type)) { >> long *data = (long*) jl_array_data(ret_array); >> } >> else if (jl_typeis(array_type, jl_float64_type)) { >> double *data = (double*) jl_array_data(ret_array); >> } >> >> >> And the issue is that even if it is an Int64 or Float64, neither of those >> IF statements will return true. >> >> >> >> On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: >>> >>> Awesome, thanks. Could you show how to use it in a minimal code example? >>> Here's what I'm currently trying, but it does not appear to be working: >>> >>> jl_value_t *ret = jl_eval_string(code_string); >>> void* array_type = jl_array_eltype(ret); >>> jl_array_t *ret_array = (jl_array_t*)ret; >>> >>> >>> >>> if (jl_typeis(array_type, jl_int64_type)) { >>> long *data = (long*) jl_array_data(ret_array); >>> } >>> else if (jl_typeis(array_type, jl_float64_type)) { double *data = ( >>> double*) jl_array_data(ret_array); >>> } >>> >>> >>> On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick wrote: > > > After determining that an array was returned, how would you determine > what the inner type of the array is (i.e. the type of the objects it > contains)? > `jl_array_eltype` > > And furthermore, if it returns an array of type "Any", would there be > any way to tell what the type is of any arbitrary element in that array? > `jl_typeof`, after retrieving the element (which will be boxed) > > Thanks! > >
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
The issue here is that `jl_array_eltype` is already returning a type. `jl_typeis(v, t)` becomes `jl_typeof(v) == t`, so your checks become: jl_typeof(array_type) == jl_int64_type But jl_typeof(array_type) -> DataType Instead, either do the equality check directly: array_type == jl_int64_type Or use the exported API only (jlapi.c): strcmp(jl_typename_str(array_type), jl_typename_str(jl_int64_type)) On Tue, Oct 18, 2016 at 7:52 PM, Kyle Kotowickwrote: > I apologize for the formatting, that should be: > > jl_value_t *ret = jl_eval_string(code_string); > void* array_type = jl_array_eltype(ret); > jl_array_t *ret_array = (jl_array_t*)ret; > > if (jl_typeis(array_type, jl_int64_type)) { > long *data = (long*) jl_array_data(ret_array); > } > else if (jl_typeis(array_type, jl_float64_type)) { > double *data = (double*) jl_array_data(ret_array); > } > > > And the issue is that even if it is an Int64 or Float64, neither of those > IF statements will return true. > > > > On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: >> >> Awesome, thanks. Could you show how to use it in a minimal code example? >> Here's what I'm currently trying, but it does not appear to be working: >> >> jl_value_t *ret = jl_eval_string(code_string); >> void* array_type = jl_array_eltype(ret); >> jl_array_t *ret_array = (jl_array_t*)ret; >> >> >> >> if (jl_typeis(array_type, jl_int64_type)) { >> long *data = (long*) jl_array_data(ret_array); >> } >> else if (jl_typeis(array_type, jl_float64_type)) { double *data = (double >> *) jl_array_data(ret_array); >> } >> >> >> On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: >>> >>> On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick >>> wrote: After determining that an array was returned, how would you determine what the inner type of the array is (i.e. the type of the objects it contains)? >>> >>> `jl_array_eltype` >>> >>> And furthermore, if it returns an array of type "Any", would there be any way to tell what the type is of any arbitrary element in that array? >>> >>> `jl_typeof`, after retrieving the element (which will be boxed) >>> >>> Thanks! >>> >>>
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
I apologize for the formatting, that should be: jl_value_t *ret = jl_eval_string(code_string); void* array_type = jl_array_eltype(ret); jl_array_t *ret_array = (jl_array_t*)ret; if (jl_typeis(array_type, jl_int64_type)) { long *data = (long*) jl_array_data(ret_array); } else if (jl_typeis(array_type, jl_float64_type)) { double *data = (double*) jl_array_data(ret_array); } And the issue is that even if it is an Int64 or Float64, neither of those IF statements will return true. On Sunday, 16 October 2016 21:36:03 UTC-4, Kyle Kotowick wrote: > > Awesome, thanks. Could you show how to use it in a minimal code example? > Here's what I'm currently trying, but it does not appear to be working: > > jl_value_t *ret = jl_eval_string(code_string); > void* array_type = jl_array_eltype(ret); > jl_array_t *ret_array = (jl_array_t*)ret; > > > > if (jl_typeis(array_type, jl_int64_type)) { > long *data = (long*) jl_array_data(ret_array); > } > else if (jl_typeis(array_type, jl_float64_type)) { double *data = (double > *) jl_array_data(ret_array); > } > > > On Friday, 14 October 2016 20:45:18 UTC-4, Isaiah wrote: >> >> On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowickwrote: >>> >>> >>> After determining that an array was returned, how would you determine >>> what the inner type of the array is (i.e. the type of the objects it >>> contains)? >>> >> >> `jl_array_eltype` >> >> >>> >>> And furthermore, if it returns an array of type "Any", would there be >>> any way to tell what the type is of any arbitrary element in that array? >>> >> >> `jl_typeof`, after retrieving the element (which will be boxed) >> >> >>> >>> Thanks! >>> >> >>
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
In addition to this, CxxWrap.jl has some additional convenience classes to work with Julia arrays from C++, see https://github.com/JuliaInterop/CxxWrap.jl#working-with-arrays Cheers, Bart On Sat, Oct 15, 2016 at 2:45 AM Isaiah Nortonwrote: > On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowick wrote: > > > After determining that an array was returned, how would you determine what > the inner type of the array is (i.e. the type of the objects it contains)? > > > `jl_array_eltype` > > > > And furthermore, if it returns an array of type "Any", would there be any > way to tell what the type is of any arbitrary element in that array? > > > `jl_typeof`, after retrieving the element (which will be boxed) > > > > Thanks! > > >
Re: [julia-users] Embedding Julia in C++ - Determining returned array types
On Fri, Oct 14, 2016 at 2:28 PM, Kyle Kotowickwrote: > > > After determining that an array was returned, how would you determine what > the inner type of the array is (i.e. the type of the objects it contains)? > `jl_array_eltype` > > And furthermore, if it returns an array of type "Any", would there be any > way to tell what the type is of any arbitrary element in that array? > `jl_typeof`, after retrieving the element (which will be boxed) > > Thanks! >
Re: [julia-users] Embedding Julia with C++
Sorry didn't get your question. In general the problem is that Eclipse doesn't seem to be able to recognize/include this sys.ji file, and I don't know how to fix it. On Wednesday, June 24, 2015 at 6:52:52 PM UTC+2, Tony Kelman wrote: Are you running on latest master? This is probably another casualty of https://github.com/JuliaLang/julia/pull/11640 On Wednesday, June 24, 2015 at 10:39:40 AM UTC-4, Kostas Tavlaridis-Gyparakis wrote: Νο, unfortunately it's not that. I just gave to the project the name juli I forgot to type the a and didn't bother correct it aftewrards, so the path name is correct. On Wednesday, June 24, 2015 at 4:31:20 PM UTC+2, Kevin Squire wrote: It's not just that julia is misspelled as juli in the path, is it? On Wednesday, June 24, 2015, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: Didn't manage to make the code run. I am really wondering what I am missing here... On Wednesday, June 24, 2015 at 3:59:47 PM UTC+2, Isaiah wrote: I guess this is still a distro path issue. The following suggestion is not very general, but to at least get going, you could try: jl_init(/home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/ julia/) On Wed, Jun 24, 2015 at 9:38 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I am simply trying to run the first example attached in the embedding documantation which is the following block of code: #include iostream #include julia.h using namespace std; int main() { /* required: setup the julia context */ jl_init(NULL); /* run julia commands */ jl_eval_string(print(sqrt(2.0))); /* strongly recommended: notify julia that the program is about to terminate. this allows julia time to cleanup pending write requests and run all finalizers */ jl_atexit_hook(); return 0; } And when I try to run the program in eclipse (after having linked the library and defined the path of the header file) the above mentioned error message appeas which says: - System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found On Wednesday, June 24, 2015 at 3:31:50 PM UTC+2, Isaiah wrote: You probably need to call `jl_init(NULL)` at the beginning of the program. If you have not done so yet, I would suggest to read the embedding documentation: http://docs.julialang.org/en/release-0.3/manual/embedding/ and start with the embedding example in the source: https://github.com/JuliaLang/julia/blob/master/examples/embedding.c On Wed, Jun 24, 2015 at 9:05 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I did download the 0.4 nightbuilt which includes the above mentioned files in the proper location, but now Eclipse is throwing me a different error I can not sort out how to overcome. When I try to run a small cpp file with a few julia comands Eclipse is compiling the file but when I try to run it it throws me the following message: System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found Futhermore since I am really new to Julia I am not sure and I don't know a lot of the existing tools, is it possible to write a function in julia that takes as an argument some data creates a model and solves it and call this function from inside my c++ project? I am asking this as in the example in the link http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#passing-julia-callback-functions-to-c attached by Isaiah with the qsort, the whole process is done inside julia framework. Whereas in my case I would be interested to write a julia program, like the one described above that I would be able to call as a function (I want it to solve a subproblem actually) inside my c++ project in eclipse. Is this relatively easy to be done? Because I think this would be the best approach for my case. On Tuesday, June 23, 2015 at 8:20:56 AM UTC+2, Jeff Waller wrote: Embedded Julia is of particular interest to me. To answer your question, everything in Julia is available via embedded Julia. I would very much discourage use of version 0.3.2; avoid it if you can. I think that particular version has the uv.h problem which is fixed in later versions. Can you gain root on this host? If so you can get 0.3.9 via PPA. Or even better if you can get ahold of one of the nightly builds, then 0.4.x comes with julia_config.jl, which figures out all of the right compile flags automatically. You just have to cut and paste in a Makefile. But if no makefile, you can run it and know the necessary compile time flags.
Re: [julia-users] Embedding Julia with C++
Νο, unfortunately it's not that. I just gave to the project the name juli I forgot to type the a and didn't bother correct it aftewrards, so the path name is correct. On Wednesday, June 24, 2015 at 4:31:20 PM UTC+2, Kevin Squire wrote: It's not just that julia is misspelled as juli in the path, is it? On Wednesday, June 24, 2015, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com javascript: wrote: Didn't manage to make the code run. I am really wondering what I am missing here... On Wednesday, June 24, 2015 at 3:59:47 PM UTC+2, Isaiah wrote: I guess this is still a distro path issue. The following suggestion is not very general, but to at least get going, you could try: jl_init(/home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/ julia/) On Wed, Jun 24, 2015 at 9:38 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I am simply trying to run the first example attached in the embedding documantation which is the following block of code: #include iostream #include julia.h using namespace std; int main() { /* required: setup the julia context */ jl_init(NULL); /* run julia commands */ jl_eval_string(print(sqrt(2.0))); /* strongly recommended: notify julia that the program is about to terminate. this allows julia time to cleanup pending write requests and run all finalizers */ jl_atexit_hook(); return 0; } And when I try to run the program in eclipse (after having linked the library and defined the path of the header file) the above mentioned error message appeas which says: - System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found On Wednesday, June 24, 2015 at 3:31:50 PM UTC+2, Isaiah wrote: You probably need to call `jl_init(NULL)` at the beginning of the program. If you have not done so yet, I would suggest to read the embedding documentation: http://docs.julialang.org/en/release-0.3/manual/embedding/ and start with the embedding example in the source: https://github.com/JuliaLang/julia/blob/master/examples/embedding.c On Wed, Jun 24, 2015 at 9:05 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I did download the 0.4 nightbuilt which includes the above mentioned files in the proper location, but now Eclipse is throwing me a different error I can not sort out how to overcome. When I try to run a small cpp file with a few julia comands Eclipse is compiling the file but when I try to run it it throws me the following message: System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found Futhermore since I am really new to Julia I am not sure and I don't know a lot of the existing tools, is it possible to write a function in julia that takes as an argument some data creates a model and solves it and call this function from inside my c++ project? I am asking this as in the example in the link http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#passing-julia-callback-functions-to-c attached by Isaiah with the qsort, the whole process is done inside julia framework. Whereas in my case I would be interested to write a julia program, like the one described above that I would be able to call as a function (I want it to solve a subproblem actually) inside my c++ project in eclipse. Is this relatively easy to be done? Because I think this would be the best approach for my case. On Tuesday, June 23, 2015 at 8:20:56 AM UTC+2, Jeff Waller wrote: Embedded Julia is of particular interest to me. To answer your question, everything in Julia is available via embedded Julia. I would very much discourage use of version 0.3.2; avoid it if you can. I think that particular version has the uv.h problem which is fixed in later versions. Can you gain root on this host? If so you can get 0.3.9 via PPA. Or even better if you can get ahold of one of the nightly builds, then 0.4.x comes with julia_config.jl, which figures out all of the right compile flags automatically. You just have to cut and paste in a Makefile. But if no makefile, you can run it and know the necessary compile time flags.
Re: [julia-users] Embedding Julia with C++
Are you running on latest master? This is probably another casualty of https://github.com/JuliaLang/julia/pull/11640 On Wednesday, June 24, 2015 at 10:39:40 AM UTC-4, Kostas Tavlaridis-Gyparakis wrote: Νο, unfortunately it's not that. I just gave to the project the name juli I forgot to type the a and didn't bother correct it aftewrards, so the path name is correct. On Wednesday, June 24, 2015 at 4:31:20 PM UTC+2, Kevin Squire wrote: It's not just that julia is misspelled as juli in the path, is it? On Wednesday, June 24, 2015, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: Didn't manage to make the code run. I am really wondering what I am missing here... On Wednesday, June 24, 2015 at 3:59:47 PM UTC+2, Isaiah wrote: I guess this is still a distro path issue. The following suggestion is not very general, but to at least get going, you could try: jl_init(/home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/ julia/) On Wed, Jun 24, 2015 at 9:38 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I am simply trying to run the first example attached in the embedding documantation which is the following block of code: #include iostream #include julia.h using namespace std; int main() { /* required: setup the julia context */ jl_init(NULL); /* run julia commands */ jl_eval_string(print(sqrt(2.0))); /* strongly recommended: notify julia that the program is about to terminate. this allows julia time to cleanup pending write requests and run all finalizers */ jl_atexit_hook(); return 0; } And when I try to run the program in eclipse (after having linked the library and defined the path of the header file) the above mentioned error message appeas which says: - System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found On Wednesday, June 24, 2015 at 3:31:50 PM UTC+2, Isaiah wrote: You probably need to call `jl_init(NULL)` at the beginning of the program. If you have not done so yet, I would suggest to read the embedding documentation: http://docs.julialang.org/en/release-0.3/manual/embedding/ and start with the embedding example in the source: https://github.com/JuliaLang/julia/blob/master/examples/embedding.c On Wed, Jun 24, 2015 at 9:05 AM, Kostas Tavlaridis-Gyparakis kostas.t...@gmail.com wrote: I did download the 0.4 nightbuilt which includes the above mentioned files in the proper location, but now Eclipse is throwing me a different error I can not sort out how to overcome. When I try to run a small cpp file with a few julia comands Eclipse is compiling the file but when I try to run it it throws me the following message: System image file /home/kostas/workspace/juli/Debug/../lib/x86_64-linux-gnu/julia/sys.ji not found Futhermore since I am really new to Julia I am not sure and I don't know a lot of the existing tools, is it possible to write a function in julia that takes as an argument some data creates a model and solves it and call this function from inside my c++ project? I am asking this as in the example in the link http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#passing-julia-callback-functions-to-c attached by Isaiah with the qsort, the whole process is done inside julia framework. Whereas in my case I would be interested to write a julia program, like the one described above that I would be able to call as a function (I want it to solve a subproblem actually) inside my c++ project in eclipse. Is this relatively easy to be done? Because I think this would be the best approach for my case. On Tuesday, June 23, 2015 at 8:20:56 AM UTC+2, Jeff Waller wrote: Embedded Julia is of particular interest to me. To answer your question, everything in Julia is available via embedded Julia. I would very much discourage use of version 0.3.2; avoid it if you can. I think that particular version has the uv.h problem which is fixed in later versions. Can you gain root on this host? If so you can get 0.3.9 via PPA. Or even better if you can get ahold of one of the nightly builds, then 0.4.x comes with julia_config.jl, which figures out all of the right compile flags automatically. You just have to cut and paste in a Makefile. But if no makefile, you can run it and know the necessary compile time flags.
Re: [julia-users] Embedding Julia with C++
The distro install file locations are going to be different, as you have found (which we should probably note in the docs -- feel free to open an issue or ideally a pull-request). i receive an error saying that there is no uv.h file in my system which is needed in one of the julia header files. Julia uses a fork of libuv, so I'm not sure how to get a proper uv.h for a linux distro build (not at a linux computer right now). Maybe Milan or Tony will have an answer. (see also: https://github.com/JuliaLang/julia/pull/8880 ) Also, one more thing I wanted to ask is the following, in general writing Julia code inside a C++ code is limited? What I want to do in general is write a JuMP model inside C++, so in general is this possible, in the sense that by embedding Julia inside C++, will I be able to use all of the tools and code of Julia language or is this only limited to a cer- tain amount of commands and packages? Technically, you should be able to do anything through the embedding API that you can do in the interactive shell (i.e.: you can call `jl_eval` with any legal Julia string). Practically, writing more than a few lines of Julia code via the embedding API sounds kind of painful (to me). The alternative is to write as much code as possible in pure Julia, and then expose a very small API to set up the problem and call the solver from C (see `cfunction`: http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#passing-julia-callback-functions-to-c ). On Mon, Jun 22, 2015 at 9:03 AM, Kostas Tavlaridis-Gyparakis kostas.tavlari...@gmail.com wrote: Hello, I am trying to embed Julia in C++ but I currently face some sort of issues. I am trying to follow the instructions shown here http://julia.readthedocs.org/en/latest/manual/embedding/. First things first, I run Ubuntu 15.04 and my Julia version is v. 0.3.2 (it's the version that is automatic installed when installing julia from ubuntu center). I use eclipse for my C++ projects, yet again I have the following issues, ac- cording to the instructions before trying to write any julia code in C or C++ you need first to: 1) link the julia library (assuming I undersand correctly this refers to libjulia.so), which should be located in Julia_DIR/usr/lib, yet again in my julia directory there is no folder under the name usr. I did though find a libjulia.so file in an other directory of my pc (/usr/lib/x86_64-linux-gnu/julia) and added this one instead. 2) include the path of julia.h which should be located in Julia_DIR/inclue/julia now again in my julia directory there are no such folders and in general there is nowhere in my pc any file such as julia.h. I did sth that is probably wrong and stupid but couldn't come up with anything else I downloaded this https://github.com/JuliaLang/julia and I included the location of where julia.h is located to eclipse as well with the direc- tions of all the other header files that were inculuded inside julia.h. Now when in Eclipse I am trying to compile and run a few simple julia commands having included julia.h i receive an error saying that there is no uv.h file in my system which is needed in one of the julia header files. I know that my whole approach is wrong, but yet again I couldn't find anywhere in my pc the proper folders or files in order to follow the steps that were sugges- ted in the julia website for running julia code inside C++. Any help would be much appreciated. Also, one more thing I wanted to ask is the following, in general writing Julia code inside a C++ code is limited? What I want to do in general is write a JuMP model inside C++, so in general is this possible, in the sense that by embedding Julia inside C++, will I be able to use all of the tools and code of Julia language or is this only limited to a cer- tain amount of commands and packages?
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
I guess so, except if you temporarily copy header files from here to a place where the compiler will find them (untested): Or add `jlulia/deps/libuv/include` to your compiler include path. On Tue, Oct 21, 2014 at 10:57 AM, Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 octobre 2014 à 07:12 -0700, Stefan Babinec a écrit : Hi Milan. Thanks for reply. Does it mean that until this is not fixed, I'm not able to use Julia's embeding c/c++ feature ? I guess so, except if you temporarily copy header files from here to a place where the compiler will find them (untested): https://github.com/JuliaLang/libuv/tree/julia-uv0.11.26/include But it may get fixed soon -- and even sooner if you propose a patch implementing Jeff's suggestion from https://github.com/JuliaLang/julia/issues/8690#issuecomment-59272693 Regards
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
Le mardi 21 octobre 2014 à 01:38 -0700, Stefan Babinec a écrit : Hello boyz. I tried to recompile on Windows first simple sample from http://docs.julialang.org/en/release-0.3/manual/embedding/ using gcc (mingw installed on Win) and following command from example: gcc -o test -I$JULIA_DIR/include/julia -L$JULIA_DIR/usr/lib -ljulia test.c I got following error: * C:/Users/SB/AppData/Local/Julia-0.3.1/include/julia/ios.h:5:16: fatal error: uv.h: No such file or directory #include uv.h compilation terminated. * I've got installed latest Julia's Release v0.3.1. I've checked the .../include/julia/ header files directory and there is no uv.h header file. See this: https://github.com/JuliaLang/julia/issues/8690 Regards
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
On Oct 21, 2014, at 4:38 AM, Stefan Babinec sysli...@gmail.com wrote: Hello boyz. Please keep in mind that there are both men and women reading and posting here.
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
Hi Milan. Thanks for reply. Does it mean that until this is not fixed, I'm not able to use Julia's embeding c/c++ feature ? Best Regards.
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
Le mardi 21 octobre 2014 à 07:12 -0700, Stefan Babinec a écrit : Hi Milan. Thanks for reply. Does it mean that until this is not fixed, I'm not able to use Julia's embeding c/c++ feature ? I guess so, except if you temporarily copy header files from here to a place where the compiler will find them (untested): https://github.com/JuliaLang/libuv/tree/julia-uv0.11.26/include But it may get fixed soon -- and even sooner if you propose a patch implementing Jeff's suggestion from https://github.com/JuliaLang/julia/issues/8690#issuecomment-59272693 Regards
Re: [julia-users] Embedding Julia in C on Windows - uv.h: No such file or directory
On Tuesday, October 21, 2014 9:57:18 AM UTC-5, Milan Bouchet-Valat wrote: But it may get fixed soon... Open PR is https://github.com/JuliaLang/julia/pull/8754