Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************
from numba import types
from sdc.str_ext import string_type
import llvmlite.binding as ll
from .. import hstr_ext
ll.add_symbol('array_setitem', hstr_ext.array_setitem)
ll.add_symbol('array_getptr1', hstr_ext.array_getptr1)
ll.add_symbol('dtor_str_arr_split_view', hstr_ext.dtor_str_arr_split_view)
ll.add_symbol('str_arr_split_view_impl', hstr_ext.str_arr_split_view_impl)
ll.add_symbol('str_arr_split_view_alloc', hstr_ext.str_arr_split_view_alloc)
# nested offset structure to represent S.str.split()
# data_offsets array includes offsets to character data array
# index_offsets array includes offsets to data_offsets array to identify lists
class StringArraySplitViewType(types.IterableType):
def __init__(self):
super(StringArraySplitViewType, self).__init__(
name='StringArraySplitViewType()')
@property
def dtype(self):
# TODO: optimized list type
return types.List(string_type)
ll.add_symbol('hpat_dist_exscan_i4', transport.hpat_dist_exscan_i4)
ll.add_symbol('hpat_dist_exscan_i8', transport.hpat_dist_exscan_i8)
ll.add_symbol('hpat_dist_exscan_f4', transport.hpat_dist_exscan_f4)
ll.add_symbol('hpat_dist_exscan_f8', transport.hpat_dist_exscan_f8)
ll.add_symbol('hpat_dist_irecv', transport.hpat_dist_irecv)
ll.add_symbol('hpat_dist_isend', transport.hpat_dist_isend)
ll.add_symbol('hpat_dist_wait', transport.hpat_dist_wait)
ll.add_symbol('allgather', transport.allgather)
ll.add_symbol('comm_req_alloc', transport.comm_req_alloc)
ll.add_symbol('comm_req_dealloc', transport.comm_req_dealloc)
ll.add_symbol('req_array_setitem', transport.req_array_setitem)
ll.add_symbol('hpat_dist_waitall', transport.hpat_dist_waitall)
ll.add_symbol('oneD_reshape_shuffle', transport.oneD_reshape_shuffle)
ll.add_symbol('permutation_int', transport.permutation_int)
ll.add_symbol('permutation_array_index', transport.permutation_array_index)
ll.add_symbol('hpat_finalize', transport.hpat_finalize)
# get size dynamically from C code
mpi_req_llvm_type = lir.IntType(8 * transport.mpi_req_num_bytes)
ll.add_symbol('hpat_dist_get_item_pointer', hdist.hpat_dist_get_item_pointer)
ll.add_symbol('hpat_get_dummy_ptr', hdist.hpat_get_dummy_ptr)
ll.add_symbol('hpat_dist_get_start', hdist.hpat_dist_get_start)
ll.add_symbol('hpat_dist_get_end', hdist.hpat_dist_get_end)
ll.add_symbol('hpat_dist_get_node_portion', hdist.hpat_dist_get_node_portion)
@lower_builtin(distributed_api.get_rank)
def dist_get_rank(context, builder, sig, args):
fnty = lir.FunctionType(lir.IntType(32), [])
fn = builder.module.get_or_insert_function(fnty, name="hpat_dist_get_rank")
return builder.call(fn, [])
# workqueue
lib, libname = select_from_backends(namedbackends)
if not lib:
# set requirements for hinting
requirements.append('TBB')
if _IS_OSX:
requirements.append('OSX_OMP')
else:
msg = "The threading layer requested '%s' is unknown to Numba."
raise ValueError(msg % t)
# No lib found, raise and hint
if not lib:
raise_with_hint(requirements)
ll.add_symbol('numba_parallel_for', lib.parallel_for)
ll.add_symbol('do_scheduling_signed', lib.do_scheduling_signed)
ll.add_symbol('do_scheduling_unsigned', lib.do_scheduling_unsigned)
launch_threads = CFUNCTYPE(None, c_int)(lib.launch_threads)
launch_threads(NUM_THREADS)
# set library name so it can be queried
global _threading_layer
_threading_layer = libname
_is_initialized = True
def _add_missing_symbol(symbol, addr):
"""Add missing symbol into LLVM internal symtab
"""
if not ll.address_of_symbol(symbol):
ll.add_symbol(symbol, addr)
def translate(self, clib, module):
logging.debug("Adding external function {0}".format(self.name))
f = getattr(clib, self.name)
llvm.add_symbol(self.name, ctypes.cast(f, ctypes.c_void_p).value)
llvm_arg_types = [arg.llvmType(module) for arg in self.type_.arg_types]
func_tp = ll.FunctionType(self.type_.return_type.llvmType(module), llvm_arg_types)
self.llvm = ll.Function(module, func_tp, self.name)
'multimap_int64_equal_range_alloc', multimap_int64_range_iterator_type())
multimap_int64_equal_range_dealloc = types.ExternalFunction(
'multimap_int64_equal_range_dealloc',
types.void(multimap_int64_range_iterator_type))
multimap_int64_equal_range_inplace = types.ExternalFunction(
'multimap_int64_equal_range_inplace',
multimap_int64_range_iterator_type(multimap_int64_type, types.int64,
multimap_int64_range_iterator_type))
ll.add_symbol('multimap_int64_init', hdict_ext.multimap_int64_init)
ll.add_symbol('multimap_int64_insert', hdict_ext.multimap_int64_insert)
ll.add_symbol('multimap_int64_equal_range', hdict_ext.multimap_int64_equal_range)
ll.add_symbol('multimap_int64_equal_range_alloc', hdict_ext.multimap_int64_equal_range_alloc)
ll.add_symbol('multimap_int64_equal_range_dealloc', hdict_ext.multimap_int64_equal_range_dealloc)
ll.add_symbol('multimap_int64_equal_range_inplace', hdict_ext.multimap_int64_equal_range_inplace)
ll.add_symbol('multimap_int64_it_is_valid', hdict_ext.multimap_int64_it_is_valid)
ll.add_symbol('multimap_int64_it_get_value', hdict_ext.multimap_int64_it_get_value)
ll.add_symbol('multimap_int64_it_inc', hdict_ext.multimap_int64_it_inc)
@lower_builtin('getiter', MultiMapRangeIteratorType)
def iterator_getiter(context, builder, sig, args):
it, = args
# return impl_ret_borrowed(context, builder, sig.return_type, it)
return it
@lower_builtin('iternext', MultiMapRangeIteratorType)
@iternext_impl(RefType.UNTRACKED)
def iternext_listiter(context, builder, sig, args, result):
ll.add_symbol('str_compare', hstr_ext.str_compare)
ll.add_symbol('str_equal', hstr_ext.str_equal)
ll.add_symbol('str_equal_cstr', hstr_ext.str_equal_cstr)
ll.add_symbol('str_split', hstr_ext.str_split)
ll.add_symbol('str_substr_int', hstr_ext.str_substr_int)
ll.add_symbol('str_to_int64', hstr_ext.str_to_int64)
ll.add_symbol('std_str_to_int64', hstr_ext.std_str_to_int64)
ll.add_symbol('str_to_float64', hstr_ext.str_to_float64)
ll.add_symbol('get_str_len', hstr_ext.get_str_len)
ll.add_symbol('compile_regex', hstr_ext.compile_regex)
ll.add_symbol('str_contains_regex', hstr_ext.str_contains_regex)
ll.add_symbol('str_contains_noregex', hstr_ext.str_contains_noregex)
ll.add_symbol('str_replace_regex', hstr_ext.str_replace_regex)
ll.add_symbol('str_from_int32', hstr_ext.str_from_int32)
ll.add_symbol('str_from_int64', hstr_ext.str_from_int64)
ll.add_symbol('str_from_float32', hstr_ext.str_from_float32)
ll.add_symbol('str_from_float64', hstr_ext.str_from_float64)
get_std_str_len = types.ExternalFunction(
"get_str_len", signature(types.intp, std_str_type))
init_string_from_chars = types.ExternalFunction(
"init_string_const", std_str_type(types.voidptr, types.intp))
_str_to_int64 = types.ExternalFunction(
"str_to_int64", signature(types.intp, types.voidptr, types.intp))
str_replace_regex = types.ExternalFunction(
"str_replace_regex", std_str_type(std_str_type, regex_type, std_str_type))
def gen_unicode_to_std_str(context, builder, unicode_val):
#
return signature(types.boolean, *unliteral_all(args))
ll.add_symbol('init_string', hstr_ext.init_string)
ll.add_symbol('init_string_const', hstr_ext.init_string_const)
ll.add_symbol('get_c_str', hstr_ext.get_c_str)
ll.add_symbol('str_concat', hstr_ext.str_concat)
ll.add_symbol('str_compare', hstr_ext.str_compare)
ll.add_symbol('str_equal', hstr_ext.str_equal)
ll.add_symbol('str_equal_cstr', hstr_ext.str_equal_cstr)
ll.add_symbol('str_split', hstr_ext.str_split)
ll.add_symbol('str_substr_int', hstr_ext.str_substr_int)
ll.add_symbol('str_to_int64', hstr_ext.str_to_int64)
ll.add_symbol('std_str_to_int64', hstr_ext.std_str_to_int64)
ll.add_symbol('str_to_float64', hstr_ext.str_to_float64)
ll.add_symbol('get_str_len', hstr_ext.get_str_len)
ll.add_symbol('compile_regex', hstr_ext.compile_regex)
ll.add_symbol('str_contains_regex', hstr_ext.str_contains_regex)
ll.add_symbol('str_contains_noregex', hstr_ext.str_contains_noregex)
ll.add_symbol('str_replace_regex', hstr_ext.str_replace_regex)
ll.add_symbol('str_from_int32', hstr_ext.str_from_int32)
ll.add_symbol('str_from_int64', hstr_ext.str_from_int64)
ll.add_symbol('str_from_float32', hstr_ext.str_from_float32)
ll.add_symbol('str_from_float64', hstr_ext.str_from_float64)
get_std_str_len = types.ExternalFunction(
"get_str_len", signature(types.intp, std_str_type))
init_string_from_chars = types.ExternalFunction(
"init_string_const", std_str_type(types.voidptr, types.intp))
_str_to_int64 = types.ExternalFunction(
"str_to_int64", signature(types.intp, types.voidptr, types.intp))
# string_array = cgutils.create_struct_proxy(typ)(context, builder)
# string_array.offsets = offsets
# string_array.data = data
# return string_array._getvalue()
@overload(len)
def str_arr_len_overload(str_arr):
if is_str_arr_typ(str_arr):
def str_arr_len(str_arr):
return str_arr.size
return str_arr_len
ll.add_symbol('get_str_len', hstr_ext.get_str_len)
ll.add_symbol('allocate_string_array', hstr_ext.allocate_string_array)
ll.add_symbol('setitem_string_array', hstr_ext.setitem_string_array)
ll.add_symbol('getitem_string_array', hstr_ext.getitem_string_array)
ll.add_symbol('getitem_string_array_std', hstr_ext.getitem_string_array_std)
ll.add_symbol('is_na', hstr_ext.is_na)
ll.add_symbol('string_array_from_sequence', hstr_ext.string_array_from_sequence)
ll.add_symbol('np_array_from_string_array', hstr_ext.np_array_from_string_array)
ll.add_symbol('print_int', hstr_ext.print_int)
ll.add_symbol('convert_len_arr_to_offset', hstr_ext.convert_len_arr_to_offset)
ll.add_symbol('set_string_array_range', hstr_ext.set_string_array_range)
ll.add_symbol('str_arr_to_int64', hstr_ext.str_arr_to_int64)
ll.add_symbol('str_arr_to_float64', hstr_ext.str_arr_to_float64)
ll.add_symbol('dtor_string_array', hstr_ext.dtor_string_array)
ll.add_symbol('c_glob', hstr_ext.c_glob)
ll.add_symbol('decode_utf8', hstr_ext.decode_utf8)
ll.add_symbol('get_utf8_size', hstr_ext.get_utf8_size)
# string_array.data = data
# return string_array._getvalue()
@overload(len)
def str_arr_len_overload(str_arr):
if is_str_arr_typ(str_arr):
def str_arr_len(str_arr):
return str_arr.size
return str_arr_len
ll.add_symbol('get_str_len', hstr_ext.get_str_len)
ll.add_symbol('allocate_string_array', hstr_ext.allocate_string_array)
ll.add_symbol('setitem_string_array', hstr_ext.setitem_string_array)
ll.add_symbol('getitem_string_array', hstr_ext.getitem_string_array)
ll.add_symbol('getitem_string_array_std', hstr_ext.getitem_string_array_std)
ll.add_symbol('is_na', hstr_ext.is_na)
ll.add_symbol('string_array_from_sequence', hstr_ext.string_array_from_sequence)
ll.add_symbol('np_array_from_string_array', hstr_ext.np_array_from_string_array)
ll.add_symbol('print_int', hstr_ext.print_int)
ll.add_symbol('convert_len_arr_to_offset', hstr_ext.convert_len_arr_to_offset)
ll.add_symbol('set_string_array_range', hstr_ext.set_string_array_range)
ll.add_symbol('str_arr_to_int64', hstr_ext.str_arr_to_int64)
ll.add_symbol('str_arr_to_float64', hstr_ext.str_arr_to_float64)
ll.add_symbol('dtor_string_array', hstr_ext.dtor_string_array)
ll.add_symbol('c_glob', hstr_ext.c_glob)
ll.add_symbol('decode_utf8', hstr_ext.decode_utf8)
ll.add_symbol('get_utf8_size', hstr_ext.get_utf8_size)
convert_len_arr_to_offset = types.ExternalFunction("convert_len_arr_to_offset", types.void(types.voidptr, types.intp))