Skip to content

Commit 94ab2df

Browse files
authored
Modified Raw -> _Raw
Modified `Raw` -> `_Raw`
2 parents 0672df2 + 89c59e1 commit 94ab2df

13 files changed

+33
-33
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
env:
22
global:
3-
- SWIFT_BRANCH=tensorflow-0.4
3+
- SWIFT_BRANCH=tensorflow-0.6
44
# PACKAGE_VERSION will be used by travis to create the Github release tag
55
- PACKAGE_VERSION=0.0.1
66

@@ -13,9 +13,9 @@ jobs:
1313
language: swift
1414
sudo: required
1515
install:
16-
- wget https://storage.googleapis.com/swift-tensorflow-artifacts/releases/v0.4/rc2/swift-tensorflow-RELEASE-0.4-osx.pkg
17-
- sudo installer -pkg swift-tensorflow-RELEASE-0.4-osx.pkg -target /
18-
- export PATH="/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.4.xctoolchain/usr/bin:$PATH"
16+
- wget https://storage.googleapis.com/swift-tensorflow-artifacts/releases/v0.6/rc1/swift-tensorflow-RELEASE-0.6-osx.pkg
17+
- sudo installer -pkg swift-tensorflow-RELEASE-0.6-osx.pkg -target /
18+
- export PATH="/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.6.xctoolchain/usr/bin:$PATH"
1919
- gem install jazzy
2020
- jazzy --min-acl internal --no-hide-documentation-coverage --theme fullwidth --output ./docs
2121
- rm -rf ./build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Swift library for Machine Learning based on [Swift for TensorFlow](https://githu
2323
Add the library to your projects dependencies in the Package.swift file as shown below.
2424
```swift
2525
dependencies: [
26-
.package(url: "https://github.com/param087/swiftML", .exact("0.0.2")),
26+
.package(url: "https://github.com/param087/swiftML", .exact("0.0.4")),
2727
],
2828
```
2929

@@ -35,7 +35,7 @@ can import them:
3535
```swift
3636

3737
// Install the swiftML package from GitHub.
38-
%install '.package(url: "https://github.com/param087/swiftML", from: "0.0.2")' swiftML
38+
%install '.package(url: "https://github.com/param087/swiftML", from: "0.0.4")' swiftML
3939

4040
// Install the swiftML package that's in the local directory.
4141
%install '.package(path: "$cwd/swiftML")' swiftML

Sources/swiftML/BernoulliNB.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class BernoulliNB {
4545
precondition(labels.shape[0] > 0, "Labels must have a positive sample count.")
4646

4747
// Find unique classes in target values.
48-
(self.classes, self.indices) = Raw.unique(labels.flattened())
48+
(self.classes, self.indices) = _Raw.unique(labels.flattened())
4949

5050
// Initialize the classLogPrior and featureLogProb based on feature count and sample count.
5151
var separated = [[Tensor<Float>]]()

Sources/swiftML/GaussianNB.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GaussianNB {
3232
precondition(labels.shape[0] > 0, "Labels must have a positive sample count.")
3333

3434
// Find unique classes in target values.
35-
(self.classes, self.indices) = Raw.unique(labels.flattened())
35+
(self.classes, self.indices) = _Raw.unique(labels.flattened())
3636

3737
var separated = [[Tensor<Float>]]()
3838
self.model = Tensor<Float>(zeros: [self.classes.shape[0], data.shape[1], 2])

Sources/swiftML/Helpers.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ extension Tensor where Scalar: TensorFlowFloatingPoint {
66
/// Reference: ["Moore–Penrose inverse"](
77
/// https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse)
88
public var pseudoinverse: Tensor {
9-
let svd = Raw.svd(self)
10-
let diag = Raw.diag(diagonal: svd.s)
11-
return matmul(matmul(svd.v, Raw.matrixInverse(diag)), svd.u.transposed())
9+
let svd = _Raw.svd(self)
10+
let diag = _Raw.diag(diagonal: svd.s)
11+
return matmul(matmul(svd.v, _Raw.matrixInverse(diag)), svd.u.transposed())
1212
}
1313
}
1414

@@ -28,7 +28,7 @@ public func deterministicSvd<T: FloatingPoint & TensorFlowScalar>(
2828
_ input: Tensor<T>,
2929
columnBasedSignFlipping: Bool = true
3030
) -> (s: Tensor<T>, u: Tensor<T>, v: Tensor<T>) {
31-
var (s, u, v) = Raw.svd(input)
31+
var (s, u, v) = _Raw.svd(input)
3232
v = v.transposed()
3333

3434
let signs: Tensor<T>
@@ -39,14 +39,14 @@ public func deterministicSvd<T: FloatingPoint & TensorFlowScalar>(
3939
for i in 0..<u.shape[1] {
4040
colValueForSign[i] = u[Int(maxAbsCols[i].scalarized()), i]
4141
}
42-
signs = Raw.sign(colValueForSign)
42+
signs = _Raw.sign(colValueForSign)
4343
} else {
4444
let maxAbsRows = abs(v).argmax(squeezingAxis: 1)
4545
var rowValueForSign = Tensor<T>(zeros: [u.shape[0]])
4646
for i in 0..<u.shape[0] {
4747
rowValueForSign[i] = v[i, Int(maxAbsRows[i].scalarized())]
4848
}
49-
signs = Raw.sign(rowValueForSign)
49+
signs = _Raw.sign(rowValueForSign)
5050
}
5151
return (s, u * signs, v * signs.reshaped(to: [u.shape[1], 1]))
5252
}

Sources/swiftML/KMeans.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public class KMeans {
9191
}
9292

9393
let probability = distance / distance.sum()
94-
let cumsum = Raw.cumsum(probability.flattened(), axis: Tensor<Int32>(-1))
94+
let cumsum = _Raw.cumsum(probability.flattened(), axis: Tensor<Int32>(-1))
9595
let threshold = Tensor<Float>(Float.random(in: 0...1))
9696

9797
var index: Int = 0
9898

9999
for j in 0..<cumsum.shape[0] {
100-
if cumsum[j] >= threshold {
100+
if cumsum[j].scalarized() >= threshold.scalarized() {
101101
break
102102
} else {
103103
index = index + 1
@@ -113,7 +113,7 @@ public class KMeans {
113113
/// - data: Data with shape `[sample count, feature count]`.
114114
internal func randomInitializer(_ data: Tensor<Float>) {
115115
// shuffle the input data.
116-
let shuffled = Raw.randomShuffle(value: data, seed: self.seed)
116+
let shuffled = _Raw.randomShuffle(value: data, seed: self.seed)
117117
for i in 0..<clusterCount {
118118
self.centroids[i] = shuffled[i]
119119
}

Sources/swiftML/KNeighborsClassifier.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public class KNeighborsClassifier {
113113

114114
// Find the top neighbor with minimum distance.
115115
(minDistances, minDistanceIndex) =
116-
Raw.topKV2(distances, k: Tensor<Int32>(Int32(data.shape[0])), sorted: true)
117-
minDistances = Raw.reverse(minDistances, dims: Tensor<Bool>([true]))
116+
_Raw.topKV2(distances, k: Tensor<Int32>(Int32(data.shape[0])), sorted: true)
117+
minDistances = _Raw.reverse(minDistances, dims: Tensor<Bool>([true]))
118118
minDistances = minDistances
119119
.slice(lowerBounds: Tensor<Int32>([0]),
120120
sizes: Tensor<Int32>([Int32(self.neighborCount)]))
121121

122-
minDistanceIndex = Raw.reverse(minDistanceIndex, dims: Tensor<Bool>([true]))
122+
minDistanceIndex = _Raw.reverse(minDistanceIndex, dims: Tensor<Bool>([true]))
123123
minDistanceIndex = minDistanceIndex
124124
.slice(lowerBounds: Tensor<Int32>([0]),
125125
sizes: Tensor<Int32>([Int32(self.neighborCount)]))
@@ -132,7 +132,7 @@ public class KNeighborsClassifier {
132132
let labelsAndWeightsTensor = computeWeights(
133133
distances: minDistances, labels: Tensor<Float>(minDistanceLabels))
134134

135-
(classes, indices) = Raw.unique(Tensor<Int32>(minDistanceLabels))
135+
(classes, indices) = _Raw.unique(Tensor<Int32>(minDistanceLabels))
136136

137137
var kClasses = Tensor<Int32>(zeros: [classes.shape[0]])
138138
var kWeights = Tensor<Float>(zeros: [classes.shape[0]])
@@ -148,7 +148,7 @@ public class KNeighborsClassifier {
148148
}
149149

150150
// Returns class with highest weight.
151-
let resultSet = Raw.topKV2(kWeights, k: Tensor<Int32>(1), sorted: true)
151+
let resultSet = _Raw.topKV2(kWeights, k: Tensor<Int32>(1), sorted: true)
152152
let classIndex = Int(resultSet.indices[0].scalarized())
153153
return kClasses[classIndex]
154154
}

Sources/swiftML/KNeighborsRegressor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public class KNeighborsRegressor {
108108

109109
// Find the top neighbors with minimum distance.
110110
(minDistances, minDistanceIndex) =
111-
Raw.topKV2(distances, k: Tensor<Int32>(Int32(data.shape[0])), sorted: true)
112-
minDistances = Raw.reverse(minDistances, dims: Tensor<Bool>([true]))
111+
_Raw.topKV2(distances, k: Tensor<Int32>(Int32(data.shape[0])), sorted: true)
112+
minDistances = _Raw.reverse(minDistances, dims: Tensor<Bool>([true]))
113113
minDistances = minDistances
114114
.slice(lowerBounds: Tensor<Int32>([0]),
115115
sizes: Tensor<Int32>([Int32(self.neighborCount)]))
116116

117-
minDistanceIndex = Raw.reverse(minDistanceIndex, dims: Tensor<Bool>([true]))
117+
minDistanceIndex = _Raw.reverse(minDistanceIndex, dims: Tensor<Bool>([true]))
118118
minDistanceIndex = minDistanceIndex
119119
.slice(lowerBounds: Tensor<Int32>([0]),
120120
sizes: Tensor<Int32>([Int32(self.neighborCount)]))

Sources/swiftML/LeastSquaresLinearRegression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class LeastSquaresLinearRegression: LinearRegression {
4444
}
4545

4646
// weights = (X^T.X)^-1.X^T.y
47-
self.weights = matmul(matmul(Raw.matrixInverse(matmul(data.transposed(), data)),
47+
self.weights = matmul(matmul(_Raw.matrixInverse(matmul(data.transposed(), data)),
4848
data.transposed()), labels)
4949
}
5050
}

Sources/swiftML/LogisticRegression.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ public class LogisticRegression {
6161
}
6262
let sampleCount = Float(data.shape[0])
6363

64-
(self.classes, self.indices) = Raw.unique(labels.flattened())
64+
(self.classes, self.indices) = _Raw.unique(labels.flattened())
6565

6666
precondition(self.classes.shape[0] >= 2, "Labels must have atleast two classes")
6767

6868
/// Loop through each class and apply one-vs-rest (OvR) scheme.
6969
for i in 0..<self.classes.shape[0] {
70-
let condition = Raw.equal(labels, classes[i])
70+
let condition = _Raw.equal(labels, classes[i])
7171
let t = Tensor<Int32>(ones: [labels.shape[0], 1])
7272
let e = Tensor<Int32>(zeros: [labels.shape[0], 1])
7373

7474
/// Create temparary labels for one-vs-rest scheme, based on class the selected class
7575
/// labeled as `1` while rest as `0`.
76-
var tempLabels = Tensor<Float>(Raw.select(condition: condition, t: t, e: e))
76+
var tempLabels = Tensor<Float>(_Raw.select(condition: condition, t: t, e: e))
7777
tempLabels = tempLabels.reshaped(to: [tempLabels.shape[0], 1])
7878

7979
/// weights of selected class in one-vs-rests scheme.

0 commit comments

Comments
 (0)