[Swift-commit] r6736 - in SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r: . code
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Sun Aug 4 10:04:10 CDT 2013
Author: wozniak
Date: 2013-08-04 10:04:10 -0500 (Sun, 04 Aug 2013)
New Revision: 6736
Added:
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.py
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.swift
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/numpy.swift
Removed:
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.py
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.swift
SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/numpy.swift
Log:
Move code to code/
Copied: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.py (from rev 6734, SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.py)
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.py (rev 0)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.py 2013-08-04 15:04:10 UTC (rev 6736)
@@ -0,0 +1,24 @@
+
+from numpy import *
+
+N = 3
+U = 7
+
+s = repr(eye(3))
+print(eval(s)*2)
+
+dets = zeros(U-1)
+
+for i in range(1,U):
+ A = ones(N)
+ A = A + i*eye(N)
+ A[2,0] = (U-i+1)**3
+ print(A)
+ d = linalg.det(A)
+ print(d)
+ dets[i-1] = abs(d)
+ print
+
+print(dets)
+print(max(dets))
+
Copied: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.swift (from rev 6734, SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.swift)
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.swift (rev 0)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/dets.swift 2013-08-04 15:04:10 UTC (rev 6736)
@@ -0,0 +1,32 @@
+
+import io;
+import math;
+import python;
+import string;
+import R;
+
+import numpy;
+
+global const int N = 3;
+global const int U = 7;
+
+main
+{
+ // Define our collection of determinants:
+ float dets[];
+ foreach i in [1:U-1]
+ {
+ // For U, i, construct a matrix via Numpy:
+ A = matrix_add(matrix_scale(eye(N), itof(i)), ones(N));
+ B = matrix_set(A, 2, 0, (U-i+1)**3);
+ // Obtain its determinant via Numpy:
+ v = determinant(B);
+ // Store the determinant in a Swift array:
+ dets[i] = abs_float(v);
+ }
+
+ // Build a fragment of R code with the dets:
+ code = sprintf("max(%s)", string_from_floats(dets));
+ r = R(code);
+ printf("max: %f", r);
+}
Copied: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/numpy.swift (from rev 6734, SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/numpy.swift)
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/numpy.swift (rev 0)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/code/numpy.swift 2013-08-04 15:04:10 UTC (rev 6736)
@@ -0,0 +1,58 @@
+
+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 A) ones(int n)
+{
+ string command = sprintf("repr(ones(%i))", n);
+ string code = numpy+command;
+ matrix t = python(code);
+ A = replace_all(t, "\n", "", 0);
+}
+
+(matrix M) matrix_scale(matrix A, float s)
+{
+ string command = sprintf("repr(%s*%s)", A, s);
+ string code = numpy+command;
+ matrix t = python(code);
+ M = replace_all(t, "\n", "", 0);
+}
+
+(matrix M) matrix_set(matrix A, int row, int column, float s)
+{
+ string fragment =
+ """
+A = %s
+A[%i,%i] = %f
+repr(A)
+""";
+ string command = sprintf(fragment, A, row, column, s);
+ string code = numpy+command;
+ matrix t = python(code);
+ M = replace_all(t, "\n", "", 0);
+}
+
+(matrix M) matrix_add(matrix A1, matrix A2)
+{
+ string command = sprintf("repr(%s+%s)", A1, A2);
+ string code = numpy+command;
+ matrix t = python(code);
+ M = replace_all(t, "\n", "", 0);
+}
+
+(float d) determinant(matrix A)
+{
+ string command = sprintf("repr(linalg.det(%s))", A);
+ string code = numpy+command;
+ string t = python(code);
+ d = tofloat(t);
+}
Deleted: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.py
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.py 2013-08-04 15:02:08 UTC (rev 6735)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.py 2013-08-04 15:04:10 UTC (rev 6736)
@@ -1,24 +0,0 @@
-
-from numpy import *
-
-N = 3
-U = 7
-
-s = repr(eye(3))
-print(eval(s)*2)
-
-dets = zeros(U-1)
-
-for i in range(1,U):
- A = ones(N)
- A = A + i*eye(N)
- A[2,0] = (U-i+1)**3
- print(A)
- d = linalg.det(A)
- print(d)
- dets[i-1] = abs(d)
- print
-
-print(dets)
-print(max(dets))
-
Deleted: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.swift
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.swift 2013-08-04 15:02:08 UTC (rev 6735)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/dets.swift 2013-08-04 15:04:10 UTC (rev 6736)
@@ -1,32 +0,0 @@
-
-import io;
-import math;
-import python;
-import string;
-import R;
-
-import numpy;
-
-global const int N = 3;
-global const int U = 7;
-
-main
-{
- // Define our collection of determinants:
- float dets[];
- foreach i in [1:U-1]
- {
- // For U, i, construct a matrix via Numpy:
- A = matrix_add(matrix_scale(eye(N), itof(i)), ones(N));
- B = matrix_set(A, 2, 0, (U-i+1)**3);
- // Obtain its determinant via Numpy:
- v = determinant(B);
- // Store the determinant in a Swift array:
- dets[i] = abs_float(v);
- }
-
- // Build a fragment of R code with the dets:
- code = sprintf("max(%s)", string_from_floats(dets));
- r = R(code);
- printf("max: %f", r);
-}
Deleted: SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/numpy.swift
===================================================================
--- SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/numpy.swift 2013-08-04 15:02:08 UTC (rev 6735)
+++ SwiftTutorials/ATPESC_2013-08-06/part11-swift-py-r/numpy.swift 2013-08-04 15:04:10 UTC (rev 6736)
@@ -1,58 +0,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 A) ones(int n)
-{
- string command = sprintf("repr(ones(%i))", n);
- string code = numpy+command;
- matrix t = python(code);
- A = replace_all(t, "\n", "", 0);
-}
-
-(matrix M) matrix_scale(matrix A, float s)
-{
- string command = sprintf("repr(%s*%s)", A, s);
- string code = numpy+command;
- matrix t = python(code);
- M = replace_all(t, "\n", "", 0);
-}
-
-(matrix M) matrix_set(matrix A, int row, int column, float s)
-{
- string fragment =
- """
-A = %s
-A[%i,%i] = %f
-repr(A)
-""";
- string command = sprintf(fragment, A, row, column, s);
- string code = numpy+command;
- matrix t = python(code);
- M = replace_all(t, "\n", "", 0);
-}
-
-(matrix M) matrix_add(matrix A1, matrix A2)
-{
- string command = sprintf("repr(%s+%s)", A1, A2);
- string code = numpy+command;
- matrix t = python(code);
- M = replace_all(t, "\n", "", 0);
-}
-
-(float d) determinant(matrix A)
-{
- string command = sprintf("repr(linalg.det(%s))", A);
- string code = numpy+command;
- string t = python(code);
- d = tofloat(t);
-}
More information about the Swift-commit
mailing list