Skip to content

Commit a08ebbd

Browse files
committed
Import 0.12.8 modifications
1 parent 2007a65 commit a08ebbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+766
-501
lines changed

tfjs-core/src/main/scala/io/brunk/tfjs/core/engine.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package io.brunk.tfjs.core
1818

1919
import scala.scalajs.js
2020
import js.annotation._
21-
import js.{ Promise, | }
21+
import js.{Promise, |}
2222
import Engine.MemoryInfo
2323
import kernels.BackendTimingInfo
2424
import kernels.KernelBackend
@@ -27,8 +27,14 @@ import Types.TensorContainer
2727
import TensorModule.DataId
2828
import Types._
2929
import Engine.CustomGradientFunc
30-
import org.scalajs.dom.{ ImageData, html }
30+
import org.scalajs.dom.{ImageData, html}
3131
import TensorModule._
32+
33+
@js.native
34+
trait TimingInfo extends BackendTimingInfo {
35+
var wallMs: Double
36+
}
37+
3238
@js.native
3339
trait TensorManager extends js.Object {
3440
def registerTensor(a: TensorND): Unit
@@ -37,17 +43,18 @@ trait TensorManager extends js.Object {
3743
def memory(): js.Any
3844
}
3945

40-
@js.native
41-
trait TimingInfo extends BackendTimingInfo {
42-
var wallMs: Double
43-
}
4446

4547
@js.native
4648
@JSGlobal
4749
class Engine protected () extends TensorManager {
4850
def this(backend: KernelBackend, safeMode: Boolean) = this()
4951
var safeMode: Boolean = js.native
5052
var registeredVariables: NamedVariableMap = js.native
53+
def tidy[T <: TensorContainer](
54+
nameOrFn: String | ScopeFn[T],
55+
fn: ScopeFn[T] = ???,
56+
gradMode: Boolean = ???
57+
): T = js.native
5158
def runKernel[T <: TensorND, I <: NamedTensorMap](
5259
forwardFunc: ForwardFunc[T],
5360
inputs: I,
@@ -82,7 +89,7 @@ class Engine protected () extends TensorManager {
8289
@js.native
8390
@JSGlobalScope
8491
object Engine extends js.Object {
85-
type ForwardFunc[T <: TensorND] = js.Function2[KernelBackend, js.Function, T]
92+
type ForwardFunc[T] = js.Function2[KernelBackend, js.Function, T]
8693
type CustomGradientFunc[T <: TensorND] = js.Function
8794
type MemoryInfo = js.Any
8895
type ScopeFn[T <: TensorContainer] = js.Function0[T]

tfjs-core/src/main/scala/io/brunk/tfjs/core/environment.scala

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,18 @@ package io.brunk.tfjs.core
1818

1919
import scala.scalajs.js
2020
import js.annotation._
21-
import js.|
21+
import js.{Promise, |}
2222
import Engine.MemoryInfo
2323
import kernels.KernelBackend
2424

25-
@js.native
26-
sealed trait Type extends js.Object {}
27-
28-
@js.native
29-
@JSGlobal
30-
object Type extends js.Object {
31-
var NUMBER: Type = js.native
32-
var BOOLEAN: Type = js.native
33-
var STRING: Type = js.native
34-
@JSBracketAccess
35-
def apply(value: Type): String = js.native
36-
}
3725

38-
@js.native
39-
trait Features extends js.Object {
40-
var DEBUG: Boolean = js.native
41-
var IS_BROWSER: Boolean = js.native
42-
var IS_NODE: Boolean = js.native
43-
var WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION: Double = js.native
44-
var WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE: Boolean = js.native
45-
var WEBGL_VERSION: Double = js.native
46-
var WEBGL_RENDER_FLOAT32_ENABLED: Boolean = js.native
47-
var WEBGL_DOWNLOAD_FLOAT_ENABLED: Boolean = js.native
48-
var WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED: Boolean = js.native
49-
var BACKEND: String = js.native
50-
var TEST_EPSILON: Double = js.native
51-
var IS_CHROME: Boolean = js.native
52-
}
53-
54-
@js.native
55-
trait URLProperty extends js.Object {
56-
var name: String = js.native
57-
var `type`: Type = js.native
58-
}
5926

6027
@js.native
6128
@JSGlobal
6229
class Environment protected () extends js.Object {
6330
def this(features: Features = ???) = this()
31+
var backendName: String = js.native
32+
var backend: KernelBackend = js.native
6433
def get[K <: String](feature: K): js.Any = js.native
6534
def getFeatures(): Features = js.native
6635
def set[K <: String](feature: K, value: js.Any): Unit = js.native
@@ -71,7 +40,8 @@ class Environment protected () extends js.Object {
7140
def registerBackend(
7241
name: String,
7342
factory: js.Function0[KernelBackend],
74-
priority: Double = ???
43+
priority: Double = ???,
44+
setTensorTrackerFn: js.Function1[js.Function0[TensorTracker], Unit] = ???
7545
): Boolean = js.native
7646
def removeBackend(name: String): Unit = js.native
7747
def engine: Engine = js.native
@@ -83,6 +53,14 @@ trait EnvironmentCompanion extends js.Object {
8353
def getBackend(): String = js.native
8454
def disposeVariables(): Unit = js.native
8555
def memory(): MemoryInfo = js.native
56+
def tidy[T <: TensorContainer](
57+
nameOrFn: String | ScopeFn[T],
58+
fn: ScopeFn[T] = ???,
59+
gradMode: Boolean = ???
60+
): T = js.native
61+
def dispose(container: TensorContainer): Unit = js.native
62+
def keep[T <: TensorND](result: T): T = js.native
63+
def time(f: js.Function0[Unit]): Promise[TimingInfo] = js.native
8664
}
8765

8866
@js.native

tfjs-core/src/main/scala/io/brunk/tfjs/core/globals.scala

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ import Types.TensorContainer
2424
import Engine.{ CustomGradientFunc, ScopeFn }
2525

2626
@js.native
27-
trait Globals extends TrackingCompanion {
28-
// TODO reuse Tracking trait but without gradScope
29-
def grad[I <: TensorND, O <: TensorND](f: js.Function1[I, O]): js.Function2[I, O, I] = js.native
30-
def grads[O <: TensorND](
31-
f: js.Function
32-
): js.Function2[js.Array[TensorND], O, js.Array[TensorND]] =
33-
js.native
34-
def valueAndGrad[I <: TensorND, O <: TensorND](
35-
f: js.Function1[I, O]
36-
): js.Function2[I, O, js.Any] =
37-
js.native
38-
def valueAndGrads[O <: TensorND](f: js.Function): js.Function2[js.Array[TensorND], O, js.Any] =
39-
js.native
40-
def variableGrads(f: js.Function0[Scalar], varList: js.Array[Variable[Rank]] = ???): js.Any =
41-
js.native
42-
def customGrad[T <: TensorND](f: CustomGradientFunc[T]): js.Function = js.native
27+
trait Globals extends js.Object {
28+
def tidy[T <: TensorContainer](
29+
nameOrFn: String | ScopeFn[T],
30+
fn: ScopeFn[T] = ???,
31+
gradMode: Boolean = ???
32+
): T = js.native
33+
def dispose(container: TensorContainer): Unit = js.native
34+
def keep[T <: Tensor](result: T): T = js.native
35+
def time(f: js.Function0[Unit]): Promise[TimingInfo] = js.native
4336
}

tfjs-core/src/main/scala/io/brunk/tfjs/core/gradients.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import Engine.ScopeFn
2424
import TensorModule.{ Scalar, TensorND }
2525
import Engine.CustomGradientFunc
2626

27-
@js.native
28-
@JSGlobal
29-
class Gradients extends js.Object {}
3027

3128
@js.native
3229
@JSGlobal

tfjs-core/src/main/scala/io/brunk/tfjs/core/index.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ trait Index
3131
with EnvironmentCompanion
3232
with Version
3333
with BrowserUtil {
34+
type InferenceModel = core.InferenceModel
35+
type ModelPredictConfig = core.ModelPredictConfig
3436
type AdadeltaOptimizer = optimizers.AdadeltaOptimizer
3537
val AdadeltaOptimizer: optimizers.AdadeltaOptimizer.type = js.native
3638
type AdagradOptimizer = optimizers.AdagradOptimizer
@@ -43,8 +45,6 @@ trait Index
4345
type Tensor[R <: Rank] = core.Tensor[R]
4446
type Variable[R <: Rank] = core.Variable[R]
4547
type DataType = core.DataType
46-
type InferenceModel = core.InferenceModel
47-
type ModelPredictConfig = core.ModelPredictConfig
4848
type NamedTensorMap = core.NamedTensorMap
4949
type Rank = core.Rank
5050
// TODO LSTMCellFunc
@@ -55,6 +55,7 @@ trait Index
5555
val serialization: core.serialization.type = js.native
5656
// TODO webgl
5757
// TODO backend
58+
// TODO doc
5859
}
5960

6061
@js.native
@@ -64,5 +65,4 @@ object Index extends js.Object {
6465
def getBackend(): String = js.native
6566
def disposeVariables(): Unit = js.native
6667
def memory(): MemoryInfo = js.native
67-
def nextFrame(): Promise[Unit] = js.native
6868
}

tfjs-core/src/main/scala/io/brunk/tfjs/core/jasmine_util.scala

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,20 @@ import js.|
2222
import kernels.KernelBackend
2323

2424
@js.native
25-
trait TestBackendFactory extends js.Object {
25+
trait TestEnv extends js.Object {
2626
var name: String = js.native
2727
var factory: js.Function0[KernelBackend] = js.native
28-
var priority: Double = js.native
28+
var features: Features = js.native
2929
}
3030

3131
@js.native
3232
@JSGlobalScope
3333
object Jasmine_util extends js.Object {
34-
def canEmulateEnvironment(emulatedFeatures: Features): Boolean = js.native
35-
def anyFeaturesEquivalentToDefault(
36-
emulatedFeatures: js.Array[Features],
37-
environment: Environment
38-
): Boolean = js.native
39-
def describeWithFlags(
40-
name: String,
41-
featuresToRun: js.Array[Features],
42-
tests: js.Function0[Unit]
43-
): Unit = js.native
44-
def TEST_BACKENDS: js.Array[TestBackendFactory] = js.native
45-
def setBeforeAll(f: js.Function1[Features, Unit]): Unit = js.native
46-
def setAfterAll(f: js.Function1[Features, Unit]): Unit = js.native
47-
def setBeforeEach(f: js.Function1[Features, Unit]): Unit = js.native
48-
def setAfterEach(f: js.Function1[Features, Unit]): Unit = js.native
49-
def setTestBackends(testBackends: js.Array[TestBackendFactory]): Unit = js.native
50-
def registerTestBackends(): Unit = js.native
34+
def envSatisfiesConstraints(constraints: Features): Boolean = js.native
35+
def parseKarmaFlags(args: js.Array[String]): TestEnv = js.native
36+
def describeWithFlags(name: String, constraints: Features, tests: js.Function0[Unit]): Unit =
37+
js.native
38+
def TEST_ENVS: js.Array[TestEnv] = js.native
39+
val CPU_FACTORY: js.Function0[MathBackendCPU] = js.native
40+
def setTestEnvs(testEnvs: js.Array[TestEnv]): Unit = js.native
5141
}

tfjs-core/src/main/scala/io/brunk/tfjs/core/kernels/backend.scala

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ trait KernelBackend extends TensorStorage with BackendTimer {
6565
def concat(a: Tensor2D, b: Tensor2D): Tensor2D
6666
def neg[T <: TensorND](a: T): T
6767
def add(a: TensorND, b: TensorND): TensorND
68+
def addN[T <: TensorND](tensors: js.Array[T]): T
6869
def subtract(a: TensorND, b: TensorND): TensorND
6970
def multiply(a: TensorND, b: TensorND): TensorND
7071
def realDivide(a: TensorND, b: TensorND): TensorND
@@ -83,14 +84,15 @@ trait KernelBackend extends TensorStorage with BackendTimer {
8384
def logicalAnd(a: TensorND, b: TensorND): TensorND
8485
def logicalOr(a: TensorND, b: TensorND): TensorND
8586
def where(condition: TensorND, a: TensorND, b: TensorND, dtype: DataType): TensorND
86-
def topKValues[T <: TensorND](x: T, k: Double): Tensor1D
87-
def topKIndices(x: TensorND, k: Double): Tensor1D
87+
def select(condition: TensorND, a: TensorND, b: TensorND): TensorND
88+
def topk[T <: TensorND](x: T, k: Double, sorted: Boolean): js.Tuple2[T, T]
8889
def min(x: TensorND, axes: js.Array[Double]): TensorND
8990
def minimum(a: TensorND, b: TensorND): TensorND
9091
def mod(a: TensorND, b: TensorND): TensorND
9192
def max(x: TensorND, axes: js.Array[Double]): TensorND
9293
def maximum(a: TensorND, b: TensorND): TensorND
9394
def all(x: TensorND, axes: js.Array[Double]): TensorND
95+
def any(x: TensorND, axes: js.Array[Double]): TensorND
9496
def squaredDifference(a: TensorND, b: TensorND): TensorND
9597
def ceil[T <: TensorND](x: T): T
9698
def floor[T <: TensorND](x: T): T
@@ -149,6 +151,16 @@ trait KernelBackend extends TensorStorage with BackendTimer {
149151
): T
150152
def transpose[T <: TensorND](x: T, perm: js.Array[Double]): T
151153
def gather[T <: TensorND](x: T, indices: Tensor1D, axis: Double): T
154+
def batchToSpaceND[T <: TensorND](
155+
x: T,
156+
blockShape: js.Array[Double],
157+
crops: js.Array[js.Array[Double]]
158+
): T = js.native
159+
def spaceToBatchND[T <: TensorND](
160+
x: T,
161+
blockShape: js.Array[Double],
162+
paddings: js.Array[js.Array[Double]]
163+
): T = js.native
152164
def resizeBilinear(
153165
x: Tensor4D,
154166
newHeight: Double,
@@ -162,6 +174,7 @@ trait KernelBackend extends TensorStorage with BackendTimer {
162174
newWidth: Double,
163175
alignCorners: Boolean
164176
): Tensor4D
177+
def resizeNearestNeighborBackprop(dy: Tensor4D, x: Tensor4D, alignCorners: Boolean): Tensor4D
165178
def batchNormalization(
166179
x: Tensor4D,
167180
mean: Tensor4D | Tensor1D,
@@ -177,6 +190,15 @@ trait KernelBackend extends TensorStorage with BackendTimer {
177190
alpha: Double,
178191
beta: Double
179192
): Tensor4D
193+
def LRNGrad(
194+
dy: Tensor4D,
195+
inputImage: Tensor4D,
196+
outputImage: Tensor4D,
197+
radius: Double,
198+
bias: Double,
199+
alpha: Double,
200+
beta: Double
201+
): Tensor4D
180202
def multinomial(
181203
logits: Tensor2D,
182204
normalized: Boolean,
@@ -185,5 +207,12 @@ trait KernelBackend extends TensorStorage with BackendTimer {
185207
): Tensor2D
186208
def oneHot(indices: Tensor1D, depth: Double, onValue: Double, offValue: Double): Tensor2D
187209
def cumsum(x: TensorND, axis: Double, exclusive: Boolean, reverse: Boolean): TensorND
210+
def nonMaxSuppression(
211+
boxes: Tensor2D,
212+
scores: Tensor1D,
213+
maxOutputSize: Double,
214+
iouThreshold: Double,
215+
scoreThreshold: Double = ???
216+
): Tensor1D
188217
def dispose(): Unit
189218
}

0 commit comments

Comments
 (0)