Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Commit

Permalink
formatting for XCode7b4
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsievert committed Jul 23, 2015
1 parent 2385cd4 commit 3f08548
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 93 deletions.
2 changes: 2 additions & 0 deletions swix/swix.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
D24A8549196D7D73009C18AC /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = com.scott;
TargetAttributes = {
Expand Down
20 changes: 10 additions & 10 deletions swix/swix/speed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class SpeedTests {
}
}
func time(f:()->(), name:String="function"){
var start = NSDate()
let start = NSDate()
f()
println(NSString(format:"\(name) time (s): %.4f", -1 * start.timeIntervalSinceNow))
print(NSString(format:"\(name) time (s): %.4f", -1 * start.timeIntervalSinceNow))
}
func pe1(){
var N = 1e6
var x = arange(N)
let N = 1e6
let x = arange(N)
// seeing where that modulo is 0
var i = argwhere((abs(x%3) < 1e-9) || (abs(x%5) < 1e-9))
// println(sum(x[i]))
Expand All @@ -38,15 +38,15 @@ func pe10(){
var top = (sqrt(N.double)).int
for i in 2 ..< top{
var max:Int = (N/i)
var j = arange(2, max.double) * i.double
var j = arange(2, max: max.double) * i.double
primes[j] *= 0.0
}
// sum(primes) is the correct answer
}
func pe73(){
var N = 1e3
var i = arange(N)+1
var (n, d) = meshgrid(i, i)
var (n, d) = meshgrid(i, y: i)

var f = (n / d).flat
f = unique(f)
Expand All @@ -57,9 +57,9 @@ func pe73(){

func soft_thresholding(){
let N = 1e2.int
var j = linspace(-1, 1, num:N)
var (x, y) = meshgrid(j, j)
var z = pow(x, 2) + pow(y, 2)
var j = linspace(-1, max: 1, num:N)
var (x, y) = meshgrid(j, y: j)
var z = pow(x, power: 2) + pow(y, power: 2)
var i = abs(z) < 0.5
z[argwhere(i)] *= 0
z[argwhere(1-i)] -= 0.5
Expand All @@ -68,7 +68,7 @@ func soft_thresholding(){


func pi_approx(){
var N = 1e6
let N = 1e6
var k = arange(N)
var pi_approx = 1 / (2*k + 1)
pi_approx[2*k[0..<(N/2).int]+1] *= -1
Expand Down
4 changes: 2 additions & 2 deletions swix/swix/swix/matrix/m-initing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func reshape(x: ndarray, shape:(Int, Int))->matrix{
}
func meshgrid(x: ndarray, y:ndarray) -> (matrix, matrix){
assert(x.n > 0 && y.n > 0, "If these matrices are empty meshgrid fails")
let z1 = reshape(`repeat`(y, N: x.n), shape: (x.n, y.n))
let z2 = reshape(`repeat`(x, N: y.n, axis: 1), shape: (x.n, y.n))
let z1 = reshape(swix_repeat(y, N: x.n), shape: (x.n, y.n))
let z2 = reshape(swix_repeat(x, N: y.n, axis: 1), shape: (x.n, y.n))
return (z2, z1)
}

Expand Down
2 changes: 1 addition & 1 deletion swix/swix/swix/ndarray/helper-functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func delete(x:ndarray, idx:ndarray) -> ndarray{
let y = x[argwhere(i)]
return y
}
func `repeat`(x: ndarray, N:Int, axis:Int=0) -> ndarray{
func swix_repeat(x: ndarray, N:Int, axis:Int=0) -> ndarray{
// repeat the array element wise or as a whole array
var y = zeros((N, x.n))

Expand Down
Loading

0 comments on commit 3f08548

Please sign in to comment.