Swarm-SLAM  1.0.0
C-SLAM Framework
misc.py
Go to the documentation of this file.
1 """"
2 This file contains various utilitary functions
3 for basic number and list operations
4 """
5 
6 def clamp(num, min_value, max_value):
7  return max(min(num, max_value), min_value)
8 
9 def list_clamp(l, idx):
10  i = clamp(idx, 0, len(l)-1)
11  return l[i]
12 
13 def list_range(l, start):
14  s = clamp(start, 0, len(l)-1)
15  return [l[i] for i in range(s, len(l)-1)]
16 
17 def list_chunks(l, start, chunk_size):
18  s = clamp(start, 0, len(l)-1)
19  return [l[i:i+chunk_size] for i in range(s, len(l), chunk_size)]
20 
21 def dict_to_list_chunks(d, start, chunk_size):
22  chunks = []
23  tmp = []
24  for k in d.keys():
25  if k >= start:
26  tmp.append(d[k])
27  if len(tmp) == chunk_size:
28  chunks.append(tmp)
29  tmp = []
30  if len(tmp) > 0:
31  chunks.append(tmp)
32 
33  return chunks
def list_range(l, start)
Definition: misc.py:13
def dict_to_list_chunks(d, start, chunk_size)
Definition: misc.py:21
def list_clamp(l, idx)
Definition: misc.py:9
def list_chunks(l, start, chunk_size)
Definition: misc.py:17
def clamp(num, min_value, max_value)
Definition: misc.py:6