Exemplo n.º 1
0
 def cp_str_list_impl(str_arr, str_list):
     n = len(str_list)
     for i in range(n):
         _str = str_list[i]
         setitem_string_array(get_offset_ptr(str_arr),
                              get_data_ptr(str_arr), _str, i)
         del_str(_str)
Exemplo n.º 2
0
 def str_list_impl(str_list):
     n = len(str_list)
     n_char = 0
     for i in range(n):
         _str = str_list[i]
         n_char += len(_str)
     str_arr = pre_alloc_string_array(n, n_char)
     for i in range(n):
         _str = str_list[i]
         setitem_string_array(get_offset_ptr(str_arr),
                              get_data_ptr(str_arr), _str, i)
         del_str(_str)  # XXX assuming str list is not used anymore
     return str_arr
Exemplo n.º 3
0
    def str_arr_arr_impl(str_arr, ind_arr):
        n = len(ind_arr)
        # get lengths
        n_strs = 0
        n_chars = 0
        for i in range(n):
            # TODO: use get_cstr_and_len instead of getitem
            _str = str_arr[ind_arr[i]]
            n_strs += 1
            n_chars += len(_str)
            del_str(_str)

        out_arr = pre_alloc_string_array(n_strs, n_chars)
        str_ind = 0
        for i in range(n):
            _str = str_arr[ind_arr[i]]
            setitem_string_array(get_offset_ptr(out_arr),
                                 get_data_ptr(out_arr), _str, str_ind)
            str_ind += 1
            del_str(_str)
        return out_arr
Exemplo n.º 4
0
 def str_arr_bool_impl(str_arr, bool_arr):
     n = len(str_arr)
     if n != len(bool_arr):
         raise IndexError(
             "boolean index did not match indexed array along dimension 0")
     n_strs = 0
     n_chars = 0
     for i in range(n):
         if bool_arr[i] == True:
             # TODO: use get_cstr_and_len instead of getitem
             str = str_arr[i]
             n_strs += 1
             n_chars += len(str)
             del_str(str)
     out_arr = pre_alloc_string_array(n_strs, n_chars)
     str_ind = 0
     for i in range(n):
         if bool_arr[i] == True:
             str = str_arr[i]
             setitem_string_array(get_offset_ptr(out_arr),
                                  get_data_ptr(out_arr), str, str_ind)
             str_ind += 1
             del_str(str)
     return out_arr