disinclined.org
/
git
/
matrixnullspace.com.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7a41639
)
add error handling & numpy to readme
master
author
Dylan Lloyd
<dylan@dylansserver.com>
Sun, 14 Jul 2013 09:40:13 +0000
(09:40 +0000)
committer
Dylan Lloyd
<dylan@dylansserver.com>
Sun, 14 Jul 2013 09:40:13 +0000
(09:40 +0000)
README.md
patch
|
blob
|
history
matrix.py
patch
|
blob
|
history
diff --git
a/README.md
b/README.md
index
5911843
..
8daf28c
100644
(file)
--- a/
README.md
+++ b/
README.md
@@
-3,4
+3,4
@@
matrixnullspace.com
A [WSGI](http://www.python.org/dev/peps/pep-0333/) application to calculate the the kernel, determinant and eigenvalues of a given matrix.
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)
.
diff --git
a/matrix.py
b/matrix.py
index
41713e2
..
f7da2d7
100755
(executable)
--- a/
matrix.py
+++ b/
matrix.py
@@
-13,13
+13,25
@@
def calculate_eigenvalues(A, eps=1e-15):
u, s, vh = svd(A)
return s
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):
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()
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]))
while len(matrix) < len(matrix[0]):
matrix.append([0]*len(matrix[0]))