This utility function is used to parse, as matrices of integers, strings returned by the Kreuzer-Skarke database. As an example,
i1 : str = " 1 0 0 0 0 1 2 1 0 -2 0 -2 0 1 0 0 0 0 -2 -1 1 2 -1 0 0 0 1 0 0 -1 0 -1 -1 1 -1 1 0 0 0 1 -1 0 1 1 -1 0 1 -2 " o1 = 1 0 0 0 0 1 2 1 0 -2 0 -2 0 1 0 0 0 0 -2 -1 1 2 -1 0 0 0 1 0 0 -1 0 -1 -1 1 -1 1 0 0 0 1 -1 0 1 1 -1 0 1 -2 |
i2 : A = matrixFromString str o2 = | 1 0 0 0 0 1 2 1 0 -2 0 -2 | | 0 1 0 0 0 0 -2 -1 1 2 -1 0 | | 0 0 1 0 0 -1 0 -1 -1 1 -1 1 | | 0 0 0 1 -1 0 1 1 -1 0 1 -2 | 4 12 o2 : Matrix ZZ <--- ZZ |
The actual format allowed is the following: Spaces, tabs, and commas are all separators for elements of the array. Newlines, and ] characters separate rows. Finally, each empty line is ignored, and the remaining lines must all have the same number of elements.
As another example, matrices coming from Sage often use square brackets, and can be read using this function.
i3 : str = "[[1, -1, -1, 1, -1, -1, -1, 1, 1, 0], [0, 1, 0, -1, 1, 0, 0, -1, -1, 0], [-1, 0, 0, 0, 1, 1, 0, 0, 0, 0], [2, 0, 0, 1, -1, -1, -1, -1, 0, 0]]" o3 = [[1, -1, -1, 1, -1, -1, -1, 1, 1, 0], [0, 1, 0, -1, 1, 0, 0, -1, -1, 0], [-1, 0, 0, 0, 1, 1, 0, 0, 0, 0], [2, 0, 0, 1, -1, -1, -1, -1, 0, 0]] |
i4 : matrixFromString str o4 = | 1 -1 -1 1 -1 -1 -1 1 1 0 | | 0 1 0 -1 1 0 0 -1 -1 0 | | -1 0 0 0 1 1 0 0 0 0 | | 2 0 0 1 -1 -1 -1 -1 0 0 | 4 10 o4 : Matrix ZZ <--- ZZ |
Formatting of white space is generally not important, except that each row must be on one line, and if there are several on a line, each row is ended by a ].
i5 : str = " [ [1, -1, -1, 1, -1, -1, -1, 1, 1, 0], [0, 1, 0, -1, 1, 0, 0, -1, -1, 0], [-1, 0, 0, 0, 1, 1, 0, 0, 0, 0], [2, 0, 0, 1, -1, -1, -1, -1, 0, 0] ] " o5 = [ [1, -1, -1, 1, -1, -1, -1, 1, 1, 0], [0, 1, 0, -1, 1, 0, 0, -1, -1, 0], [-1, 0, 0, 0, 1, 1, 0, 0, 0, 0], [2, 0, 0, 1, -1, -1, -1, -1, 0, 0] ] |
i6 : matrixFromString str o6 = | 1 -1 -1 1 -1 -1 -1 1 1 0 | | 0 1 0 -1 1 0 0 -1 -1 0 | | -1 0 0 0 1 1 0 0 0 0 | | 2 0 0 1 -1 -1 -1 -1 0 0 | 4 10 o6 : Matrix ZZ <--- ZZ |
The object matrixFromString is a method function.