A [WSGI](http://www.python.org/dev/peps/pep-0333/) application to calculate the the kernel, determinant and eigenvalues of a given matrix.
-Requires [SciPy](http://www.scipy.org/).
+Requires [SciPy](http://www.scipy.org/) and [NumPy](https://en.wikipedia.org/wiki/NumPy).
u, s, vh = svd(A)
return s
+def fail(start_response, message):
+ start_response('400 Bad Request', [])
+ return 'error: ' + message
+
def application(environ, start_response):
- parameters = cgi.parse_qs(environ.get('QUERY_STRING', ''))
+ parameters = cgi.parse_qs(environ.get('QUERY_STRING'))
+ if not 'matrix' in parameters or parameters['matrix'] == '':
+ return fail(start_response, 'missing matrix')
query_string = str(parameters['matrix'][0])
matrix = query_string.splitlines()
for index, row in enumerate(matrix):
matrix[index] = row.split()
+ if len(matrix[index]) != len(matrix[0]):
+ return fail(start_response, 'ragged matrix')
+ for index, n in enumerate(matrix[index]):
+ try: float(n)
+ except ValueError:
+ return fail(start_response, 'invalid matrix element')
while len(matrix) < len(matrix[0]):
matrix.append([0]*len(matrix[0]))