Beispiel #1
0
    def process(self):

        self.ensure_enums_have_no_space(enums=["current_op"])

        inputs, outputs = self.inputs, self.outputs

        if not outputs[0].is_linked:
            return

        func = self.implementation_func_dict[self.implementation][0].get(
            self.current_op)[1]
        num_inputs = len(inputs)

        # get either input data, or socket default
        input_one = inputs[0].sv_get(deepcopy=True)

        level = levels_of_list_or_np(input_one) - 1
        if num_inputs == 1:
            recurse_func = self.implementation_func_dict[
                self.implementation][1]
            params = [input_one, func, level]
            # result = recurse_func(input_one, func, level, self.output_numpy)
        else:
            input_two = inputs[1].sv_get(deepcopy=True)
            level = max(level, levels_of_list_or_np(input_two) - 1)
            min_l2_level = 3 if inputs[1].bl_idname == "SvVerticesSocket" else 2
            params = [input_one, input_two, func, level, min_l2_level]
            recurse_func = self.implementation_func_dict[
                self.implementation][2]

        if self.implementation == 'NumPy':
            params.append(self.output_numpy)
        result = recurse_func(*params)
        outputs[0].sv_set(result)
    def process(self):
        inputs, outputs = self.inputs, self.outputs

        if not outputs[0].is_linked:
            return

        func = self.implementation_func_dict[self.implementation][0].get(
            self.current_op)[1]
        num_inputs = len(inputs)

        # get either input data, or socket default
        input_one = inputs[0].sv_get(deepcopy=True)

        # level = levelsOflist(input_one) - 1
        level = levels_of_list_or_np(input_one) - 1
        if num_inputs == 1:
            recurse_func = self.implementation_func_dict[
                self.implementation][1]
            params = [input_one, func, level]
            # result = recurse_func(input_one, func, level, self.output_numpy)
        else:
            input_two = inputs[1].sv_get(deepcopy=True)
            level = max(level, levels_of_list_or_np(input_two) - 1)
            params = [input_one, input_two, func, level]
            recurse_func = self.implementation_func_dict[
                self.implementation][2]

        if self.implementation == 'NumPy':
            params.append(self.output_numpy)
        result = recurse_func(*params)
        outputs[0].sv_set(result)
Beispiel #3
0
    def process(self):

        if not self.outputs['data'].links:
            return

        slots = []
        for socket in self.inputs:
            if socket.is_linked and socket.links:
                slots.append(socket.sv_get(deepcopy=False))
        if len(slots) == 0:
            return
        if self.match_and_join:
            match_func = list_match_func[self.list_match]
            if self.mix_check:
                result = match_and_join_mix(slots, self.JoinLevel,
                                            self.wrap_check, match_func)
            else:
                result = match_and_join(slots, self.JoinLevel, self.wrap_check,
                                        match_func)
        else:
            if self.numpy_mode:
                if self.outputs[0].bl_idname == 'SvVerticesSocket':
                    min_axis = 2
                else:
                    min_axis = 1
                depth = levels_of_list_or_np(slots[0])
                true_depth = depth - min_axis
                result = numpy_join(slots, self.JoinLevel, self.mix_check,
                                    true_depth)
            else:
                result = python_join(slots, self.JoinLevel, self.mix_check,
                                     self.wrap_check)

        self.outputs[0].sv_set(result)
Beispiel #4
0
def process_matched(params, main_func, matching_mode, input_nesting, outputs_num):
    '''params will spread using the matching fmode,
       the main_func is the function to apply
       the input_nesting should be like an Integer List like [1, 2, 1, 3...] one level per parameter
       outputs_num: number of outputs (Integer)
       '''
    input_levels = [levels_of_list_or_np(p) for p in params]

    over_levels = [lv > dl for lv, dl in zip(input_levels, input_nesting)]
    one_output = outputs_num == 1
    matching_f = list_match_func[matching_mode]
    if one_output:
        result = []
    else:
        result = [[] for l in range(outputs_num)]
    if any(over_levels):
        p_temp = []
        for p, lv, dl in zip(params, input_levels, input_nesting):

            if lv <= dl:
                p_temp.append([p])
            else:
                p_temp.append(p)

        params = matching_f(p_temp)
        for g in zip(*params):
            local_result = process_matched(g, main_func, matching_mode, input_nesting, outputs_num)
            append_result(result, local_result, one_output)

    else:
        result = main_func(matching_f(params))

    return result
