5 from __future__
import print_function
11 from .wrap
import SignalBase
12 from .wrap
import create_signal_wrapper
as SignalWrapper
17 Transform a string of format '[n](x_1,x_2,...,x_n)' into a tuple of numbers. 20 a = re.match(
r"\[(\d+)\]", vector)
21 size = int(a.group(1))
23 vector = vector[len(a.group(0)) :]
25 vector = vector.lstrip(
"(").rstrip(
")\n")
27 vector = vector.split(
",")
29 if len(vector) != size:
33 +
" of vector does not fit actual size: " 36 res = map(float, vector)
42 Transform a tuple of numbers into a string of format 43 '[n](x_1, x_2, ..., x_n)' 45 string =
"[%d](" % len(vector)
48 string +=
"%f)" % vector[-1]
54 Transform a string of format 55 '[n,m]((x_11,x_12,...,x_1m),...,(x_n1,x_n2,...,x_nm))' into a tuple 59 a = re.search(
r"\[(\d+),(\d+)]", string)
60 nRows = int(a.group(1))
61 nCols = int(a.group(2))
63 string = string[len(a.group(0)) :]
64 rows = string.split(
"),(")
65 if len(rows) != nRows:
69 +
" of matrix does not fit actual nb rows: " 74 rstr = rstr.lstrip(
"(").rstrip(
")\n")
75 r = map(float, rstr.split(
","))
80 +
" of matrix does not fit displayed nb cols: " 89 Transform a tuple of tuple of numbers into a string of format 90 '[n,m]((x_11,x_12,...,x_1m),...,(x_n1,x_n2,...,x_nm))'. 95 nCols = len(matrix[0])
96 string =
"[%d,%d](" % (nRows, nCols)
97 for r
in range(nRows):
99 for c
in range(nCols):
100 string += str(float(matrix[r][c]))
112 Transform an object to a string. Object is either 113 - an entity (more precisely a sub-class named Feature) 116 - a floating point number, 120 if hasattr(obj,
"__iter__"):
125 if hasattr(obj[0],
"__iter__"):
131 elif hasattr(obj,
"name"):
139 Convert a string into one of the following types 140 - a matrix (tuple of tuple), 143 - a floating point number. 144 Successively attempts conversion in the above order and return 145 on success. If no conversion fits, the string is returned. 147 if isinstance(string, float):
149 if isinstance(string, int):
151 if isinstance(string, tuple):
def matrixToString(matrix)
def stringToMatrix(string)
def stringToTuple(vector)
def stringToObject(string)
def tupleToString(vector)