[Swift-commit] r8104 - SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Tue Aug 12 11:56:24 CDT 2014


Author: wozniak
Date: 2014-08-12 11:56:24 -0500 (Tue, 12 Aug 2014)
New Revision: 8104

Added:
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/numpy.swift
   SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/run-local.sh
Log:
Working Python example


Added: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/numpy.swift
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/numpy.swift	                        (rev 0)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/numpy.swift	2014-08-12 16:56:24 UTC (rev 8104)
@@ -0,0 +1,43 @@
+
+import io;
+import python;
+import string;
+
+f()
+{
+  python(
+----    
+print("Python works!")
+repr(0)
+----);
+}
+
+global const string numpy = "from numpy import *\n\n";
+
+typedef matrix string;
+
+(matrix A) eye(int n)
+{
+  string command = sprintf("repr(eye(%i))", n);
+  string code = numpy+command;
+  matrix t = python(code);
+  A = replace_all(t, "\n", "", 0);
+}
+
+(matrix R) add(matrix A1, matrix A2)
+{
+  string command = sprintf("repr(%s+%s)", A1, A2);
+  string code = numpy+command;
+  matrix t = python(code);
+  R = replace_all(t, "\n", "", 0);
+}
+
+main
+{
+  f();
+  matrix A1 = eye(3);
+  matrix A2 = eye(3);
+  matrix sum = add(A1, A2);
+  printf("2*eye(3)=%s", sum);
+}
+

Copied: SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/run-local.sh (from rev 8102, SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/03-blas/run-local.sh)
===================================================================
--- SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/run-local.sh	                        (rev 0)
+++ SwiftTutorials/ATPESC_2014-08-14/swift-t/examples/04-py/run-local.sh	2014-08-12 16:56:24 UTC (rev 8104)
@@ -0,0 +1,7 @@
+#!/bin/bash -eu
+
+source ../../cfg/setup-local.sh
+
+PROGRAM=numpy
+stc     ${PROGRAM}.swift
+turbine ${PROGRAM}.tcl




More information about the Swift-commit mailing list