Library Index#
This section provides a complete list of all objects and functions in jluna, ordered by header name.
Note
Use the “search” bar on the left of the page or the table of contents in the top right to find any particular function quickly!
Box#
-
template<typename T>
unsafe::Value *jluna::docs_only::box(T value)# convert C++-side value to Julia-side value
Note
this function is a stand-in for the multitude of box functions in namespace
jluna::
. For a complete list of what value types can be boxed, please consult the manual.- Parameters:
value – C++-side value
- Returns:
pointer to julia-side value
-
template<is_julia_value T>
unsafe::Value *jluna::unsafe::unsafe_box(T*)# box without type checking
- Parameters:
value – C++-side value
- Returns:
julia-side value of equivalent type to C++ arg
Concept: is_boxable#
template<typename T>
concept is_boxable = requires(T t)
{
box(t);
} or requires(T t)
{
(unsafe::Value*) t;
};
Unbox#
-
template<typename T>
T jluna::docs_only::unbox(unsafe::Value *value)# convert Julia-side value to C++-side value
Note
this function is a stand-in for the multitude of unbox functions in namespace
jluna::
. For a complete list of what value types can be unboxed, please consult the manual.- Parameters:
value – pointer to julia-side memory of arbitrary type
- Returns:
C++-side object by value
-
template<typename T>
T jluna::unsafe::unsafe_unbox(unsafe::Value*)# unbox without type checking
- Parameters:
value – Julia-side value
- Returns:
unboxed value
Concept: is_unboxable#
template<typename T>
concept is_unboxable = requires(T t, jl_value_t* v)
{
{unbox<T>(v)};
};
Safe#
Safe: Initialize#
-
constexpr size_t jluna::JULIA_NUM_THREADS_AUTO = 0#
constant, equivalent to
-t auto
-
void jluna::initialize(size_t n_threads = 1, bool suppress_log = false, const std::string &jluna_shared_library_path = "", const std::string &julia_bindir = "", const std::string &image_path = "")#
initialize environment from image
- Parameters:
n_threads – number of threads to initialize the julia threadpool with. Default: 1
suppress_log – should logging be disabled. Default: No
jluna_shared_library_path – absolute path that is the location of libjluna.so. Leave empty to use default path
julia_bindir – absolute path that is the location of the julia image. Leave empty to use default path
image_path – the path of a system image file (*.so), a non-absolute path is interpreted as relative to julia_bindir
Safe: Call Function#
-
template<is_julia_value_pointer... Args_t>
unsafe::Value *jluna::safe_call(unsafe::Function *function, Args_t...)# call function with args, with verbose exception forwarding
- Template Parameters:
Args_t – argument types, must be castable to unsafe::Value*
- Parameters:
function – function
args – arguments, either need to be already Julia-side or boxable
- Returns:
result
Safe: Eval#
-
unsafe::Value *jluna::safe_eval(const std::string&, unsafe::Module *module = jl_main_module)#
evaluate string with exception forwarding
- Parameters:
string – code as string
module – module to eval the code in,
Main
by default
- Returns:
result
Safe: Miscellaneous#
-
unsafe::Value *jluna::as_julia_pointer(unsafe::Value*)#
forward value as Ptr{T}
- Template Parameters:
any – type castable to unsafe::Value*
- Parameters:
value – value
- Returns:
Julia-side pointer object
-
template<is_julia_value_pointer... Ts>
void jluna::println(Ts...)# call julia-side println on values
- Parameters:
values – values, if Julia-side, no operation will take place, if C++-side, values will be boxed before being printed
-
unsafe::Value *jluna::undef()#
get julia-side undef @eturns value of type UndefInitializer, does not need to be preserved
-
unsafe::Value *jluna::nothing()#
get julia-side nothing
- Returns:
value of type Nothing, does not need to be preserved
-
unsafe::Value *jluna::missing()#
get julia-side
- Returns:
value of type Missing, does not need to be preserved
-
void jluna::collect_garbage()#
trigger the garbage collector
Unsafe#
GC#
-
template<typename T>
size_t jluna::unsafe::docs_only::gc_preserve(T *value)# preserve value
- Parameters:
values – pointer
- Returns:
vector of ids, needed to free the objects
-
template<typename ...Ts>
size_t jluna::unsafe::docs_only::gc_preserve(Ts... value)# preserve values
- Parameters:
values – pointer
- Returns:
vector of ids, needed to free the objects
-
void jluna::unsafe::gc_release(size_t id)#
free a preserved object, the object may not be dealloaced immediately, simply marked for garbage collection
- Parameters:
id – id of object, result of gc_preserve
-
void jluna::unsafe::gc_release(std::vector<size_t> &ids)#
free preserved objects
- Parameters:
ids – vector of ids
-
void jluna::unsafe::gc_disable()#
set garbage collection to inactive
-
void jluna::unsafe::gc_enable()#
set garbage collection to active
Unsafe: Get / Call Functions#
-
unsafe::Function *jluna::unsafe::get_function(unsafe::Module *module, unsafe::Symbol *name)#
access function in module
- Parameters:
module – pointer to module object
name – function name
- Returns:
function pointer, or nullptr if not found
-
unsafe::Function *jluna::unsafe::get_function(unsafe::Symbol *module_name, unsafe::Symbol *function_name)#
access function by module name
- Parameters:
module_name – name of module, as opposed to the module itself
function_name – name of function
- Returns:
function pointer, or nullptr if not found
-
template<is_julia_value_pointer... Args_t>
unsafe::Value *jluna::unsafe::call(unsafe::Function *function, Args_t... args)# call function with args
- Template Parameters:
Args_t – argument types, must be castable to unsafe::Value*
- Parameters:
function – function to invoke
args – argument, forwarded to function
- Returns:
results of function or
nothing
-
template<is_julia_value_pointer... Args_t>
unsafe::Value *jluna::unsafe::call(unsafe::DataType *type, Args_t... args)# invoke a types constructor
- Template Parameters:
Args_t – argument types, must be castable to unsafe::Value*
- Parameters:
type – type whose constructor to call
args – arguments, forwarded to constructor
- Returns:
resulting type instance
Unsafe: Get / Set Values#
-
unsafe::Value *jluna::unsafe::get_value(unsafe::Module *module, unsafe::Symbol *name)#
get julia-side value by variable name
- Parameters:
module – module the variable is defined in
name – variable name
- Returns:
pointer to value
-
unsafe::Value *jluna::unsafe::get_value(unsafe::Symbol *module_name, unsafe::Symbol *variable_name)#
get julia-side value by variable name
- Parameters:
module – name of the module the variable is defined in, as opposed to the module itself
name – variable name
- Returns:
pointer to value
-
void jluna::unsafe::set_value(unsafe::Module *module, unsafe::Symbol *name, unsafe::Value *value)#
set julia-side value, by variable name
- Parameters:
module – module the variable is defined in
name – variable name
value – new value
- Returns:
pointer to variable after assignment, or nullptr if no assignment took place
-
void jluna::unsafe::set_value(unsafe::Symbol *module_name, unsafe::Symbol *variable_name)#
set julia-side value by variable name
- Parameters:
module – name of the module the variable is defined in, as opposed to the module itself
name – variable name
value – new value
- Returns:
pointer to variable after assignment, or nullptr if no assignment took place
Unsafe: Get / Set Fields#
-
unsafe::Value *jluna::unsafe::get_field(unsafe::Value *value, unsafe::Symbol *field)#
get value of a instances field
- Parameters:
value – instance
field – name of the field
- Returns:
value of the field
Unsafe: Expressions#
-
unsafe::Value *jluna::operator""_eval(const char*, size_t)#
literal operator for prettier syntax
- Returns:
result of jl_eval_string
-
unsafe::Symbol *jluna::operator""_sym(const char*, size_t)#
string suffix operator to create a symbol from a string
- Returns:
symbol
-
unsafe::Value *jluna::unsafe::eval(unsafe::Expression*, unsafe::Module* = jl_main_module)#
eval expression in module scope
- Parameters:
expression – expression
module – module to eval in
-
template<is_julia_value_pointer... Args_t>
unsafe::Expression *jluna::unsafe::Expr(unsafe::Symbol*, Args_t...)# construct a Julia-side expression
- Parameters:
symbol – used as Expr.head @params arguments: [optional] used as Expr.args
- Returns:
pointer to resulting expression
Proxy#
-
class Proxy#
holds ownership of julia-side value. mutating named proxies mutate the corresponding variable, c.f docs/manual.md
Subclassed by jluna::Array< Value_t, 1 >, jluna::Array< Value_t, Rank >, jluna::Module, jluna::Symbol, jluna::Type
Public Functions
-
Proxy()#
default ctor
-
Proxy(unsafe::Value *value, jl_sym_t *symbol = nullptr)#
construct with no owner, reserved for global temporaries and main
- Parameters:
value – value
symbol – name, or nullptr for unnamed proxy
construct with owner
- Parameters:
value – value
owner – shared pointer to owner
symbol – name, or nullptr for unnamed proxy
-
~Proxy()#
dtor
-
Proxy operator[](const std::string &field)#
access field
- Parameters:
field_name – name of the field
- Returns:
field as proxy
-
template<typename T, std::enable_if_t<std::is_same_v<T, char>, Bool> = true>
Proxy operator[](const T *field)# access field
- Parameters:
field_name – name of the field as const char*
- Returns:
field as proxy
-
template<is_unboxable T>
T operator[](const std::string &field)# access field
- Parameters:
field_name – name of the field as string
- Returns:
unboxed value
-
template<is_unboxable T, typename U, std::enable_if_t<std::is_same_v<U, char>, Bool> = true>
T operator[](const U *field)# access field
- Parameters:
field_name – name of the field as const char*
- Returns:
unboxed value
-
Proxy operator[](size_t)#
linear indexing, if array type, returns getindex result
- Parameters:
index – index, 0-based
- Returns:
field as proxy
-
template<is_unboxable T>
T operator[](size_t)# linear indexing, if array type returns getindex result
- Parameters:
index – index, 0-based
- Returns:
field as proxy
-
virtual operator std::string() const#
cast to string using Julia’s Base.string
-
template<is_unboxable T, std::enable_if_t<not std::is_same_v<T, std::string>, bool> = true>
operator T() const# implicitly convert to T via unboxing
- Returns:
value as T
-
template<typename T, std::enable_if_t<std::is_base_of_v<Proxy, T>, bool> = true>
operator T()# implicitly downcast to base
- Returns:
value as T
-
template<typename T, std::enable_if_t<std::is_base_of_v<Proxy, T>, bool> = true>
T as()# equivalent alternative to explicit operator T
- Returns:
value as T
-
std::string get_name() const#
get variable name, if any
- Returns:
name as string
-
std::vector<std::string> get_field_names() const#
if proxy is not a type value, get the fields of the proxies types. If proxy is already a type, get fieldnames of itself
- Returns:
vector of strings
-
bool isa(const Type &type)#
check if this <: type
- Parameters:
type – type
- Returns:
true if
*this isa type
, false otherwise
-
template<is_boxable... Args_t>
Proxy safe_call(Args_t&&...)# call with any arguments @tparams Args_t: types of arguments, need to be boxable
- Returns:
proxy
-
template<typename T, is_boxable... Args_t, std::enable_if_t<not std::is_void_v<T> and not is<Proxy, T>, bool> = true>
T safe_call(Args_t&&... args)# call and return value, does not construct proxy @tparams T: return value @tparams Args_t: types of arguments
- Returns:
value
-
template<typename T, is_boxable... Args_t, std::enable_if_t<std::is_void_v<T> and not is<Proxy, T>, bool> = true>
T safe_call(Args_t&&... args)# call and return value, does not construct proxy @tparams Args_t: types of arguments
- Returns:
nothing
-
template<is_boxable... Args_t>
Proxy operator()(Args_t&&...)# call with arguments and exception forwarding, if proxy is a callable function @tparams Args_t: types of arguments, need to be boxable
- Returns:
proxy
-
bool is_mutating() const#
check whether assigning to this proxy will modify values julia-side
- Returns:
true if set as mutating and neither an immutable type, singleton or const variable
-
Proxy &operator=(unsafe::Value*)#
assign value to proxy, this modifies the value julia-side
- Parameters:
value – Julia-side value
- Returns:
reference to self
-
template<is_boxable T>
Proxy &operator=(T)# assign value to proxy, this modifies the value julia-side
- Parameters:
T – value
- Returns:
reference to self
-
Proxy as_unnamed() const#
create a new unnamed proxy that holds the same value
- Returns:
new proxy by valuejluna: Manual & Tut
-
void update()#
update value if proxy symbol was reassigned outside of operator=
-
class ProxyValue#
internal proxy value, not intended to be interfaced with by end-users
-
Proxy()#
-
class ProxyValue
internal proxy value, not intended to be interfaced with by end-users
Module#
-
class Module : public jluna::Proxy#
Public Functions
-
Module(jl_module_t*)#
construct from Julia module, implicit
- Parameters:
value – pointer to Julia module
name – symbol
-
~Module()#
destructor
-
operator jl_module_t*()#
decay to C-type, implicit
-
Proxy safe_eval(const std::string&)#
eval string in module scope with exception forwarding
- Parameters:
code – julia code as string
- Returns:
result of expression as unnamed proxy
-
Proxy safe_eval_file(const std::string&)#
eval file in module scope, with exception forwarding
- Parameters:
path – absolute path to .jl file
- Returns:
result of executing the file
-
template<is_boxable T>
void assign(const std::string &variable_name, T value)# [thread-safe] assign variable with given name in module, if variable does not exist, throw UndefVarError
- Parameters:
name – variable name, should not contain “.”
value – new value
- Returns:
jluna::Proxy to value after assignment
-
template<is_boxable T>
void create_or_assign(const std::string &variable_name, T value)# [thread-safe] assign variable with given name in module, if variable does not exist, create it
- Parameters:
name – variable name, should not contain “.”
value – new value
- Returns:
jluna::Proxy to value after assignment
-
Proxy get(const std::string &variable_name)#
get variable value as named proxy
- Parameters:
variable_name – name of variable
- Returns:
proxy
-
template<is_unboxable T>
T get(const std::string &variable_name)# get variable value
- Template Parameters:
value – type
- Parameters:
variable_name – name of variable
- Returns:
value
-
Proxy new_undef(const std::string &name)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
- Returns:
named proxy to newly created value
-
Proxy new_bool(const std::string &name, bool value = false)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – bool value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_char(const std::string &name, char value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – uint32 unicode code, default 0
- Returns:
named proxy to newly created value
-
Proxy new_uint8(const std::string &name, uint8_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – uint8 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_uint16(const std::string &name, uint16_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – uint16 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_uint32(const std::string &name, uint32_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – uint32 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_uint64(const std::string &name, uint64_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – uint64 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_int8(const std::string &name, int8_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – int8 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_int16(const std::string &name, int16_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – int16 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_int32(const std::string &name, int32_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – int32 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_int64(const std::string &name, int64_t value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – int64 value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_float32(const std::string &name, float value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – float value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_float64(const std::string &name, double value = 0)#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – double value, default 0
- Returns:
named proxy to newly created value
-
Proxy new_string(const std::string &name, const std::string &value = "")#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – string
- Returns:
named proxy to newly created value
-
Proxy new_symbol(const std::string &name, const std::string &value = "")#
[thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
variable_name – exact name of variable
value – string
- Returns:
named proxy to newly created value
-
template<is_primitive T>
Proxy new_complex(const std::string &name, T real = 0, T imag = 0)# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
value – type T of Core.Complex{T}
- Parameters:
variable_name – exact name of variable
real – real part of complex number
imag – imaginary part of complex number
- Returns:
named proxy to newly created value
-
template<is_boxable T>
Proxy new_vector(const std::string &name, const std::vector<T>& = {})# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
value – type T of Core.Vector{T}
- Parameters:
variable_name – exact name of variable
vector – vector
- Returns:
named proxy to newly created value
-
template<is_boxable Key_t, is_boxable Value_t>
Proxy new_dict(const std::string &name, const std::map<Key_t, Value_t>& = {})# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
Key_t – key type in Base.IdDict{Key_t, Value_t}
Value_t – value type in Base.IdDict{Key_t, Value_t}
- Parameters:
variable_name – exact name of variable
map – map
- Returns:
named proxy to newly created value
-
template<is_boxable Key_t, is_boxable Value_t>
Proxy new_dict(const std::string &name, const std::unordered_map<Key_t, Value_t>& = {})# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
Key_t – key type in Base.Dict{Key_t, Value_t}
Value_t – value type in Base.Dict{Key_t, Value_t}
- Parameters:
variable_name – exact name of variable
unordered_map – unordered map
- Returns:
named proxy to newly created value
-
template<is_boxable T>
Proxy new_set(const std::string &name, const std::set<T> &value = {})# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
value – type of Base.Set{T}
- Parameters:
variable_name – exact name of variable
set – set
- Returns:
named proxy to newly created value
-
template<is_boxable T1, is_boxable T2>
Proxy new_pair(const std::string &name, T1 first, T2 second)# [thread-safe] creates new variable in main, then returns named proxy to it
- Template Parameters:
T1 – first value type
T2 – second value type
- Parameters:
variable_name – exact name of variable
first – first
second – second
- Returns:
named proxy to newly created value
-
template<is_boxable... Ts>
Proxy new_tuple(const std::string &name, Ts...)# [thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
Ts... – value types
variable_name – exact name of variable
values – tuple values
- Returns:
named proxy to newly created value
-
template<is_boxable T, size_t N, is<size_t>... Dims>
Array<T, N> new_array(const std::string &name, Dims... dims)# [thread-safe] creates new variable in main, then returns named proxy to it
- Parameters:
T – value types
variable_name – exact name of variable
dims – length in each dimension
- Returns:
named proxy to newly created array, filled with undef
-
Module get_parent_module() const#
wrap c-property parent
- Returns:
parent as module, nullptr if topmod
-
bool is_top_module() const#
wrap hidden c-property istopmod
- Returns:
bool
-
bool is_defined(const std::string &variable_name) const#
is variable defined
- Parameters:
name – exact variable name
- Returns:
Base.isdefined(this, :name)
-
void import(const std::string &package_name)#
import a package
- Parameters:
package_name –
-
void add_using(const std::string &package_name)#
import names
- Parameters:
package_name –
-
void include(const std::string &file_path)#
include file in module scope
- Parameters:
package_name –
-
Module(jl_module_t*)#
Unsafe: Arrays#
-
unsafe::Array *jluna::unsafe::docs_only::new_array(unsafe::Value *value_type, size_t one_d)#
allocate 1d array
- Parameters:
value_type – value type of the array @params one_d: size along first dimension
- Returns:
array after allocation
-
unsafe::Array *jluna::unsafe::docs_only::new_array(unsafe::Value *value_type, size_t one_d, size_t two_d)#
allocate 1d array
- Parameters:
value_type – value type of the array @params one_d: size along first dimension @params two_d: size along second dimension
- Returns:
array after allocation
-
template<typename ...Dims>
unsafe::Array *jluna::unsafe::docs_only::new_array(unsafe::Value *value_type, Dims... size_per_dimension)# allocate new array
- Parameters:
value_type – value type of the array @params size_per_dimension: size along each dimension
- Returns:
array after allocation
-
unsafe::Array *jluna::unsafe::docs_only::new_array_from_data(unsafe::Value *value_type, void *data, size_t one_d)#
allocate 1d array as thin wrapper
- Parameters:
value_type – value type of the array
data – pointer to the data, no verification is performed that the data is properly aligned or of the given value type @params size: size along first dimension
- Returns:
array object as thin wrapper
-
template<typename ...Dims>
unsafe::Array *jluna::unsafe::docs_only::new_array_from_data(unsafe::Value *value_type, void *data, Dims... size_per_dimension)# create an array from already existing data, does not invoking a copy
- Parameters:
value_type – value type of the array
data – pointer to the data, no verification is performed that the data is properly aligned or of the given value type
size_per_dimension – size along each dimension
- Returns:
array object as thin wrapper
-
void jluna::unsafe::sizehint(unsafe::Array*, size_t n_elements)#
pre-allocate array, may increase performance
- Parameters:
array – array to reserve
n_elements – new number of elements
-
template<typename ...Dims>
void jluna::unsafe::docs_only::resize_array(unsafe::Array *array, Dims...)# reshape array along all dimensions
- Parameters:
array – array to reshape
size_per_dimension – size along each dimension, number of dimension is denoted by the number of sizes
-
void jluna::unsafe::docs_only::resize_array(unsafe::Array *array, size_t one_d)#
reshape array to 1d
Note
optimal performance is only achieved if the array is already 1d
- Parameters:
array – array to reshape
one_d – size along first dimension
-
void jluna::unsafe::docs_only::resize_array(unsafe::Array *array, size_t one_d, size_t two_d)#
reshape array to 2d
Note
optimal performance is only achieved if the array is already 2d
- Parameters:
array – array to reshape
one_d – size along first dimension
two_d – size along second dimension
-
void jluna::unsafe::override_array(unsafe::Array *overridden, const unsafe::Array *constant)#
replace one arrays content with another, does not cause allocation
- Parameters:
overridden – array to be modified
constant – unmodified array whose data will be written to the argument
-
size_t jluna::unsafe::get_array_size(unsafe::Array*)#
get number of elements in array
- Parameters:
array – array
- Returns:
number of elements
-
size_t jluna::unsafe::get_array_size(unsafe::Array*, size_t dimension_index)#
get array size along specified dimension
- Parameters:
dimension_index – index, 0-based
- Returns:
size along that dimension
-
template<typename ...Index>
unsafe::Value *jluna::unsafe::docs_only::get_index(unsafe::Array*, Index... index_per_dimension)# access element
- Parameters:
array – array to access @params index_per_dimension: index in each dimension
- Returns:
pointer to element, or nullptr if out of bounds
-
unsafe::Value *jluna::unsafe::docs_only::get_index(unsafe::Array*, size_t)#
access element, linear indexing
- Parameters:
array – array to access @params index: index along the first dimension
- Returns:
pointer to element, or nullptr if out of bounds
-
unsafe::Value *jluna::unsafe::docs_only::get_index(unsafe::Array*, size_t, size_t)#
access element, linear indexing
- Parameters:
array – array to access @params i: index along the first dimension @params j: index along the second dimension
- Returns:
pointer to element, or nullptr if out of bounds
-
template<typename ...Index>
void jluna::unsafe::docs_only::set_index(unsafe::Array*, unsafe::Value *value, Index... index_per_dimension)# modify element by index
- Parameters:
array – array to modify
new_value – new value assigned to the element @params index_per_dimension: index in each dimension
-
void jluna::unsafe::docs_only::set_index(unsafe::Array*, unsafe::Value *value, size_t)#
modify element by index
- Parameters:
array – array to modify
value – new value assigned to the element @params index: index along the first dimension
-
void jluna::unsafe::docs_only::set_index(unsafe::Array*, unsafe::Value *value, size_t, size_t)#
modify element by index
- Parameters:
array – array to modify
value – new value assigned to the element @params i: index along the first dimension @params j: index along the second dimension
-
unsafe::Value *jluna::unsafe::get_array_data(unsafe::Array*)#
access raw array data
- Parameters:
array – array
- Returns:
pointer to first element
-
void jluna::unsafe::swap_array_data(unsafe::Array *before, unsafe::Array *after)#
swap raw array data, resizes arrays if necessary
- Parameters:
before – initial array, will be modified
after – array whos data will be written to the initial array
-
template<typename T>
void jluna::unsafe::set_array_data(unsafe::Array *array, T *new_data, size_t new_size)# set array data, resizes array if necessary
Note
if value types mismatch, the behavior is undefined
- Parameters:
array – array to be modified
new_data – pointer to new data
new_size – number of elements in new_data
-
void jluna::unsafe::push_front(unsafe::Array*, unsafe::Value *value)#
push element to front of 1d array
- Parameters:
array – array
value – value
Array#
-
template<is_boxable Value_t, size_t Rank>
class Array : public jluna::Proxy# wrapper for julia-side Array{Value_t, Rank}
- Template Parameters:
Value_t – boxable value ype
Rank – rank of the array
Public Functions
-
Array(Proxy*)#
construct as child of already existing proxy, implicit
- Parameters:
proxy – pointer to already created proxy
-
Array(unsafe::Value *value, jl_sym_t *symbol = nullptr)#
constructor
- Parameters:
value – pointer to Julia-side allocated array
symbol – name of Julia-side variable, or nullptr for anonymous variable
-
Array(size_t)#
constructor, initialize values as undef, implicit
- Parameters:
size – target size of the new array
-
template<typename ...Dims>
Array(Value_t*, Dims... size_per_dimension)# construct as thin wrapper, does not invoke copy
Warning
user is responsible for data being properly formatted and staying in scope
- Parameters:
data – raw pointer to Julia-side data
size_per_dimension – size along all dimensions, where Rank is the number of dimensions
-
auto operator[](size_t)#
linear indexing, no bounds checking
Note
this function intentionally shadows Proxy::operator[](size_t) -> Proxy
- Parameters:
index – 0-based
- Returns:
assignable iterator to element
-
jluna::Vector<Value_t> operator[](const GeneratorExpression&) const#
julia-style array comprehension indexing
- Parameters:
generator_expression – generator expression used for the index list
- Returns:
new array, result of Julia-side getindex(this, range)
-
jluna::Vector<Value_t> operator[](const std::vector<size_t> &range) const#
julia-style list indexing
- Parameters:
range – iterable range with indices
- Returns:
new array, result of Julia-side getindex(this, range)
-
template<is_boxable T>
jluna::Vector<Value_t> operator[](std::initializer_list<T>&&) const# julia-style list indexing
- Parameters:
list – initializer list with indices
- Returns:
new array, result of Julia-side getindex(this, range)
-
template<is_unboxable T = Value_t>
T operator[](size_t) const# linear indexing, no bounds checking
- Template Parameters:
T – return type, usually Value_t
- Parameters:
index – index, 0-based
- Returns:
unboxed value at given index. May throw jluna::JuliaException if index out of range
- template<typename... Args, std::enable_if_t< sizeof...(Args)==Rank and(std::is_integral_v< Args > and ...), bool > = true> auto at (Args... in)
multi-dimensional indexing
- Parameters:
n – Rank-many integers
- Returns:
non-const (assignable) iterator to value
- template<is_unboxable T = Value_t, typename... Args, std::enable_if_t< sizeof...(Args)==Rank and(std::is_integral_v< Args > and ...), bool > = true> T at (Args... in) const
multi-dimensional indexing
- Parameters:
n – Rank-many integers
- Returns:
unboxed value
-
template<is_boxable T = Value_t>
void set(size_t i, T)# manually assign a value using a linear index
- Parameters:
index – linear index, 0-based
value – new value
-
size_t get_n_elements() const#
get number of elements
- Returns:
Base.length
-
size_t size(size_t dimension_index) const#
get size in specific dimension
- Parameters:
dimension_index – 0-based
- Returns:
result of Base.size(array, dimension_index)
-
auto begin()#
get iterator to 0-indexed element
- Returns:
assignable iterator
-
auto begin() const#
get iterator to 0-indexed element
- Returns:
const iterator
-
auto end()#
get iterator to past-the-end element
- Returns:
assignable iterator
-
auto end() const#
get iterator to past-the-end element
- Returns:
const iterator
-
auto front()#
get first element, equivalent to operator[](0)
- Returns:
assignable iterator
-
template<is_unboxable T = Value_t>
T front() const# get first element, equivalent to operator[](0)
- Returns:
unboxed value
-
auto back()#
get last valid element
- Returns:
assignable iterator
-
bool empty() const#
is empty
- Returns:
true if size is 0 along all dimensions, false otherwise
-
void reserve(size_t)#
call Base.sizehint!, allocates array to be of specified size. Useful for optimization
- Parameters:
size – target size
-
void *data()#
expose raw data as void*
- Returns:
void pointer
Public Static Attributes
-
class ConstIterator#
non-assignable iterator
Subclassed by jluna::Array< Value_t, Rank >::Iterator
Public Functions
-
auto &operator++()#
increment
- Returns:
reference to self
-
auto &operator++(int)#
post-fix increment
- Returns:
reference to self
-
auto &operator--()#
post-fix decrement
- Returns:
reference to self
-
auto &operator--(int)#
post-fix decrement
- Returns:
reference to self
-
bool operator==(const ConstIterator&) const#
equality operator
- Parameters:
other – other iterator
- Returns:
true if both iterators iterat the same array and have the same linear index
-
bool operator!=(const ConstIterator&) const#
inequality operator
- Parameters:
other – other iterator
- Returns:
not (this == other)
-
auto operator*() const#
forward to self
- Returns:
self
-
auto operator*()#
forward to assignable
- Returns:
assignable
-
auto &operator++()#
-
struct Iterator : public jluna::Array<Value_t, Rank>::ConstIterator#
assignable iterator
Public Functions
-
template<is_boxable T = Value_t>
auto &operator=(T value)# assign array being iterated at given position, also assigns Julia-side proxy, even if host proxy is not mutating
- Parameters:
value – new value
- Returns:
reference to self
-
template<is_unboxable T = Value_t, std::enable_if_t<not std::is_same_v<T, Proxy>, bool> = true>
operator T() const# decay into unboxed value
- Template Parameters:
value-type, not – necessarily the same as declared in the array type, implicit
-
auto operator*() const#
forward to self
- Returns:
self
-
auto operator*()#
forward to assignable
- Returns:
assignable
-
template<is_boxable T = Value_t>
Array: Non-Const Iterator#
-
struct Iterator : public jluna::Array<Value_t, Rank>::ConstIterator
assignable iterator
Public Functions
-
Iterator(size_t i, Array<Value_t, Rank>*)
ctor
- Parameters:
index –
pointer – to array
-
template<is_boxable T = Value_t>
auto &operator=(T value) assign array being iterated at given position, also assigns Julia-side proxy, even if host proxy is not mutating
- Parameters:
value – new value
- Returns:
reference to self
-
template<is_unboxable T = Value_t, std::enable_if_t<not std::is_same_v<T, Proxy>, bool> = true>
operator T() const decay into unboxed value
- Template Parameters:
value-type, not – necessarily the same as declared in the array type, implicit
-
auto operator*() const
forward to self
- Returns:
self
-
auto operator*()
forward to assignable
- Returns:
assignable
-
Iterator(size_t i, Array<Value_t, Rank>*)
Array: Const Iterator#
-
class ConstIterator
non-assignable iterator
Subclassed by jluna::Array< Value_t, Rank >::Iterator
Public Functions
-
ConstIterator(size_t i, Array<Value_t, Rank>*)
ctor
- Parameters:
index –
pointer – to array
-
auto &operator++()
increment
- Returns:
reference to self
-
auto &operator++(int)
post-fix increment
- Returns:
reference to self
-
auto &operator--()
post-fix decrement
- Returns:
reference to self
-
auto &operator--(int)
post-fix decrement
- Returns:
reference to self
-
bool operator==(const ConstIterator&) const
equality operator
- Parameters:
other – other iterator
- Returns:
true if both iterators iterat the same array and have the same linear index
-
bool operator!=(const ConstIterator&) const
inequality operator
- Parameters:
other – other iterator
- Returns:
not (this == other)
-
auto operator*() const
forward to self
- Returns:
self
-
auto operator*()
forward to assignable
- Returns:
assignable
-
template<is_unboxable T = Value_t, std::enable_if_t<not is<Proxy, T>, bool> = true>
operator T() const decay into unboxed value, implicit
- Template Parameters:
T – value type, not necessarily the same as declared in the array type
-
operator Proxy()
decay into proxy, implicit
-
ConstIterator(size_t i, Array<Value_t, Rank>*)
Array: Typedefs#
Vector#
-
template<is_boxable Value_t>
class Vector : public jluna::Array<Value_t, 1># vector, alias for array of rank 1
Public Functions
-
Vector()#
- Parameters:
default – ctor
-
Vector(const std::vector<Value_t> &vec)#
construct as unnamed proxy from vector
- Parameters:
vector – C++-side vector
-
Vector(const GeneratorExpression&)#
construct from generator expression
- Parameters:
expression – generator expression, will be fully serialized on constructor call
-
Vector(Value_t *data, size_t size)#
constrct as thin wrapper around data
Warning
the user is responsible for data being correctly formatted and staying in scope
- Parameters:
data – pointer to Julia-side data
size – size along the first dimension
-
Vector(unsafe::Value *value, jl_sym_t *symbol = nullptr)#
construct from value
- Parameters:
value – Julia-side value
symbol – name of variable, or nullptr if anonymous variable
-
void insert(size_t pos, Value_t value)#
insert a value
- Parameters:
pos – linear index, 0-based
value – new value
-
void erase(size_t pos)#
erase at specified position
- Parameters:
pos – linear index, 0-based
-
Vector()#
cppcall#
-
template<typename Signature, typename Lambda_t>
unsafe::Value *jluna::as_julia_function(Lambda_t lambda)# make lambda available to Julia
- Template Parameters:
Signature – signature of lambda, C-style
Lambda_t – automatically deduced
- Returns:
unsafe pointer to Julia-side function object
-
template<typename Return_t>
unsafe::Value *jluna::register_function(std::function<Return_t()>)# make function with signature () -> Return_t available to julia
- Template Parameters:
Return_t – return type of lambda, may be
void
- Parameters:
function – lambda
- Returns:
unsafe pointer to Julia-side function object
-
template<typename Return_t, typename Arg1_t>
unsafe::Value *jluna::register_function(std::function<Return_t(Arg1_t)> f)# make function with signature (T1) -> Return_t available to julia
- Template Parameters:
Return_t – return type of lambda, may be
void
- Parameters:
function – lambda
- Returns:
unsafe pointer to Julia-side function object
-
template<typename Return_t, typename Arg1_t, typename Arg2_t>
unsafe::Value *jluna::register_function(std::function<Return_t(Arg1_t, Arg2_t)> f)# make function with signature (T1, T2) -> Return_t available to julia
- Template Parameters:
Return_t – return type of lambda, may be
void
- Parameters:
function – lambda
- Returns:
unsafe pointer to Julia-side function object
-
template<typename Return_t, typename Arg1_t, typename Arg2_t, typename Arg3_t>
unsafe::Value *jluna::register_function(std::function<Return_t(Arg1_t, Arg2_t, Arg3_t)> f)# make function with signature (T1, T2, T3) -> Return_t available to julia
- Template Parameters:
Return_t – return type of lambda, may be
void
- Parameters:
function – lambda
- Returns:
unsafe pointer to Julia-side function object
Exceptions#
-
class JuliaException : public std::exception#
wrapper for julia exceptions
Public Functions
-
JuliaException() = default#
default ctor
-
JuliaException(jl_value_t *exception, const std::string &stacktrace)#
ctor
- Parameters:
exception – value pointing to a julia-side instance of the exception
stacktrace – string describing the exception and the stacktrace
-
const char *what() const noexcept final#
get description
- Returns:
c-string
-
JuliaException() = default#
-
struct JuliaUninitializedException : public std::exception#
exception thrown when trying to use jluna or julia before initialization
-
void jluna::forward_last_exception()#
if exception occurred, forward as JuliaException
-
void jluna::throw_if_uninitialized()#
throw if initialize was not yet called
Generator Expression#
-
class GeneratorExpression#
wrapper for Base.Generator, only create by _gen
Note
expression is evaluated lazily
Public Functions
-
~GeneratorExpression()#
dtor
-
ForwardIterator begin() const#
get iterator to front of range
- Returns:
iterator
-
ForwardIterator end() const#
get iterator to past-the-end element
- Returns:
iterator
-
size_t size() const#
get length of iterable component
-
class ForwardIterator#
Iterator.
Public Functions
-
ForwardIterator(const GeneratorExpression*, Int64)#
Ctor.
-
template<is_unboxable T>
operator T()# cast to C++ type
- Template Parameters:
resulting – type
- Returns:
T
-
void operator++()#
prefix advance by 1 state
-
void operator++(int)#
postfix advance by 1 state
-
bool operator==(const GeneratorExpression::ForwardIterator &other) const#
comparison
- Parameters:
other – other iterator
- Returns:
true if iterators point to the same expression and have the same state
-
bool operator!=(const GeneratorExpression::ForwardIterator &other) const#
comparison
- Parameters:
other – other iterator
- Returns:
false if iterators point to the same expression and have the same state
-
ForwardIterator(const GeneratorExpression*, Int64)#
-
~GeneratorExpression()#
-
class ForwardIterator
Iterator.
Public Functions
-
ForwardIterator(const GeneratorExpression*, Int64)
Ctor.
-
unsafe::Value *operator*()
dereference to julia object
-
template<is_unboxable T>
operator T() cast to C++ type
- Template Parameters:
resulting – type
- Returns:
T
-
void operator++()
prefix advance by 1 state
-
void operator++(int)
postfix advance by 1 state
-
bool operator==(const GeneratorExpression::ForwardIterator &other) const
comparison
- Parameters:
other – other iterator
- Returns:
true if iterators point to the same expression and have the same state
-
bool operator!=(const GeneratorExpression::ForwardIterator &other) const
comparison
- Parameters:
other – other iterator
- Returns:
false if iterators point to the same expression and have the same state
-
ForwardIterator(const GeneratorExpression*, Int64)
Multi Threading#
Future#
-
template<typename Value_t>
class Future# the result of a thread
Task#
-
template<typename Result_t>
class Task# Public Functions
-
~Task()#
dtor
-
Task &operator=(Task &&other) noexcept#
move ctor
- Parameters:
other – other task, will be unusable after
-
void join()#
stall the thread this function is called from until the task is done
-
void schedule()#
start the thread
-
bool is_failed() const#
is task failed
- Returns:
true if task has failed and exited, false otherwise
-
~Task()#
-
void jluna::yield()#
pause the current task, has to be called from within a task allocated via ThreadPool::create
ThreadPool#
-
class ThreadPool#
threadpool that allows scheduled C++-side tasks to safely access the Julia State from within a thread. Pool cannot be resized, it will use the native Julia threads to execute any C++-side tasks
Note
during task creation, the copy ctor will be invoked for all arguments
args
and the functions return value. To avoid this, wrap the type in an std::refPublic Static Functions
-
template<typename ...Args_t>
static Task<void> create(const std::function<void(Args_t...)> &f, Args_t... args)# create a task from a std::function returning void
Note
once the task is done, .result() will return a future with value of type jluna::Nothing_t
- Parameters:
f – function returning void
args – arguments
- Returns:
Task, not yet scheduled
-
template<is_not<void> Return_t, typename ...Args_t>
static Task<Return_t> create(const std::function<Return_t(Args_t...)> &f, Args_t... args)# create a task from a std::function returning non-void
- Parameters:
f – function
args – arguments
- Returns:
Task, not yet scheduled
-
template<typename Signature, typename Lambda_t, typename ...Args_t, typename T = std::invoke_result_t<std::function<Signature>, Args_t...>>
static Task<T> create(Lambda_t f, Args_t... args)# create a task from a lambda
- Parameters:
f – lambda
args – arguments
- Returns:
Task, not yet scheduled
-
static size_t n_threads()#
get number of threads
- Returns:
number
-
static size_t thread_id()#
get id of current task
- Returns:
number
-
template<typename ...Args_t>
Mutex#
-
class Mutex#
thread-safe wrapper for Base.ReentrantLock, lockable and capable of stalling both a Julia task and a C++ thread
Symbol#
-
class Symbol : public jluna::Proxy#
wrapper for
jl_sym_t*
Public Functions
-
Symbol()#
default ctor
-
Symbol(const std::string&)#
allocate symbol Julia-side, implicit
- Parameters:
string – value of symbol, constructed via
Base.Symbol(string)
-
Symbol(jl_sym_t *value, jl_sym_t *symbol = nullptr)#
construct as unnamed proxy, implicit
- Parameters:
value – Julia-side symbol
name – name of proxy, or nullptr for unnamed proxy
-
operator jl_sym_t*() const#
decay to C-type, implicit
-
size_t hash() const#
hash, constant runtime
- Returns:
hash
-
bool operator==(const Symbol &other) const#
equality operator, uses hash
- Parameters:
other – other symbol
- Returns:
true if hashes equal, false otherwise
-
bool operator!=(const Symbol &other) const#
inequality operator, uses hash
- Parameters:
other – other symbol
- Returns:
false if hashes equal, true otherwise
-
bool operator<(const Symbol &other) const#
comparison operator, uses hash
- Parameters:
other – other symbol
- Returns:
true if this.hash < other.hash
-
bool operator<=(const Symbol &other) const#
comparison operator, uses hash
- Parameters:
other – other symbol
- Returns:
true if this.hash <= other.hash
-
Symbol()#
Type#
-
class Type : public jluna::Proxy#
forward declaration
Public Functions
-
Type()#
default ctor, construct as Nothing
-
Type(jl_datatype_t *value)#
construct from type, implicit
- Parameters:
value – Julia-side type
-
operator jl_datatype_t*()#
decay to C-type, implicit
-
size_t get_n_parameters() const#
get number of parameters
- Returns:
size_t
-
size_t get_n_fields() const#
get number of fields
- Returns:
size_t
-
unsafe::Value *get_singleton_instance() const#
if type is singleton, get instance of that singleton
- Returns:
instance ptr if singleton-type, nullptr otherwise
-
bool is_subtype_of(const Type&) const#
this <: other
- Parameters:
other – other type
- Returns:
true if subtype, false otherwise
-
bool operator<(const Type&) const#
this <: other
- Parameters:
other – other type
- Returns:
true if subtype, false otherwise
-
bool is_supertype_of(const Type&) const#
other <: this
- Parameters:
other – other type
- Returns:
true if super, false otherwise
-
bool operator>(const Type&) const#
this <: other
- Parameters:
other – other type
- Returns:
true if subtype, false otherwise
-
bool is_same_as(const Type&) const#
this === other
- Parameters:
other – other type
- Returns:
true if both are the same type, false otherwise
-
bool operator==(const Type&) const#
this === other
- Parameters:
other – other type
- Returns:
true if both are the same type, false otherwise
-
bool operator!=(const Type&) const#
not(this === other)
- Parameters:
other – other type
- Returns:
true if both are the same type, false otherwise
-
bool is_primitive() const#
is primitive type
- Returns:
bool
-
bool is_struct_type() const#
is struct type
- Returns:
bool
-
bool is_declared_mutable() const#
is mutable
- Returns:
bool
-
bool is_isbits() const#
is bits type
- Returns:
bool
-
bool is_singleton() const#
is singleton
- Returns:
bool
-
bool is_abstract_type() const#
is abstract
- Returns:
bool
-
bool is_abstract_ref_type() const#
is abstract ref
- Returns:
bool
-
bool typename_is(const std::string &symbol)#
check if .name property of unrolled type is equal to typename
- Parameters:
symbol – name of type, evaluated to Main.eval(symbol)
- Returns:
bool
-
Type()#
Typedefs#
-
using jluna::Bool = bool#
1-bit bool interpreted as 8-bit Bool julia-side
-
using jluna::Char = uint8_t#
8-bit char interpreted as 32-bit Char julia-side
-
using jluna::Int8 = int8_t#
8-bit int interpreted as Int8 julia-side
-
using jluna::Int16 = int16_t#
16-bit int interpreted as Int16 julia-side
-
using jluna::Int32 = int32_t#
32-bit int interpreted as Int32 julia-side
-
using jluna::Int64 = int64_t#
64-bit int interpreted as Int64 julia-side
-
using jluna::UInt8 = uint8_t#
8-bit unsigned int interpreted as UInt8 julia-side
-
using jluna::UInt16 = uint16_t#
16-bit unsigned int interpreted as UInt16 julia-side
-
using jluna::UInt32 = uint32_t#
32-bit unsigned int interpreted as UInt32 julia-side
-
using jluna::UInt64 = uint64_t#
64-bit unsigned int interpreted as UInt64 julia-side
-
using jluna::Float32 = float#
32-bit float interpreted as Float32 julia-side
-
using jluna::Float64 = double#
64-bit double interpreted as Float64 julia-side
-
using jluna::Nothing = void#
nothing
-
using jluna::unsafe::Value = jl_value_t#
address of julia-side memory
-
using jluna::unsafe::Function = jl_function_t#
address of julia-side function
-
using jluna::unsafe::Symbol = jl_sym_t#
julia-side, non-proxy symbol
-
using jluna::unsafe::Module = jl_module_t#
julia-side, non-proxy module
-
using jluna::unsafe::Expression = jl_expr_t#
julia-side expression
-
using jluna::unsafe::Array = jl_array_t#
julia-side array
-
using jluna::unsafe::DataType = jl_datatype_t#
julia-side type
-
template<typename T>
struct as_julia_type# constexpr transform C++ type into the julia type it will be after unboxing
- Template Parameters:
C++ – type
- Return:
type_name, accessible via member if type can be deduced, has no member otherwise
template<typename T>
concept to_julia_type_convertable = requires(T)
{
as_julia_type<T>::type_name;
};
Usertype#
-
set_usertype_enabled(T)#
declare T to be a usertype at compile time, uses C++-side name as Julia-side typename
- Parameters:
T – type
-
template<typename T>
class Usertype# customizable wrapper for non-julia type T
Note
for information on how to use this class, visit https://github.com/Clemapfel/jluna/blob/master/docs/manual.md#usertypes
Public Functions
-
Usertype() = delete#
ctor delete, static-only interface
Public Static Functions
-
static bool is_enabled()#
was enabled at compile time using set_usertype_enabled
- Returns:
bool
-
static std::string get_name()#
get julia-side name
- Returns:
name
-
template<typename Field_t>
static void add_property(const std::string &name, std::function<Field_t(T&)> box_get, std::function<void(T&, Field_t)> unbox_set = noop_set<Field_t>)# add field
- Parameters:
name – julia-side name of field
box_get – lambda with signature (T&) -> unsafe::Value*
unbox_set – lambda with signature (T&, unsafe::Value*) -> void
-
static void implement(unsafe::Module *module = Main)#
create the type, setup through the interface, julia-side
- Parameters:
module – module in which the type is evaluated
-
static bool is_implemented()#
has implement() been called at least once
- Returns:
bool
-
static unsafe::Value *box(T&)#
box interface
Note
this function will call implement() if it has not been called before, incurring a tremendous overhead on first execution, once
- Parameters:
T& – instance
- Returns:
boxed value
-
static T unbox(unsafe::Value*)#
box interface
Note
this function will call implement() if it has not been called before, incurring a tremendous overhead on first execution, once
- Parameters:
unsafe::Value* –
- Returns:
unboxed value
-
Usertype() = delete#