Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0b17a5

Browse filesBrowse files
author
Bill Prin
committed
Add numpy Flexible example
1 parent 2d783c4 commit f0b17a5
Copy full SHA for f0b17a5

File tree

Expand file treeCollapse file tree

5 files changed

+83
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+83
-0
lines changed

‎appengine/flexible/numpy/app.yaml

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
runtime: python
2+
vm: true
3+
entrypoint: gunicorn -b :$PORT main:app
4+
5+
runtime_config:
6+
python_version: 3

‎appengine/flexible/numpy/main.py

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import logging
16+
17+
from flask import Flask
18+
import numpy as np
19+
20+
app = Flask(__name__)
21+
22+
23+
# [START numpy]
24+
@app.route('/')
25+
def calculate():
26+
return_str = ''
27+
x = np.array([[1, 2], [3, 4]])
28+
y = np.array([[5, 6], [7, 8]])
29+
30+
return_str += 'x: {} , y: {}<br />'.format(str(x), str(y))
31+
32+
# Multiply matrices
33+
return_str += 'x dot y : {}'.format(str(np.dot(x, y)))
34+
return return_str
35+
# [END numpy]
36+
37+
38+
@app.errorhandler(500)
39+
def server_error(e):
40+
logging.exception('An error occurred during a request.')
41+
return """
42+
An internal error occurred: <pre>{}</pre>
43+
See logs for full stacktrace.
44+
""".format(e), 500
45+
46+
if __name__ == '__main__':
47+
# This is used when running locally. Gunicorn is used to run the
48+
# application on Google App Engine. See entrypoint in app.yaml.
49+
app.run(host='127.0.0.1', port=8080, debug=True)

‎appengine/flexible/numpy/main_test.py

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_index():
19+
main.app.testing = True
20+
client = main.app.test_client()
21+
22+
r = client.get('/')
23+
assert r.status_code == 200
24+
assert '[[19 22]\n [43 50]]' in r.data.decode('utf-8')
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==0.11.1
2+
gunicorn==19.6.0
3+
numpy==1.11.1

‎requirements-dev.txt

Copy file name to clipboardExpand all lines: requirements-dev.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mailjet-rest==v1.2.2
2222
mock==2.0.0
2323
mysql-python==1.2.5; python_version == '2.7'
2424
mysqlclient==1.3.7
25+
numpy==1.11.1
2526
oauth2client==3.0.0
2627
Pillow==3.3.0
2728
pyasn1-modules==0.0.8

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.