Skip to content

Commit

Permalink
Renamed func rand… to func random…
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Oct 29, 2019
1 parent 8da2f5e commit 49ebd0d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
32 changes: 16 additions & 16 deletions Sources/Surge/Linear Algebra/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,42 @@ public struct Matrix<Scalar> where Scalar: FloatingPoint, Scalar: ExpressibleByF
// MARK: - Initialization: Randomized

extension Matrix where Scalar == Float {
public static func randUniform(
public static func randomUniform(
rows: Int,
columns: Int,
range: ClosedRange<Float> = 0.0...1.0
) -> Matrix {
var generator = SystemRandomNumberGenerator()
return self.randUniform(
return self.randomUniform(
rows: rows,
columns: columns,
range: range,
using: &generator
)
}

public static func randUniform<T>(
public static func randomUniform<T>(
rows: Int,
columns: Int,
range: ClosedRange<Float> = 0.0...1.0,
using generator: inout T
) -> Matrix where T: RandomNumberGenerator {
let grid = Surge.randUniform(
let grid = Surge.randomUniform(
count: rows * columns,
range: range,
using: &generator
)
return Matrix(rows: rows, columns: columns, grid: grid)
}

public static func randNormal(
public static func randomNormal(
rows: Int,
columns: Int,
mu: Float = 0.0,
sigma: Float = 1.0
) -> Matrix {
var generator = SystemRandomNumberGenerator()
return self.randNormal(
return self.randomNormal(
rows: rows,
columns: columns,
mu: mu,
Expand All @@ -140,14 +140,14 @@ extension Matrix where Scalar == Float {
)
}

public static func randNormal<T>(
public static func randomNormal<T>(
rows: Int,
columns: Int,
mu: Float = 0.0,
sigma: Float = 1.0,
using generator: inout T
) -> Matrix where T: RandomNumberGenerator {
let grid = Surge.randNormal(
let grid = Surge.randomNormal(
count: rows * columns,
mu: mu,
sigma: sigma,
Expand All @@ -158,42 +158,42 @@ extension Matrix where Scalar == Float {
}

extension Matrix where Scalar == Double {
public static func randUniform(
public static func randomUniform(
rows: Int,
columns: Int,
range: ClosedRange<Double> = 0.0...1.0
) -> Matrix {
var generator = SystemRandomNumberGenerator()
return self.randUniform(
return self.randomUniform(
rows: rows,
columns: columns,
range: range,
using: &generator
)
}

public static func randUniform<T>(
public static func randomUniform<T>(
rows: Int,
columns: Int,
range: ClosedRange<Double> = 0.0...1.0,
using generator: inout T
) -> Matrix where T: RandomNumberGenerator {
let grid = Surge.randUniform(
let grid = Surge.randomUniform(
count: rows * columns,
range: range,
using: &generator
)
return Matrix(rows: rows, columns: columns, grid: grid)
}

public static func randNormal(
public static func randomNormal(
rows: Int,
columns: Int,
mu: Double = 0.0,
sigma: Double = 1.0
) -> Matrix {
var generator = SystemRandomNumberGenerator()
return self.randNormal(
return self.randomNormal(
rows: rows,
columns: columns,
mu: mu,
Expand All @@ -202,14 +202,14 @@ extension Matrix where Scalar == Double {
)
}

public static func randNormal<T>(
public static func randomNormal<T>(
rows: Int,
columns: Int,
mu: Double = 0.0,
sigma: Double = 1.0,
using generator: inout T
) -> Matrix where T: RandomNumberGenerator {
let grid = Surge.randNormal(
let grid = Surge.randomNormal(
count: rows * columns,
mu: mu,
sigma: sigma,
Expand Down
32 changes: 16 additions & 16 deletions Sources/Surge/Linear Algebra/Vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,77 +55,77 @@ public struct Vector<Scalar> where Scalar: FloatingPoint, Scalar: ExpressibleByF
// MARK: - Initialization: Randomized

extension Vector where Scalar == Float {
public static func randUniform(
public static func randomUniform(
count: Int,
range: ClosedRange<Float> = 0.0...1.0
) -> Vector {
var generator = SystemRandomNumberGenerator()
return self.randUniform(count: count, range: range, using: &generator)
return self.randomUniform(count: count, range: range, using: &generator)
}

public static func randUniform<T>(
public static func randomUniform<T>(
count: Int,
range: ClosedRange<Float> = 0.0...1.0,
using generator: inout T
) -> Vector where T: RandomNumberGenerator {
let scalars = Surge.randUniform(count: count, range: range, using: &generator)
let scalars = Surge.randomUniform(count: count, range: range, using: &generator)
return Vector(scalars: scalars)
}

public static func randNormal(
public static func randomNormal(
count: Int,
mu: Float = 0.0,
sigma: Float = 1.0
) -> Vector {
var generator = SystemRandomNumberGenerator()
return self.randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return self.randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
}

public static func randNormal<T>(
public static func randomNormal<T>(
count: Int,
mu: Float = 0.0,
sigma: Float = 1.0,
using generator: inout T
) -> Vector where T: RandomNumberGenerator {
let scalars = Surge.randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
let scalars = Surge.randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return Vector(scalars: scalars)
}
}

extension Vector where Scalar == Double {
public static func randUniform(
public static func randomUniform(
count: Int,
range: ClosedRange<Double> = 0.0...1.0
) -> Vector {
var generator = SystemRandomNumberGenerator()
return self.randUniform(count: count, range: range, using: &generator)
return self.randomUniform(count: count, range: range, using: &generator)
}

public static func randUniform<T>(
public static func randomUniform<T>(
count: Int,
range: ClosedRange<Double> = 0.0...1.0,
using generator: inout T
) -> Vector where T: RandomNumberGenerator {
let scalars = Surge.randUniform(count: count, range: range, using: &generator)
let scalars = Surge.randomUniform(count: count, range: range, using: &generator)
return Vector(scalars: scalars)
}

public static func randNormal(
public static func randomNormal(
count: Int,
mu: Double = 0.0,
sigma: Double = 1.0
) -> Vector {
var generator = SystemRandomNumberGenerator()
return self.randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return self.randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
}

public static func randNormal<T>(
public static func randomNormal<T>(
count: Int,
mu: Double = 0.0,
sigma: Double = 1.0,
using generator: inout T
) -> Vector where T: RandomNumberGenerator {
let scalars = Surge.randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
let scalars = Surge.randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return Vector(scalars: scalars)
}
}
Expand Down
32 changes: 16 additions & 16 deletions Sources/Surge/Statistics/Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,64 @@ import Foundation

// MARK: - Random: Uniform Distribution

public func randUniform(
public func randomUniform(
count: Int,
range: ClosedRange<Float> = 0.0...1.0
) -> [Float] {
var generator = SystemRandomNumberGenerator()
return randUniform(count: count, range: range, using: &generator)
return randomUniform(count: count, range: range, using: &generator)
}

public func randUniform(
public func randomUniform(
count: Int,
range: ClosedRange<Double> = 0.0...1.0
) -> [Double] {
var generator = SystemRandomNumberGenerator()
return randUniform(count: count, range: range, using: &generator)
return randomUniform(count: count, range: range, using: &generator)
}

public func randUniform<T>(
public func randomUniform<T>(
count: Int,
range: ClosedRange<Float>,
using generator: inout T
) -> [Float] where T: RandomNumberGenerator {
return (0..<count).map { _ in Float.random(in: range, using: &generator) }
}

public func randUniform<T>(
public func randomUniform<T>(
count: Int,
range: ClosedRange<Double>,
using generator: inout T
) -> [Double] where T: RandomNumberGenerator {
return (0..<count).map { _ in Double.random(in: range, using: &generator) }
}

public func randNormal(
public func randomNormal(
count: Int,
mu: Float = 0.0,
sigma: Float = 1.0
) -> [Float] {
var generator = SystemRandomNumberGenerator()
return randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
}

public func randNormal(
public func randomNormal(
count: Int,
mu: Double = 0.0,
sigma: Double = 1.0
) -> [Double] {
var generator = SystemRandomNumberGenerator()
return randNormal(count: count, mu: mu, sigma: sigma, using: &generator)
return randomNormal(count: count, mu: mu, sigma: sigma, using: &generator)
}

public func randNormal<T>(
public func randomNormal<T>(
count: Int,
mu: Float = 0.0,
sigma: Float = 1.0,
using generator: inout T
) -> [Float] where T: RandomNumberGenerator {
var lhs: [Float] = randUniform(count: count, range: 0.0...1.0, using: &generator)
var rhs: [Float] = randUniform(count: count, range: 0.0...1.0, using: &generator)
var lhs: [Float] = randomUniform(count: count, range: 0.0...1.0, using: &generator)
var rhs: [Float] = randomUniform(count: count, range: 0.0...1.0, using: &generator)

boxMullerTransformInPlace(&lhs, &rhs)

Expand All @@ -92,16 +92,16 @@ public func randNormal<T>(
return lhs
}

public func randNormal<T>(
public func randomNormal<T>(
count: Int,
mu: Double = 0.0,
sigma: Double = 1.0,
using generator: inout T
) -> [Double] where T: RandomNumberGenerator {
// Box-Muller transform

var lhs: [Double] = randUniform(count: count, range: 0.0...1.0, using: &generator)
var rhs: [Double] = randUniform(count: count, range: 0.0...1.0, using: &generator)
var lhs: [Double] = randomUniform(count: count, range: 0.0...1.0, using: &generator)
var rhs: [Double] = randomUniform(count: count, range: 0.0...1.0, using: &generator)

boxMullerTransformInPlace(&lhs, &rhs)

Expand Down

0 comments on commit 49ebd0d

Please sign in to comment.