Skip to content

Commit fe2937d

Browse files
committed
[CORE] Fix issues from 0.12.8 import
1 parent a08ebbd commit fe2937d

27 files changed

+168
-91
lines changed

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ lazy val example =
6565
npmDevDependencies in Compile += "html-webpack-plugin" -> "3.2.0",
6666
scalaJSUseMainModuleInitializer := true,
6767
mainClass in Compile := Some("example.Example"),
68-
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "dev.config.js")
6968
)
7069
.dependsOn(`scalajs-tfjs-core`)
7170
.dependsOn(`scalajs-tfjs-layers`)
@@ -114,7 +113,7 @@ lazy val library =
114113
lazy val npmLibrary =
115114
new {
116115
object Version {
117-
val tfjsCore = "0.11.9"
116+
val tfjsCore = "0.12.8"
118117
val tfjsLayers = "0.6.7"
119118
val tfjsConverter = "0.4.3"
120119
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 1.2.0
1+
sbt.version = 1.2.1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2017 Sören Brunk
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** DOM API facades that aren't in scalajs-dom yet. TODO PR */
18+
package io.brunk.dom
19+
import scala.scalajs.js
20+
import scala.scalajs.js.annotation.JSGlobal
21+
22+
@js.native
23+
@JSGlobal
24+
class WebGLQuery private[this] () extends js.Object
25+
26+
@js.native
27+
@JSGlobal
28+
class WebGLSync private[this] () extends js.Object

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import js.{Promise, |}
2222
import Engine.MemoryInfo
2323
import kernels.BackendTimingInfo
2424
import kernels.KernelBackend
25-
import Engine.ForwardFunc
26-
import Types.TensorContainer
25+
import Engine.{CustomGradientFunc, ForwardFunc, ScopeFn}
26+
import Types.{TensorContainer, TypedArray}
2727
import TensorModule.DataId
28-
import Types._
29-
import Engine.CustomGradientFunc
3028
import org.scalajs.dom.{ImageData, html}
3129
import TensorModule._
3230

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import js.annotation._
2121
import js.{Promise, |}
2222
import Engine.MemoryInfo
2323
import kernels.KernelBackend
24-
24+
import Engine.ScopeFn
25+
import Tensor_types.TensorContainer
26+
import TensorModule.TensorND
2527

2628

2729
@js.native
@@ -48,7 +50,8 @@ class Environment protected () extends js.Object {
4850
}
4951

5052
@js.native
51-
trait EnvironmentCompanion extends js.Object {
53+
@JSGlobal
54+
object Environment extends js.Object {
5255
def setBackend(backendType: String, safeMode: Boolean = ???): Unit = js.native
5356
def getBackend(): String = js.native
5457
def disposeVariables(): Unit = js.native

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,30 @@ import Engine.{ CustomGradientFunc, ScopeFn }
2525

2626
@js.native
2727
trait Globals extends js.Object {
28+
// Start Gradients
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
43+
// End Gradients
44+
// Start Environment
2845
def tidy[T <: TensorContainer](
2946
nameOrFn: String | ScopeFn[T],
3047
fn: ScopeFn[T] = ???,
3148
gradMode: Boolean = ???
3249
): T = js.native
3350
def dispose(container: TensorContainer): Unit = js.native
34-
def keep[T <: Tensor](result: T): T = js.native
51+
def keep[T <: TensorND](result: T): T = js.native
3552
def time(f: js.Function0[Unit]): Promise[TimingInfo] = js.native
53+
// End Environment
3654
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ trait Index
2828
with Train
2929
with Globals
3030
with VariableCompanion
31-
with EnvironmentCompanion
3231
with Version
3332
with BrowserUtil {
3433
type InferenceModel = core.InferenceModel
@@ -51,18 +50,16 @@ trait Index
5150
// TODO Reduction
5251
// Second level exports.
5352
val environment: EnvironmentModule.type = js.native
53+
// Start Environment
54+
def setBackend(backendType: String, safeMode: Boolean = ???): Unit = js.native
55+
def getBackend(): String = js.native
56+
def disposeVariables(): Unit = js.native
57+
def memory(): MemoryInfo = js.native
58+
// End Environment
5459
val io: core.io.io.type = js.native
5560
val serialization: core.serialization.type = js.native
5661
// TODO webgl
62+
val webgl: WebGl = js.native
5763
// TODO backend
5864
// TODO doc
5965
}
60-
61-
@js.native
62-
@JSGlobalScope
63-
object Index extends js.Object {
64-
def setBackend(backendType: String, safeMode: Boolean = ???): Unit = js.native
65-
def getBackend(): String = js.native
66-
def disposeVariables(): Unit = js.native
67-
def memory(): MemoryInfo = js.native
68-
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ import org.scalajs.dom.experimental.RequestInit
2222

2323
import scala.scalajs.js
2424
import js.annotation._
25-
import js.{ Promise, | }
25+
import js.{Promise, |}
2626
import scala.scalajs.js.typedarray.ArrayBuffer
2727

2828
@js.native
2929
@JSImport("@tensorflow/tfjs-core", "io")
30-
object io extends ModelManagement with WeightsLoader {
30+
object io extends ModelManagement {
31+
def loadWeights(
32+
manifest: WeightsManifestConfig,
33+
filePathPrefix: String = ???,
34+
weightNames: js.Array[String] = ???,
35+
requestOptions: RequestInit = ???
36+
): Promise[NamedTensorMap] = js.native
3137
def registerSaveRouter(saveRouter: IORouter): Unit = js.native
3238
def registerLoadRouter(loadRouter: IORouter): Unit = js.native
3339
def getSaveHandlers(url: String): js.Array[IOHandler] = js.native
@@ -38,6 +44,7 @@ object io extends ModelManagement with WeightsLoader {
3844
def encodeWeights(tensors: NamedTensorMap): Promise[js.Any] = js.native
3945
def decodeWeights(buffer: ArrayBuffer, specs: js.Array[WeightsManifestEntry]): NamedTensorMap =
4046
js.native
47+
// TODO browserFiles, concatenateArrayBuffers, fromMemory, getModelArtifactsInfoForJSON
4148
type IOHandler = types.IOHandler
4249
type LoadHandler = types.LoadHandler
4350
type ModelArtifacts = types.ModelArtifacts

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.scalajs.dom.experimental.RequestInit
2626

2727
@js.native
2828
@JSGlobalScope
29-
object Weights_loader extends js.Object {
29+
object WeightsLoader extends js.Object {
3030
def loadWeightsAsArrayBuffer(
3131
fetchURLs: js.Array[String],
3232
requestOptions: RequestInit = ???

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import scala.scalajs.js
2020
import js.annotation._
2121
import js.|
2222
import kernels.KernelBackend
23+
import kernels.MathBackendCPU
2324

2425
@js.native
2526
trait TestEnv extends js.Object {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ trait KernelBackend extends TensorStorage with BackendTimer {
155155
x: T,
156156
blockShape: js.Array[Double],
157157
crops: js.Array[js.Array[Double]]
158-
): T = js.native
158+
): T
159159
def spaceToBatchND[T <: TensorND](
160160
x: T,
161161
blockShape: js.Array[Double],
162162
paddings: js.Array[js.Array[Double]]
163-
): T = js.native
163+
): T
164164
def resizeBilinear(
165165
x: Tensor4D,
166166
newHeight: Double,

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import _root_.io.brunk.tfjs.core.ops.Conv_util.Conv2DInfo
2323

2424
import scala.scalajs.js
2525
import js.annotation._
26-
import js.{ Promise, | }
26+
import js.{Promise, |}
2727
import org.scalajs.dom.html
2828
import org.scalajs.dom
2929

@@ -79,13 +79,19 @@ class MathBackendCPU extends KernelBackend {
7979
def logicalOr(a: TensorND, b: TensorND): TensorND = js.native
8080
def select(condition: TensorND, a: TensorND, b: TensorND): TensorND = js.native
8181
def where(condition: TensorND): Tensor2D = js.native
82+
def where(
83+
condition: TensorND,
84+
a: TensorND,
85+
b: TensorND,
86+
dtype: DataType
87+
): TensorND = js.native
8288
def topk[T <: TensorND](x: T, k: Double, sorted: Boolean): js.Tuple2[T, T] = js.native
8389
def min(x: TensorND, axes: js.Array[Double]): TensorND = js.native
8490
def minimum(a: TensorND, b: TensorND): TensorND = js.native
8591
def mod(a: TensorND, b: TensorND): TensorND = js.native
8692
def max(x: TensorND, axes: js.Array[Double]): TensorND = js.native
8793
def maximum(a: TensorND, b: TensorND): TensorND = js.native
88-
def all(x: TensorND, axes: js.Array[Double]): TensorND = js.native
94+
def all(x: TensorND, axes: js.Array[Double]): TensorND = js.native
8995
def any(x: TensorND, axes: js.Array[Double]): TensorND = js.native
9096
def squaredDifference(a: TensorND, b: TensorND): TensorND = js.native
9197
def ceil[T <: TensorND](x: T): T = js.native
@@ -148,8 +154,9 @@ class MathBackendCPU extends KernelBackend {
148154
def spaceToBatchND[T <: TensorND](
149155
x: T,
150156
blockShape: js.Array[Double],
151-
paddings: js.Array[js.Tuple2[Double, Double]]
152-
): T = js.native
157+
// TODO original impl takes js.Array[js.Tuple2[Double, Double]] here but js.Array[js.Array[Double]] in superclass
158+
paddings: js.Array[js.Array[Double]]
159+
): T = js.native
153160
def maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D = js.native
154161
def maxPoolBackprop(dy: Tensor4D, x: Tensor4D, y: Tensor4D, convInfo: Conv2DInfo): Tensor4D =
155162
js.native

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ import js.|
2626
@JSGlobalScope
2727
object Backend_util extends js.Object {
2828
def castTensor[T <: TensorND](x: T, dtype: DataType, backend: KernelBackend): T = js.native
29-
def reshapeTensor[T <: Tensor[R], R <: Rank](x: T, shape: js.Any): Tensor[R] = js.native
29+
def reshapeTensor[T <: Tensor[R], R <: Rank](x: T, shape: R#Shape): Tensor[R] = js.native
3030
}

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class MathBackendWebGL protected () extends KernelBackend {
104104
bias: Double,
105105
alpha: Double,
106106
beta: Double
107-
): Tensor4D
107+
): Tensor4D = js.native
108108
def tile[T <: TensorND](x: T, reps: js.Array[Double]): T = js.native
109109
def pad[T <: TensorND](
110110
x: T,
@@ -113,16 +113,17 @@ class MathBackendWebGL protected () extends KernelBackend {
113113
): T = js.native
114114
def transpose[T <: TensorND](x: T, perm: js.Array[Double]): T = js.native
115115
def gather[T <: TensorND](x: T, indices: Tensor1D, axis: Double): T = js.native
116-
def batchToSpaceND[T <: Tensor](
116+
def batchToSpaceND[T <: TensorND](
117117
x: T,
118118
blockShape: js.Array[Double],
119119
crops: js.Array[js.Array[Double]]
120120
): T = js.native
121-
def spaceToBatchND[T <: Tensor](
121+
def spaceToBatchND[T <: TensorND](
122122
x: T,
123123
blockShape: js.Array[Double],
124-
paddings: js.Array[js.Tuple2[Double, Double]]
125-
): T = js.native
124+
// TODO original impl takes js.Array[js.Tuple2[Double, Double]] here but js.Array[js.Array[Double]] in superclass
125+
paddings: js.Array[js.Array[Double]]
126+
): T = js.native
126127
def sum(x: TensorND, axes: js.Array[Double]): TensorND = js.native
127128
def unsortedSegmentSum[T <: TensorND](x: T, segmentIds: Tensor1D, numSegments: Double): TensorND =
128129
js.native
@@ -138,21 +139,27 @@ class MathBackendWebGL protected () extends KernelBackend {
138139
def logicalNot[T <: TensorND](x: T): T = js.native
139140
def logicalAnd(a: TensorND, b: TensorND): TensorND = js.native
140141
def logicalOr(a: TensorND, b: TensorND): TensorND = js.native
141-
def where(condition: TensorND, a: TensorND, b: TensorND, dtype: DataType): TensorND = js.native
142-
def topKValues[T <: TensorND](x: T, k: Double): Tensor1D = js.native
143-
def topKIndices(x: TensorND, k: Double): Tensor1D = js.native
142+
def select(condition: TensorND, a: TensorND, b: TensorND): TensorND = js.native
143+
def where(condition: TensorND): Tensor2D = js.native
144+
def where(
145+
condition: TensorND,
146+
a: TensorND,
147+
b: TensorND,
148+
dtype: DataType
149+
): TensorND = js.native
150+
def topk[T <: TensorND](x: T, k: Double, sorted: Boolean): js.Tuple2[T, T] = js.native
144151
def min(x: TensorND, axes: js.Array[Double]): TensorND = js.native
145152
def minimum(a: TensorND, b: TensorND): TensorND = js.native
146153
def mod(a: TensorND, b: TensorND): TensorND = js.native
147154
def max(x: TensorND, axes: js.Array[Double]): TensorND = js.native
148155
def maximum(a: TensorND, b: TensorND): TensorND = js.native
149156
def all(x: TensorND, axes: js.Array[Double]): TensorND = js.native
150-
def any(x: Tensor, axes: js.Array[Double]): Tensor = js.native
157+
def any(x: TensorND, axes: js.Array[Double]): TensorND = js.native
151158
def squaredDifference(a: TensorND, b: TensorND): TensorND = js.native
152159
def realDivide(a: TensorND, b: TensorND): TensorND = js.native
153160
def floorDiv(a: TensorND, b: TensorND): TensorND = js.native
154161
def add(a: TensorND, b: TensorND): TensorND = js.native
155-
def addN[T <: Tensor](tensors: js.Array[T]): T = js.native
162+
def addN[T <: TensorND](tensors: js.Array[T]): T = js.native
156163
def subtract(a: TensorND, b: TensorND): TensorND = js.native
157164
def pow[T <: TensorND](a: T, b: TensorND): T = js.native
158165
def ceil[T <: TensorND](x: T): T = js.native

tfjs-core/src/main/scala/io/brunk/tfjs/core/kernels/webgl/binaryop_gpu.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.brunk.tfjs.core.kernels.webgl
1818

19+
import org.scalajs.dom.webgl
20+
1921
import scala.scalajs.js
2022
import js.annotation._
2123
import js.|
@@ -28,8 +30,8 @@ class BinaryOpProgram protected () extends GPGPUProgram with SupportsBroadasting
2830
var outputShape: js.Array[Double] = js.native
2931
var userCode: String = js.native
3032
//var supportsBroadcasting: Boolean = js.native
31-
var startLoc: WebGLUniformLocation = js.native
32-
def getCustomSetupFunc(): js.Function2[GPGPUContext, WebGLProgram, Unit] = js.native
33+
var startLoc: webgl.UniformLocation = js.native
34+
def getCustomSetupFunc(): js.Function2[GPGPUContext, webgl.Program, Unit] = js.native
3335
}
3436

3537
@js.native

tfjs-core/src/main/scala/io/brunk/tfjs/core/kernels/webgl/gpgpu_context.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package io.brunk.tfjs.core.kernels.webgl
1818

19+
import io.brunk.dom.{WebGLQuery, WebGLSync}
20+
1921
import scala.scalajs.js
2022
import js.annotation._
2123
import js.{Promise, |}
2224
import org.scalajs.dom.webgl
2325
import org.scalajs.dom.html
2426
import org.scalajs.dom
27+
import org.scalajs.dom.experimental.webgl.extensions.WebGLLoseContext
2528

2629
import scala.scalajs.js.typedarray.Float32Array
2730

@@ -36,7 +39,7 @@ trait FenceContext extends js.Object {
3639
class GPGPUContext protected () extends js.Object {
3740
def this(gl: webgl.RenderingContext = ???) = this()
3841
var gl: webgl.RenderingContext = js.native
39-
var loseContextExtension: WebGLLoseContextExtension = js.native
42+
var loseContextExtension: WebGLLoseContext = js.native
4043
var disjointQueryTimerExtension
4144
: WebGL2DisjointQueryTimerExtension | WebGL1DisjointQueryTimerExtension = js.native
4245
var vertexBuffer: webgl.Buffer = js.native
@@ -146,6 +149,6 @@ class GPGPUContext protected () extends js.Object {
146149

147150
@js.native
148151
@JSGlobalScope
149-
object Gpgpu_context extends js.Object {
152+
object GPGPUContextModule extends js.Object {
150153
def binSearchLastTrue(arr: js.Array[js.Function0[Boolean]]): Double = js.native
151154
}

0 commit comments

Comments
 (0)