nb module¶
Numba-compiled functions.
Provides an arsenal of Numba-compiled functions for records and mapped arrays. These only accept NumPy arrays and other Numba-compatible types.
Note
vectorbt treats matrices as first-class citizens and expects input arrays to be 2-dim, unless function has suffix _1d
or is meant to be input to another function. Data is processed along index (axis 0).
All functions passed as argument should be Numba-compiled.
Records should retain the order they were created in.
ol_expand_mapped_nb function¶
_expand_mapped_nb(
mapped_arr,
col_arr,
idx_arr,
target_shape,
fill_value
)
ol_stack_expand_mapped_nb function¶
_stack_expand_mapped_nb(
mapped_arr,
col_map,
fill_value
)
apply_on_mapped_nb function¶
apply_on_mapped_nb(
mapped_arr,
col_map,
apply_func_nb,
*args
)
Apply function on mapped array per column.
Returns the same shape as mapped_arr
.
apply_func_nb
should accept the indices of values, index of the column, values of the column, and *args
, and return an array.
apply_on_records_nb function¶
apply_on_records_nb(
records,
col_map,
apply_func_nb,
*args
)
Apply function on records per column.
Returns the same shape as records
.
apply_func_nb
should accept the records of the column and *args
, and return an array.
bottom_n_inout_map_nb function¶
bottom_n_inout_map_nb(
inout,
idxs,
col,
mapped_arr,
n
)
inout_map_func_nb
that returns indices of bottom N elements.
col_map_nb function¶
col_map_nb(
col_arr,
n_cols
)
Build a map between columns and their indices.
Returns an array with indices segmented by column, and an array with count per segment.
Works well for unsorted column arrays.
col_map_select_nb function¶
col_map_select_nb(
col_map,
new_cols
)
Same as mapped_col_range_select_nb
but using column map col_map
.
col_range_nb function¶
col_range_nb(
col_arr,
n_cols
)
Build column range for sorted column array.
Creates a 2-dim array with first column being start indices (inclusive) and second column being end indices (exclusive).
Note
Requires col_arr
to be in ascending order. This can be done by sorting.
col_range_select_nb function¶
col_range_select_nb(
col_range,
new_cols
)
Perform indexing on a sorted array using column range col_range
.
Returns indices of elements corresponding to columns in new_cols
and a new column array.
expand_mapped_nb function¶
expand_mapped_nb(
mapped_arr,
col_arr,
idx_arr,
target_shape,
fill_value
)
Set each element to a value by boolean mask.
is_col_idx_sorted_nb function¶
is_col_idx_sorted_nb(
col_arr,
id_arr
)
Check whether the column and index arrays are sorted.
is_col_sorted_nb function¶
is_col_sorted_nb(
col_arr
)
Check whether the column array is sorted.
is_mapped_expandable_nb function¶
is_mapped_expandable_nb(
col_arr,
idx_arr,
target_shape
)
Check whether mapped array can be expanded without positional conflicts.
map_records_nb function¶
map_records_nb(
records,
map_func_nb,
*args
)
Map each record to a single value.
map_func_nb
should accept a single record and *args
, and return a single value.
mapped_to_mask_nb function¶
mapped_to_mask_nb(
mapped_arr,
col_map,
inout_map_func_nb,
*args
)
Map mapped array to a mask per column.
Returns the same shape as mapped_arr
.
inout_map_func_nb
should accept the boolean array that should be written, indices of values, index of the column, values of the column, and *args
, and return nothing.
mapped_value_counts_nb function¶
mapped_value_counts_nb(
codes,
n_uniques,
col_map
)
Get value counts of an already factorized mapped array.
record_col_map_select_nb function¶
record_col_map_select_nb(
records,
col_map,
new_cols
)
Same as record_col_range_select_nb() but using column map col_map
.
record_col_range_select_nb function¶
record_col_range_select_nb(
records,
col_range,
new_cols
)
Perform indexing on sorted records using column range col_range
.
Returns new records.
reduce_mapped_nb function¶
reduce_mapped_nb(
mapped_arr,
col_map,
fill_value,
reduce_func_nb,
*args
)
Reduce mapped array by column to a single value.
Faster than expand_mapped_nb() and vbt.*
used together, and also requires less memory. But does not take advantage of caching.
reduce_func_nb
should accept index of the column, mapped array and *args
, and return a single value.
reduce_mapped_to_array_nb function¶
reduce_mapped_to_array_nb(
mapped_arr,
col_map,
fill_value,
reduce_func_nb,
*args
)
Reduce mapped array by column to an array.
reduce_func_nb
same as for reduce_mapped_nb() but should return an array.
reduce_mapped_to_idx_array_nb function¶
reduce_mapped_to_idx_array_nb(
mapped_arr,
col_map,
idx_arr,
fill_value,
reduce_func_nb,
*args
)
Reduce mapped array by column to an index array.
Same as reduce_mapped_to_array_nb() except idx_arr
should be passed.
Note
Must return integers or raise an exception.
reduce_mapped_to_idx_nb function¶
reduce_mapped_to_idx_nb(
mapped_arr,
col_map,
idx_arr,
fill_value,
reduce_func_nb,
*args
)
Reduce mapped array by column to an index.
Same as reduce_mapped_nb() except idx_arr
should be passed.
Note
Must return integers or raise an exception.
stack_expand_mapped_nb function¶
stack_expand_mapped_nb(
mapped_arr,
col_map,
fill_value
)
Expand mapped array by stacking without using index data.
top_n_inout_map_nb function¶
top_n_inout_map_nb(
inout,
idxs,
col,
mapped_arr,
n
)
inout_map_func_nb
that returns indices of top N elements.