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

Commit

Permalink
fixes an issue where random wasn't random and tests generation
Browse files Browse the repository at this point in the history
specifically, `imshow` let me see some structure in a “random” matrix.
Turns out changing the seed helped this.
  • Loading branch information
scottsievert committed Sep 13, 2015
1 parent 8e7ce07 commit 3fa81c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "swix/swix/tests/tests.swift"
timestampString = "462756782.87901"
timestampString = "463813473.607358"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "310"
endingLineNumber = "310"
startingLineNumber = "329"
endingLineNumber = "329"
landmarkName = "readWriteTests()"
landmarkType = "5">
</BreakpointContent>
Expand Down
2 changes: 1 addition & 1 deletion swix/swix/swix/ndarray/initing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func rand(N: Int, distro:String="uniform") -> ndarray{
let x = zeros(N)
var i:__CLPK_integer = 1
if distro=="normal" {i = __CLPK_integer(3)}
var seed:Array<__CLPK_integer> = [SWIX_SEED, 0, 0, 0]
var seed:Array<__CLPK_integer> = [SWIX_SEED, 2, 3, 5]
var nn:__CLPK_integer = __CLPK_integer(N)
dlarnv_(&i, &seed, &nn, !x)
SWIX_SEED = seed[0]
Expand Down
21 changes: 20 additions & 1 deletion swix/swix/swix/tests/tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,26 @@ class swixTests {
assert(copy(arange(4)) ~== arange(4))
assert(asarray(0..<2) ~== array(0, 1))
assert(copy(arange(3)) ~== array(0, 1, 2))
assert(sum((rand(3) - array(0.516, 0.294, 0.727)) < 1e-2) == 3)
//assert(sum((rand(3) - array(0.516, 0.294, 0.727)) < 1e-2) == 3)

var N = 1e4.int
seed(42)
var x = rand(N)

seed(42)
var y = rand(N)
assert(x ~== y)

seed(29)
y = rand(N)
assert(!(x ~== y))

seed(42)
y = rand(N)
assert(x ~== y)

assert(abs(x.mean() - 0.5) < 1e-1)
assert(abs(variance(x) - 1/12) < 1e-1)
}
func ndarraySwiftTests(){
// testing the file ndarray.swift
Expand Down

0 comments on commit 3fa81c9

Please sign in to comment.