Beispiel #5
0
def recurse_f_level_control(params,
                            constant,
                            main_func,
                            matching_f,
                            desired_levels,
                            concatenate="APPEND"):
    '''params will spread using the matching function (matching_f), the const is a constant
        parameter that you dont want to spread , the main_func is the function to apply
        and the desired_levels should be like [1, 2, 1, 3...] one level per parameter'''
    input_levels = [levels_of_list_or_np(p) for p in params]
    over_levels = [lv > dl for lv, dl in zip(input_levels, desired_levels)]
    if any(over_levels):
        p_temp = []
        result = []
        result_add = result.extend if concatenate == 'EXTEND' else result.append
        for p, lv, dl in zip(params, input_levels, desired_levels):
            if lv <= dl:
                p_temp.append([p])
            else:
                p_temp.append(p)
        params = matching_f(p_temp)
        for g in zip(*params):
            result_add(
                recurse_f_level_control(matching_f(g),
                                        constant,
                                        main_func,
                                        matching_f,
                                        desired_levels,
                                        concatenate=concatenate))
    else:
        result = main_func(params, constant, matching_f)
    return result
Beispiel #6
0
def recurse_fxy_numpy(l1, l2, func, level, min_l2_level, out_numpy):
    if level == 1:
        nl1 = np.array(l1)
        nl2 = np.array(l2)
        nl1, nl2 = numpy_match_long_repeat([nl1, nl2])
        res = func(nl1, nl2) if out_numpy else func(nl1, nl2).tolist()
        return res
    else:
        res = []
        res_append = res.append
        if levels_of_list_or_np([l1]) < 4:
            l1 = [l1]
        if levels_of_list_or_np([l2]) < min_l2_level+1:
            l2 = [l2]
        # will only be used if lists are of unequal length
        fl = l2[-1] if len(l1) > len(l2) else l1[-1]
        for u, v in zip_longest(l1, l2, fillvalue=fl):
            res_append(recurse_fxy_numpy(u, v, func, level-1, min_l2_level, out_numpy))
        return res
Beispiel #7
0
 def what_is_next(self):
     if self._stack[-1] is DataWalker.EXIT_VALUE:
         return DataWalker.END
     if isinstance(self._stack[-1], (list, tuple, np.ndarray)):
         nesting = levels_of_list_or_np(self._stack[-1])
     else:
         nesting = 0
     if nesting == self._output_nesting:
         return DataWalker.VALUE
     else:  # todo add the case when next element has too less nested levels
         return DataWalker.SUB_TREE
Beispiel #8
0
    def process(self):
        if not (self.inputs['Vectors'].is_linked
                and any(s.is_linked for s in self.outputs)):
            return

        vectors = self.inputs['Vectors'].sv_get(deepcopy=False)

        if self.correct_output == 'FLAT':
            data = dataCorrect_np(vectors)
            xyz = unpack(data, self.output_numpy)
        else:
            input_level = levels_of_list_or_np(vectors)
            xyz = unpack_multilevel(vectors, input_level, self.output_numpy)

        for i, name in enumerate(['X', 'Y', 'Z']):
            if self.outputs[name].is_linked:
                self.outputs[name].sv_set(xyz[i])
Beispiel #9
0
def format_to_text(data):
    deptl = levels_of_list_or_np(data)
    out = ''
    if deptl > 1:
        for i, sub_data in enumerate(data):
            if i > 0:
                out += '\n'
            sub_data_len = len(sub_data) - 1
            for i, d in enumerate(sub_data):
                out += str(d)
                if i < sub_data_len:
                    out += '\n'

    else:
        for d in data:
            out += str(d) + '\n'
    return out
Beispiel #10
0
    def process(self):

        if self.outputs[0].is_linked:
            current_func = func_from_mode(self.current_op)
            params = [
                si.sv_get(default=[[]], deepcopy=False) for si in self.inputs
            ]
            matching_f = list_match_func[self.list_match]
            desired_levels = [2 if self.current_op == 'join_all' else 1
                              ] * len(params)
            inputs_signature = self.sockets_signature.split(' ')[0]
            ops = [current_func, inputs_signature]
            if self.current_op == 'to_string':
                depth = levels_of_list_or_np(params[0])
                desired_levels = [max(depth - self.level + 1, 1)]
            result = recurse_f_level_control(params, ops, string_tools,
                                             matching_f, desired_levels)

            self.outputs[0].sv_set(result)
Beispiel #11
0
    def process(self):
        if self.inputs['Data'].is_linked:
            data = self.inputs['Data'].sv_get(deepcopy=False)

            # blocking too height values of levels, reduce
            levels = levels_of_list_or_np(data)-1
            if levels >= self.level:
                levels = self.level-1
            elif levels < 1:
                levels = 1
            # assign out
            if self.outputs['First'].is_linked:
                out = self.count(data, levels, 0)
                self.outputs['First'].sv_set(out)
            if self.outputs['Middl'].is_linked:
                out = self.count(data, levels, 1)
                self.outputs['Middl'].sv_set(out)
            if self.outputs['Last'].is_linked:
                out = self.count(data, levels, 2)
                self.outputs['Last'].sv_set(out)