def from_string(value, zerofillers=None, onefillers=None, row_sep=';'):
    """Make Matrix object from string `value`."""
    if not value:
        return Matrix()
    try:
        row_str_list = [lex for lex in value.split(row_sep) if lex != '']
    except AttributeError:
        raise TypeError('expected `value` is string, but got '
                        '{}'.format(type(value)))
    return Matrix((vector.from_string(
        row, onefillers=onefillers, zerofillers=zerofillers).value
                   for row in row_str_list), max(len(s) for s in row_str_list))
 def __make_row_from_value(self, value):
     """Make row from value of various type."""
     try:
         value = value.value
         new_row = vector.Vector(value, self._ncolumns)
     except AttributeError:
         if isinstance(value, int):
             new_row = vector.Vector(value, self._ncolumns)
         elif isinstance(value, str):
             new_row = vector.from_string(value)
             new_row.set_length(self._ncolumns)
         else:
             new_row = vector.from_iterable(value)
             new_row.set_length(self._ncolumns)
     return new_row
Example #3
0
 def test_make_vector_from_string(self):
     """Test make vector from string."""
     vec = vector.from_string('*1&11-0110|*1-',
                              onefillers='&|',
                              zerofillers='*-')
     self.assertEqual(int(vec), 0b01111001101010)