From 19cfb67768015694fc8980cbe4dda3d2602fbc85 Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Tue, 30 Jun 2020 18:22:10 -0400 Subject: [PATCH 1/6] chain all the chain ops. --- tfjs-core/src/backends/backend_util.ts | 2 +- tfjs-core/src/engine.ts | 3 +- tfjs-core/src/public/chained_ops/abs.ts | 33 ++ tfjs-core/src/public/chained_ops/acos.ts | 33 ++ tfjs-core/src/public/chained_ops/acosh.ts | 33 ++ .../src/public/chained_ops/add_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/arg_max.ts | 33 ++ tfjs-core/src/public/chained_ops/arg_min.ts | 33 ++ tfjs-core/src/public/chained_ops/as1d.ts | 35 ++ tfjs-core/src/public/chained_ops/as2d.ts | 41 ++ tfjs-core/src/public/chained_ops/as3d.ts | 43 ++ tfjs-core/src/public/chained_ops/as4d.ts | 44 ++ tfjs-core/src/public/chained_ops/as5d.ts | 47 ++ tfjs-core/src/public/chained_ops/as_scalar.ts | 36 ++ tfjs-core/src/public/chained_ops/as_type.ts | 40 ++ tfjs-core/src/public/chained_ops/asin.ts | 33 ++ tfjs-core/src/public/chained_ops/asinh.ts | 33 ++ tfjs-core/src/public/chained_ops/atan.ts | 33 ++ tfjs-core/src/public/chained_ops/atanh.ts | 33 ++ tfjs-core/src/public/chained_ops/cast.ts | 33 ++ tfjs-core/src/public/chained_ops/ceil.ts | 33 ++ .../src/public/chained_ops/clip_by_value.ts | 34 ++ tfjs-core/src/public/chained_ops/cos.ts | 33 ++ tfjs-core/src/public/chained_ops/cosh.ts | 33 ++ .../src/public/chained_ops/div_strict.ts | 34 ++ .../src/public/chained_ops/equal_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/erf.ts | 33 ++ tfjs-core/src/public/chained_ops/exp.ts | 33 ++ tfjs-core/src/public/chained_ops/expm1.ts | 33 ++ tfjs-core/src/public/chained_ops/fft.ts | 33 ++ tfjs-core/src/public/chained_ops/flatten.ts | 35 ++ tfjs-core/src/public/chained_ops/floor.ts | 33 ++ tfjs-core/src/public/chained_ops/gather.ts | 35 ++ .../chained_ops/greater_equal_strict.ts | 37 ++ .../src/public/chained_ops/greater_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/ifft.ts | 33 ++ tfjs-core/src/public/chained_ops/irfft.ts | 33 ++ tfjs-core/src/public/chained_ops/is_finite.ts | 33 ++ tfjs-core/src/public/chained_ops/is_inf.ts | 33 ++ tfjs-core/src/public/chained_ops/is_nan.ts | 33 ++ .../public/chained_ops/less_equal_strict.ts | 37 ++ .../src/public/chained_ops/less_strict.ts | 34 ++ tfjs-core/src/public/chained_ops/log.ts | 33 ++ tfjs-core/src/public/chained_ops/log1p.ts | 33 ++ .../src/public/chained_ops/log_sigmoid.ts | 33 ++ .../src/public/chained_ops/log_softmax.ts | 34 ++ .../src/public/chained_ops/maximum_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/mean.ts | 34 ++ tfjs-core/src/public/chained_ops/min.ts | 34 ++ .../src/public/chained_ops/minimum_strict.ts | 37 ++ .../src/public/chained_ops/mod_strict.ts | 37 ++ .../src/public/chained_ops/mul_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/neg.ts | 33 ++ tfjs-core/src/public/chained_ops/norm.ts | 37 ++ .../public/chained_ops/not_equal_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/ones_like.ts | 33 ++ .../src/public/chained_ops/pow_strict.ts | 36 ++ .../src/public/chained_ops/reciprocal.ts | 33 ++ .../chained_ops/register_all_chained_ops.ts | 103 +++- .../register_all_chained_ops_test.ts | 88 ++- .../src/public/chained_ops/reshape_as.ts | 39 ++ tfjs-core/src/public/chained_ops/rfft.ts | 33 ++ tfjs-core/src/public/chained_ops/round.ts | 33 ++ tfjs-core/src/public/chained_ops/rsqrt.ts | 33 ++ tfjs-core/src/public/chained_ops/sigmoid.ts | 33 ++ tfjs-core/src/public/chained_ops/sign.ts | 33 ++ tfjs-core/src/public/chained_ops/sin.ts | 33 ++ tfjs-core/src/public/chained_ops/sinh.ts | 33 ++ tfjs-core/src/public/chained_ops/slice.ts | 35 ++ tfjs-core/src/public/chained_ops/softmax.ts | 33 ++ tfjs-core/src/public/chained_ops/softplus.ts | 33 ++ tfjs-core/src/public/chained_ops/sqrt.ts | 33 ++ tfjs-core/src/public/chained_ops/square.ts | 33 ++ .../chained_ops/squared_difference_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/step.ts | 33 ++ .../src/public/chained_ops/strided_slice.ts | 41 ++ .../src/public/chained_ops/sub_strict.ts | 37 ++ tfjs-core/src/public/chained_ops/sum.ts | 34 ++ tfjs-core/src/public/chained_ops/tan.ts | 33 ++ tfjs-core/src/public/chained_ops/tanh.ts | 33 ++ tfjs-core/src/public/chained_ops/to_bool.ts | 33 ++ tfjs-core/src/public/chained_ops/to_float.ts | 33 ++ tfjs-core/src/public/chained_ops/to_int.ts | 33 ++ tfjs-core/src/public/chained_ops/topk.ts | 34 ++ .../chained_ops/unsorted_segment_sum.ts | 35 ++ .../src/public/chained_ops/zeros_like.ts | 33 ++ tfjs-core/src/tensor.ts | 550 +----------------- 87 files changed, 3029 insertions(+), 563 deletions(-) create mode 100644 tfjs-core/src/public/chained_ops/abs.ts create mode 100644 tfjs-core/src/public/chained_ops/acos.ts create mode 100644 tfjs-core/src/public/chained_ops/acosh.ts create mode 100644 tfjs-core/src/public/chained_ops/add_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/arg_max.ts create mode 100644 tfjs-core/src/public/chained_ops/arg_min.ts create mode 100644 tfjs-core/src/public/chained_ops/as1d.ts create mode 100644 tfjs-core/src/public/chained_ops/as2d.ts create mode 100644 tfjs-core/src/public/chained_ops/as3d.ts create mode 100644 tfjs-core/src/public/chained_ops/as4d.ts create mode 100644 tfjs-core/src/public/chained_ops/as5d.ts create mode 100644 tfjs-core/src/public/chained_ops/as_scalar.ts create mode 100644 tfjs-core/src/public/chained_ops/as_type.ts create mode 100644 tfjs-core/src/public/chained_ops/asin.ts create mode 100644 tfjs-core/src/public/chained_ops/asinh.ts create mode 100644 tfjs-core/src/public/chained_ops/atan.ts create mode 100644 tfjs-core/src/public/chained_ops/atanh.ts create mode 100644 tfjs-core/src/public/chained_ops/cast.ts create mode 100644 tfjs-core/src/public/chained_ops/ceil.ts create mode 100644 tfjs-core/src/public/chained_ops/clip_by_value.ts create mode 100644 tfjs-core/src/public/chained_ops/cos.ts create mode 100644 tfjs-core/src/public/chained_ops/cosh.ts create mode 100644 tfjs-core/src/public/chained_ops/div_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/equal_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/erf.ts create mode 100644 tfjs-core/src/public/chained_ops/exp.ts create mode 100644 tfjs-core/src/public/chained_ops/expm1.ts create mode 100644 tfjs-core/src/public/chained_ops/fft.ts create mode 100644 tfjs-core/src/public/chained_ops/flatten.ts create mode 100644 tfjs-core/src/public/chained_ops/floor.ts create mode 100644 tfjs-core/src/public/chained_ops/gather.ts create mode 100644 tfjs-core/src/public/chained_ops/greater_equal_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/greater_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/ifft.ts create mode 100644 tfjs-core/src/public/chained_ops/irfft.ts create mode 100644 tfjs-core/src/public/chained_ops/is_finite.ts create mode 100644 tfjs-core/src/public/chained_ops/is_inf.ts create mode 100644 tfjs-core/src/public/chained_ops/is_nan.ts create mode 100644 tfjs-core/src/public/chained_ops/less_equal_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/less_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/log.ts create mode 100644 tfjs-core/src/public/chained_ops/log1p.ts create mode 100644 tfjs-core/src/public/chained_ops/log_sigmoid.ts create mode 100644 tfjs-core/src/public/chained_ops/log_softmax.ts create mode 100644 tfjs-core/src/public/chained_ops/maximum_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/mean.ts create mode 100644 tfjs-core/src/public/chained_ops/min.ts create mode 100644 tfjs-core/src/public/chained_ops/minimum_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/mod_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/mul_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/neg.ts create mode 100644 tfjs-core/src/public/chained_ops/norm.ts create mode 100644 tfjs-core/src/public/chained_ops/not_equal_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/ones_like.ts create mode 100644 tfjs-core/src/public/chained_ops/pow_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/reciprocal.ts create mode 100644 tfjs-core/src/public/chained_ops/reshape_as.ts create mode 100644 tfjs-core/src/public/chained_ops/rfft.ts create mode 100644 tfjs-core/src/public/chained_ops/round.ts create mode 100644 tfjs-core/src/public/chained_ops/rsqrt.ts create mode 100644 tfjs-core/src/public/chained_ops/sigmoid.ts create mode 100644 tfjs-core/src/public/chained_ops/sign.ts create mode 100644 tfjs-core/src/public/chained_ops/sin.ts create mode 100644 tfjs-core/src/public/chained_ops/sinh.ts create mode 100644 tfjs-core/src/public/chained_ops/slice.ts create mode 100644 tfjs-core/src/public/chained_ops/softmax.ts create mode 100644 tfjs-core/src/public/chained_ops/softplus.ts create mode 100644 tfjs-core/src/public/chained_ops/sqrt.ts create mode 100644 tfjs-core/src/public/chained_ops/square.ts create mode 100644 tfjs-core/src/public/chained_ops/squared_difference_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/step.ts create mode 100644 tfjs-core/src/public/chained_ops/strided_slice.ts create mode 100644 tfjs-core/src/public/chained_ops/sub_strict.ts create mode 100644 tfjs-core/src/public/chained_ops/sum.ts create mode 100644 tfjs-core/src/public/chained_ops/tan.ts create mode 100644 tfjs-core/src/public/chained_ops/tanh.ts create mode 100644 tfjs-core/src/public/chained_ops/to_bool.ts create mode 100644 tfjs-core/src/public/chained_ops/to_float.ts create mode 100644 tfjs-core/src/public/chained_ops/to_int.ts create mode 100644 tfjs-core/src/public/chained_ops/topk.ts create mode 100644 tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts create mode 100644 tfjs-core/src/public/chained_ops/zeros_like.ts diff --git a/tfjs-core/src/backends/backend_util.ts b/tfjs-core/src/backends/backend_util.ts index 8dae7b09586..901d96fa2b5 100644 --- a/tfjs-core/src/backends/backend_util.ts +++ b/tfjs-core/src/backends/backend_util.ts @@ -69,7 +69,7 @@ export function castTensor( const real = backend.real(x); const result = real.cast(dtype); real.dispose(); - return result; + return result as T; } if (dtype === 'int32') { return backend.int(x); diff --git a/tfjs-core/src/engine.ts b/tfjs-core/src/engine.ts index 4ee48fa5a10..164a21af24e 100644 --- a/tfjs-core/src/engine.ts +++ b/tfjs-core/src/engine.ts @@ -19,6 +19,7 @@ import {BackendTimingInfo, DataMover, KernelBackend} from './backends/backend'; import {Environment, setEnvironmentGlobal} from './environment'; import {getGlobalNamespace} from './global_util'; import {getGradient, getKernel, getKernelsForBackend, GradFunc, NamedAttrMap, TensorInfo} from './kernel_registry'; +import {cast} from './ops/ops'; import {Profiler} from './profiler'; import {backpropagateGradients, getFilteredNodesXToY, TapeNode} from './tape'; import {DataId, setTensorTracker, Tensor, TensorTracker, Variable} from './tensor'; @@ -743,7 +744,7 @@ export class Engine implements TensorTracker, DataMover { dtype?: DataType): Variable { name = name || this.nextVariableId().toString(); if (dtype != null && dtype !== initialValue.dtype) { - initialValue = initialValue.asType(dtype); + initialValue = cast(initialValue, dtype); } const v = new Variable(initialValue, trainable, name, this.nextTensorId()); if (this.state.registeredVariables[v.name] != null) { diff --git a/tfjs-core/src/public/chained_ops/abs.ts b/tfjs-core/src/public/chained_ops/abs.ts new file mode 100644 index 00000000000..4e416c5181c --- /dev/null +++ b/tfjs-core/src/public/chained_ops/abs.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {abs} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + abs(this: T): T; + } +} + +Tensor.prototype.abs = function(this: T) { + this.throwIfDisposed(); + return abs(this); +}; diff --git a/tfjs-core/src/public/chained_ops/acos.ts b/tfjs-core/src/public/chained_ops/acos.ts new file mode 100644 index 00000000000..bddbe5aba0a --- /dev/null +++ b/tfjs-core/src/public/chained_ops/acos.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {acos} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + acos(this: T): T; + } +} + +Tensor.prototype.acos = function(this: T) { + this.throwIfDisposed(); + return acos(this); +}; diff --git a/tfjs-core/src/public/chained_ops/acosh.ts b/tfjs-core/src/public/chained_ops/acosh.ts new file mode 100644 index 00000000000..e53b5cb6a8d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/acosh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {acosh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + acosh(this: T): T; + } +} + +Tensor.prototype.acosh = function(this: T) { + this.throwIfDisposed(); + return acosh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/add_strict.ts b/tfjs-core/src/public/chained_ops/add_strict.ts new file mode 100644 index 00000000000..96b82cf7723 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/add_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {addStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + addStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.addStrict = function( + this: T, x: T|TensorLike) { + this.throwIfDisposed(); + return addStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/arg_max.ts b/tfjs-core/src/public/chained_ops/arg_max.ts new file mode 100644 index 00000000000..23096b92da3 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/arg_max.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {argMax} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + argMax(axis?: number): T; + } +} + +Tensor.prototype.argMax = function(axis?: number): T { + this.throwIfDisposed(); + return argMax(this, axis); +}; diff --git a/tfjs-core/src/public/chained_ops/arg_min.ts b/tfjs-core/src/public/chained_ops/arg_min.ts new file mode 100644 index 00000000000..cf57a5ea8c6 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/arg_min.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {argMin} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + argMin(axis?: number): T; + } +} + +Tensor.prototype.argMin = function(axis: number): T { + this.throwIfDisposed(); + return argMin(this, axis); +}; diff --git a/tfjs-core/src/public/chained_ops/as1d.ts b/tfjs-core/src/public/chained_ops/as1d.ts new file mode 100644 index 00000000000..8fcc0df46bd --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as1d.ts @@ -0,0 +1,35 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + as1D(): Tensor1D; + } +} + +/** Converts a `tf.Tensor` to a `tf.Tensor1D`. */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.as1D = function(): T { + this.throwIfDisposed(); + return reshape(this, [this.size]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/as2d.ts b/tfjs-core/src/public/chained_ops/as2d.ts new file mode 100644 index 00000000000..229fe03b122 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as2d.ts @@ -0,0 +1,41 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + as2D(rows: number, columns: number): Tensor2D; + } +} + +/** + * Converts a `tf.Tensor` to a `tf.Tensor2D`. + * + * @param rows Number of rows in `tf.Tensor2D`. + * @param columns Number of columns in `tf.Tensor2D`. + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.as2D = function( + rows: number, columns: number): T { + this.throwIfDisposed(); + return reshape(this, [rows, columns]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/as3d.ts b/tfjs-core/src/public/chained_ops/as3d.ts new file mode 100644 index 00000000000..1364dc4021d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as3d.ts @@ -0,0 +1,43 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + as3D(rows: number, columns: number, depth: number): + Tensor3D; + } +} + +/** + * Converts a `tf.Tensor` to a `tf.Tensor3D`. + * + * @param rows Number of rows in `tf.Tensor3D`. + * @param columns Number of columns in `tf.Tensor3D`. + * @param depth Depth of `tf.Tensor3D`. + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.as3D = function( + rows: number, columns: number, depth: number): T { + this.throwIfDisposed(); + return reshape(this, [rows, columns, depth]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/as4d.ts b/tfjs-core/src/public/chained_ops/as4d.ts new file mode 100644 index 00000000000..88ac7df9cae --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as4d.ts @@ -0,0 +1,44 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + as4D( + rows: number, columns: number, depth: number, depth2: number): Tensor4D; + } +} + +/** + * Converts a `tf.Tensor` to a `tf.Tensor4D`. + * + * @param rows Number of rows in `tf.Tensor4D`. + * @param columns Number of columns in `tf.Tensor4D`. + * @param depth Depth of `tf.Tensor4D`. + * @param depth2 4th dimension of `tf.Tensor4D`. + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.as4D = function( + rows: number, columns: number, depth: number, depth2: number): T { + this.throwIfDisposed(); + return reshape(this, [rows, columns, depth, depth2]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/as5d.ts b/tfjs-core/src/public/chained_ops/as5d.ts new file mode 100644 index 00000000000..f3f970b2b6f --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as5d.ts @@ -0,0 +1,47 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + as5D( + rows: number, columns: number, depth: number, depth2: number, + depth3: number): Tensor5D; + } +} + +/** + * Converts a `tf.Tensor` to a `tf.Tensor5D`. + * + * @param rows Number of rows in `tf.Tensor5D`. + * @param columns Number of columns in `tf.Tensor5D`. + * @param depth Depth of `tf.Tensor5D`. + * @param depth2 4th dimension of `tf.Tensor5D`. + * @param depth3 5th dimension of 'tf.Tensor5D' + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.as5D = function( + rows: number, columns: number, depth: number, depth2: number, + depth3: number): T { + this.throwIfDisposed(); + return reshape(this, [rows, columns, depth, depth2, depth3]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/as_scalar.ts b/tfjs-core/src/public/chained_ops/as_scalar.ts new file mode 100644 index 00000000000..fbeede9c025 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as_scalar.ts @@ -0,0 +1,36 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +import {reshape} from '../../ops/reshape'; +import {Scalar, Tensor} from '../../tensor'; +import {Rank} from '../../types'; +import {assert} from '../../util'; + +declare module '../../tensor' { + interface Tensor { + asScalar(): Scalar; + } +} + +/** Converts a size-1 `tf.Tensor` to a `tf.Scalar`. */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.asScalar = function(this: T): Scalar { + this.throwIfDisposed(); + assert(this.size === 1, () => 'The array must have only 1 element.'); + return reshape(this, []); +}; diff --git a/tfjs-core/src/public/chained_ops/as_type.ts b/tfjs-core/src/public/chained_ops/as_type.ts new file mode 100644 index 00000000000..26ad3bf2935 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/as_type.ts @@ -0,0 +1,40 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cast} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {DataType, Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + asType(this: T, dtype: DataType): T; + } +} + +/** + * Casts a `tf.Tensor` to a specified dtype. + * + * @param dtype Data-type to cast the tensor to. + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.asType = function( + this: T, dtype: DataType): T { + this.throwIfDisposed(); + return cast(this, dtype); +}; diff --git a/tfjs-core/src/public/chained_ops/asin.ts b/tfjs-core/src/public/chained_ops/asin.ts new file mode 100644 index 00000000000..3d6df5fa399 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/asin.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {asin} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + asin(this: T): T; + } +} + +Tensor.prototype.asin = function(this: T): T { + this.throwIfDisposed(); + return asin(this); +}; diff --git a/tfjs-core/src/public/chained_ops/asinh.ts b/tfjs-core/src/public/chained_ops/asinh.ts new file mode 100644 index 00000000000..0e14938749a --- /dev/null +++ b/tfjs-core/src/public/chained_ops/asinh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {asinh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + asinh(this: T): T; + } +} + +Tensor.prototype.asinh = function(this: T): T { + this.throwIfDisposed(); + return asinh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/atan.ts b/tfjs-core/src/public/chained_ops/atan.ts new file mode 100644 index 00000000000..fe37adec892 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/atan.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {atan} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + atan(this: T): T; + } +} + +Tensor.prototype.atan = function(this: T): T { + this.throwIfDisposed(); + return atan(this); +}; diff --git a/tfjs-core/src/public/chained_ops/atanh.ts b/tfjs-core/src/public/chained_ops/atanh.ts new file mode 100644 index 00000000000..c5241795826 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/atanh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {atanh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + atanh(this: T): T; + } +} + +Tensor.prototype.atanh = function(this: T): T { + this.throwIfDisposed(); + return atanh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/cast.ts b/tfjs-core/src/public/chained_ops/cast.ts new file mode 100644 index 00000000000..653df4a2711 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/cast.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cast} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {DataType, Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + cast(dtype: DataType): T; + } +} + +Tensor.prototype.cast = function(dtype: DataType): T { + this.throwIfDisposed(); + return cast(this, dtype) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/ceil.ts b/tfjs-core/src/public/chained_ops/ceil.ts new file mode 100644 index 00000000000..e1ac3494edd --- /dev/null +++ b/tfjs-core/src/public/chained_ops/ceil.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {ceil} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + ceil(this: T): T; + } +} + +Tensor.prototype.ceil = function(this: T): T { + this.throwIfDisposed(); + return ceil(this); +}; diff --git a/tfjs-core/src/public/chained_ops/clip_by_value.ts b/tfjs-core/src/public/chained_ops/clip_by_value.ts new file mode 100644 index 00000000000..f4aa819faa1 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/clip_by_value.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {clipByValue} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + clipByValue(min: number, max: number): Tensor; + } +} + +Tensor.prototype.clipByValue = function( + min: number, max: number): T { + this.throwIfDisposed(); + return clipByValue(this, min, max) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/cos.ts b/tfjs-core/src/public/chained_ops/cos.ts new file mode 100644 index 00000000000..5241a43c0c1 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/cos.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cos} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + cos(this: T): T; + } +} + +Tensor.prototype.cos = function(this: T): T { + this.throwIfDisposed(); + return cos(this); +}; diff --git a/tfjs-core/src/public/chained_ops/cosh.ts b/tfjs-core/src/public/chained_ops/cosh.ts new file mode 100644 index 00000000000..b53a75cc0d5 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/cosh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cosh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + cosh(this: T): T; + } +} + +Tensor.prototype.cosh = function(this: T): T { + this.throwIfDisposed(); + return cosh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/div_strict.ts b/tfjs-core/src/public/chained_ops/div_strict.ts new file mode 100644 index 00000000000..1ee330ad412 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/div_strict.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {divStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + divStrict(this: T, x: T|TensorLike): T; + } +} + +Tensor.prototype.divStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return divStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/equal_strict.ts b/tfjs-core/src/public/chained_ops/equal_strict.ts new file mode 100644 index 00000000000..4ca91e67196 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/equal_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {equalStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + equalStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.equalStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return equalStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/erf.ts b/tfjs-core/src/public/chained_ops/erf.ts new file mode 100644 index 00000000000..941d863fa40 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/erf.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {erf} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + erf(this: T): T; + } +} + +Tensor.prototype.erf = function(this: T): T { + this.throwIfDisposed(); + return erf(this); +}; diff --git a/tfjs-core/src/public/chained_ops/exp.ts b/tfjs-core/src/public/chained_ops/exp.ts new file mode 100644 index 00000000000..de2837e41ef --- /dev/null +++ b/tfjs-core/src/public/chained_ops/exp.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {exp} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + exp(this: T): T; + } +} + +Tensor.prototype.exp = function(this: T): T { + this.throwIfDisposed(); + return exp(this); +}; diff --git a/tfjs-core/src/public/chained_ops/expm1.ts b/tfjs-core/src/public/chained_ops/expm1.ts new file mode 100644 index 00000000000..5d36996a053 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/expm1.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {expm1} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + expm1(this: T): T; + } +} + +Tensor.prototype.expm1 = function(this: T): T { + this.throwIfDisposed(); + return expm1(this); +}; diff --git a/tfjs-core/src/public/chained_ops/fft.ts b/tfjs-core/src/public/chained_ops/fft.ts new file mode 100644 index 00000000000..ce06dea3a74 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/fft.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {fft} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + fft(this: Tensor): Tensor; + } +} + +Tensor.prototype.fft = function(this: Tensor): T { + this.throwIfDisposed(); + return fft(this) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/flatten.ts b/tfjs-core/src/public/chained_ops/flatten.ts new file mode 100644 index 00000000000..4110ef91aea --- /dev/null +++ b/tfjs-core/src/public/chained_ops/flatten.ts @@ -0,0 +1,35 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + flatten(): Tensor1D; + } +} + +/** Flatten a Tensor to a 1D array. */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.flatten = function(): T { + this.throwIfDisposed(); + return reshape(this, [this.size]) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/floor.ts b/tfjs-core/src/public/chained_ops/floor.ts new file mode 100644 index 00000000000..6c123638ca4 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/floor.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {floor} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + floor(this: T): T; + } +} + +Tensor.prototype.floor = function(this: T): T { + this.throwIfDisposed(); + return floor(this); +}; diff --git a/tfjs-core/src/public/chained_ops/gather.ts b/tfjs-core/src/public/chained_ops/gather.ts new file mode 100644 index 00000000000..5b8c52dc6af --- /dev/null +++ b/tfjs-core/src/public/chained_ops/gather.ts @@ -0,0 +1,35 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {gather} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + gather( + this: T, indices: Tensor|TensorLike, axis?: number): T; + } +} + +Tensor.prototype.gather = function( + this: T, indices: Tensor|TensorLike, axis?: number): T { + this.throwIfDisposed(); + return gather(this, indices, axis); +}; diff --git a/tfjs-core/src/public/chained_ops/greater_equal_strict.ts b/tfjs-core/src/public/chained_ops/greater_equal_strict.ts new file mode 100644 index 00000000000..3fb276edac2 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/greater_equal_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {greaterEqualStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + greaterEqualStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.greaterEqualStrict = function( + this: T, x: T|TensorLike) { + this.throwIfDisposed(); + return greaterEqualStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/greater_strict.ts b/tfjs-core/src/public/chained_ops/greater_strict.ts new file mode 100644 index 00000000000..7fe2c1643b4 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/greater_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {greaterStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + greaterStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.greaterStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return greaterStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/ifft.ts b/tfjs-core/src/public/chained_ops/ifft.ts new file mode 100644 index 00000000000..d059cec6181 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/ifft.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {ifft} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + ifft(this: Tensor): Tensor; + } +} + +Tensor.prototype.ifft = function(this: Tensor): T { + this.throwIfDisposed(); + return ifft(this) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/irfft.ts b/tfjs-core/src/public/chained_ops/irfft.ts new file mode 100644 index 00000000000..dc26b10c22d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/irfft.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {irfft} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + irfft(this: Tensor): Tensor; + } +} + +Tensor.prototype.irfft = function(this: Tensor): T { + this.throwIfDisposed(); + return irfft(this) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/is_finite.ts b/tfjs-core/src/public/chained_ops/is_finite.ts new file mode 100644 index 00000000000..c93d5be6a35 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/is_finite.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {isFinite} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + isFinite(this: T): T; + } +} + +Tensor.prototype.isFinite = function(this: T): T { + this.throwIfDisposed(); + return isFinite(this); +}; diff --git a/tfjs-core/src/public/chained_ops/is_inf.ts b/tfjs-core/src/public/chained_ops/is_inf.ts new file mode 100644 index 00000000000..97e35eadfcf --- /dev/null +++ b/tfjs-core/src/public/chained_ops/is_inf.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {isInf} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + isInf(this: T): T; + } +} + +Tensor.prototype.isInf = function(this: T): T { + this.throwIfDisposed(); + return isInf(this); +}; diff --git a/tfjs-core/src/public/chained_ops/is_nan.ts b/tfjs-core/src/public/chained_ops/is_nan.ts new file mode 100644 index 00000000000..96f7393d01a --- /dev/null +++ b/tfjs-core/src/public/chained_ops/is_nan.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {isNaN} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + isNaN(this: T): T; + } +} + +Tensor.prototype.isNaN = function(this: T): T { + this.throwIfDisposed(); + return isNaN(this); +}; diff --git a/tfjs-core/src/public/chained_ops/less_equal_strict.ts b/tfjs-core/src/public/chained_ops/less_equal_strict.ts new file mode 100644 index 00000000000..9d8b40ecef7 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/less_equal_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {lessEqualStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + lessEqualStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.lessEqualStrict = function( + this: T, x: T|TensorLike) { + this.throwIfDisposed(); + return lessEqualStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/less_strict.ts b/tfjs-core/src/public/chained_ops/less_strict.ts new file mode 100644 index 00000000000..f8b0507606d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/less_strict.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {lessStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + lessStrict(this: T, x: T|TensorLike): T; + } +} + +Tensor.prototype.lessStrict = function( + this: T, x: T|TensorLike) { + this.throwIfDisposed(); + return lessStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/log.ts b/tfjs-core/src/public/chained_ops/log.ts new file mode 100644 index 00000000000..4df7964e53b --- /dev/null +++ b/tfjs-core/src/public/chained_ops/log.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {log} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + log(this: T): T; + } +} + +Tensor.prototype.log = function(this: T): T { + this.throwIfDisposed(); + return log(this); +}; diff --git a/tfjs-core/src/public/chained_ops/log1p.ts b/tfjs-core/src/public/chained_ops/log1p.ts new file mode 100644 index 00000000000..3deed8de998 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/log1p.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {log1p} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + log1p(this: T): T; + } +} + +Tensor.prototype.log1p = function(this: T): T { + this.throwIfDisposed(); + return log1p(this); +}; diff --git a/tfjs-core/src/public/chained_ops/log_sigmoid.ts b/tfjs-core/src/public/chained_ops/log_sigmoid.ts new file mode 100644 index 00000000000..50720581927 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/log_sigmoid.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {logSigmoid} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + logSigmoid(this: T): T; + } +} + +Tensor.prototype.logSigmoid = function(this: T): T { + this.throwIfDisposed(); + return logSigmoid(this); +}; diff --git a/tfjs-core/src/public/chained_ops/log_softmax.ts b/tfjs-core/src/public/chained_ops/log_softmax.ts new file mode 100644 index 00000000000..a2460dcfb63 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/log_softmax.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {logSoftmax} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + logSoftmax(this: T, axis?: number): T; + } +} + +Tensor.prototype.logSoftmax = function( + this: T, axis?: number): T { + this.throwIfDisposed(); + return logSoftmax(this, axis); +}; diff --git a/tfjs-core/src/public/chained_ops/maximum_strict.ts b/tfjs-core/src/public/chained_ops/maximum_strict.ts new file mode 100644 index 00000000000..6a035f99057 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/maximum_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {maximumStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + maximumStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.maximumStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return maximumStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/mean.ts b/tfjs-core/src/public/chained_ops/mean.ts new file mode 100644 index 00000000000..acbc58e757b --- /dev/null +++ b/tfjs-core/src/public/chained_ops/mean.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {mean} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + mean(axis?: number|number[], keepDims?: boolean): T; + } +} + +Tensor.prototype.mean = function( + axis?: number|number[], keepDims?: boolean): T { + this.throwIfDisposed(); + return mean(this, axis, keepDims); +}; diff --git a/tfjs-core/src/public/chained_ops/min.ts b/tfjs-core/src/public/chained_ops/min.ts new file mode 100644 index 00000000000..4094b36945e --- /dev/null +++ b/tfjs-core/src/public/chained_ops/min.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {min} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + min(axis?: number|number[], keepDims?: boolean): T; + } +} + +Tensor.prototype.min = function( + axis?: number|number[], keepDims?: boolean) { + this.throwIfDisposed(); + return min(this, axis, keepDims); +}; diff --git a/tfjs-core/src/public/chained_ops/minimum_strict.ts b/tfjs-core/src/public/chained_ops/minimum_strict.ts new file mode 100644 index 00000000000..b3486448a3e --- /dev/null +++ b/tfjs-core/src/public/chained_ops/minimum_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {minimumStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + minimumStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.minimumStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return minimumStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/mod_strict.ts b/tfjs-core/src/public/chained_ops/mod_strict.ts new file mode 100644 index 00000000000..74585edb127 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/mod_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {modStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + modStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.modStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return modStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/mul_strict.ts b/tfjs-core/src/public/chained_ops/mul_strict.ts new file mode 100644 index 00000000000..f3b6825f1c4 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/mul_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {mulStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + mulStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.mulStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return mulStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/neg.ts b/tfjs-core/src/public/chained_ops/neg.ts new file mode 100644 index 00000000000..86f1b513425 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/neg.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {neg} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + neg(this: T): T; + } +} + +Tensor.prototype.neg = function(this: T): T { + this.throwIfDisposed(); + return neg(this); +}; diff --git a/tfjs-core/src/public/chained_ops/norm.ts b/tfjs-core/src/public/chained_ops/norm.ts new file mode 100644 index 00000000000..12d49ebda3f --- /dev/null +++ b/tfjs-core/src/public/chained_ops/norm.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {norm} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + norm( + ord?: number|'euclidean'|'fro', axis?: number|number[], + keepDims?: boolean): Tensor; + } +} + +Tensor.prototype.norm = function( + ord?: number|'euclidean'|'fro', axis?: number|number[], + keepDims?: boolean) { + this.throwIfDisposed(); + return norm(this, ord, axis, keepDims) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/not_equal_strict.ts b/tfjs-core/src/public/chained_ops/not_equal_strict.ts new file mode 100644 index 00000000000..37ba97becaf --- /dev/null +++ b/tfjs-core/src/public/chained_ops/not_equal_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {notEqualStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + notEqualStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.notEqualStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return notEqualStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/ones_like.ts b/tfjs-core/src/public/chained_ops/ones_like.ts new file mode 100644 index 00000000000..d1658364bba --- /dev/null +++ b/tfjs-core/src/public/chained_ops/ones_like.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {onesLike} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + onesLike(this: T): T; + } +} + +Tensor.prototype.onesLike = function(this: T): T { + this.throwIfDisposed(); + return onesLike(this); +}; diff --git a/tfjs-core/src/public/chained_ops/pow_strict.ts b/tfjs-core/src/public/chained_ops/pow_strict.ts new file mode 100644 index 00000000000..619f933b365 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/pow_strict.ts @@ -0,0 +1,36 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {powStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + powStrict(exp: Tensor): Tensor; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.powStrict = function(exp: Tensor): T { + this.throwIfDisposed(); + return powStrict(this, exp) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/reciprocal.ts b/tfjs-core/src/public/chained_ops/reciprocal.ts new file mode 100644 index 00000000000..d9b9467b66c --- /dev/null +++ b/tfjs-core/src/public/chained_ops/reciprocal.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reciprocal} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + reciprocal(this: T): T; + } +} + +Tensor.prototype.reciprocal = function(this: T): T { + this.throwIfDisposed(); + return reciprocal(this); +}; diff --git a/tfjs-core/src/public/chained_ops/register_all_chained_ops.ts b/tfjs-core/src/public/chained_ops/register_all_chained_ops.ts index d9b725d28b9..8aa5702ac7b 100644 --- a/tfjs-core/src/public/chained_ops/register_all_chained_ops.ts +++ b/tfjs-core/src/public/chained_ops/register_all_chained_ops.ts @@ -14,70 +14,153 @@ * limitations under the License. * ============================================================================= */ + +import './abs'; +import './acos'; +import './acosh'; +import './add_strict'; import './add'; import './all'; import './any'; +import './arg_max'; +import './arg_min'; +import './as_scalar'; +import './as_type'; +import './as1d'; +import './as2d'; +import './as3d'; +import './as4d'; +import './as5d'; +import './asin'; +import './asinh'; +import './atan'; import './atan2'; +import './atanh'; import './avg_pool'; +import './batch_to_space_nd'; import './batchnorm'; import './broadcast_to'; -import './batch_to_space_nd'; +import './cast'; +import './ceil'; +import './clip_by_value'; import './concat'; import './conv1d'; -import './conv2d'; import './conv2d_transpose'; +import './conv2d'; +import './cos'; +import './cosh'; import './cumsum'; import './depth_to_space'; -import './depthwise_conv2d'; import './depthwise_conv2D_deprecated'; +import './depthwise_conv2d'; import './dilation2d'; -import './div'; import './div_no_nan'; +import './div_strict'; +import './div'; import './dot'; import './elu'; +import './equal_strict'; import './equal'; +import './erf'; +import './exp'; import './expand_dims'; +import './expm1'; +import './fft'; +import './flatten'; +import './floor'; import './floorDiv'; -import './greater'; +import './gather'; +import './greater_equal_strict'; import './greater_equal'; +import './greater_strict'; +import './greater'; +import './ifft'; +import './irfft'; +import './is_finite'; +import './is_inf'; +import './is_nan'; import './leaky_relu'; -import './less'; +import './less_equal_strict'; import './less_equal'; +import './less_strict'; +import './less'; import './local_response_normalization'; +import './log_sigmoid'; +import './log_softmax'; +import './log_sum_exp'; +import './log'; +import './log1p'; import './logical_and'; import './logical_not'; import './logical_or'; import './logical_xor'; -import './log_sum_exp'; import './mat_mul'; -import './max'; import './max_pool'; +import './max'; +import './maximum_strict'; import './maximum'; +import './mean'; +import './min'; +import './minimum_strict'; import './minimum'; +import './mod_strict'; import './mod'; +import './mul_strict'; import './mul'; +import './neg'; +import './norm'; +import './not_equal_strict'; import './not_equal'; import './one_hot'; +import './ones_like'; import './pad'; import './pool'; +import './pow_strict'; import './pow'; import './prelu'; import './prod'; +import './reciprocal'; import './relu'; +import './relu6'; +import './reshape_as'; import './reshape'; import './resize_bilinear'; import './resize_nearest_neighbor'; -import './relu6'; import './reverse'; +import './rfft'; +import './round'; +import './rsqrt'; import './selu'; import './separable_conv2d'; +import './sigmoid'; +import './sign'; +import './sin'; +import './sinh'; +import './slice'; +import './softmax'; +import './softplus'; +import './space_to_batch_nd'; import './split'; +import './sqrt'; +import './square'; import './squared_difference'; +import './squared_difference_strict'; import './squeeze'; -import './space_to_batch_nd'; import './stack'; +import './step'; +import './strided_slice'; +import './sub_strict'; import './sub'; +import './sum'; +import './tan'; +import './tanh'; import './tile'; +import './to_bool'; +import './to_float'; +import './to_int'; +import './topk'; import './transpose'; +import './unsorted_segment_sum'; import './unstack'; import './where'; +import './zeros_like'; diff --git a/tfjs-core/src/public/chained_ops/register_all_chained_ops_test.ts b/tfjs-core/src/public/chained_ops/register_all_chained_ops_test.ts index 055aecabc36..5549cfb6cab 100644 --- a/tfjs-core/src/public/chained_ops/register_all_chained_ops_test.ts +++ b/tfjs-core/src/public/chained_ops/register_all_chained_ops_test.ts @@ -24,73 +24,155 @@ import {ALL_ENVS, describeWithFlags} from '../../jasmine_util'; // flexibility to change in future. const CHAINED_OPS = [ + 'abs', + 'acos', + 'acosh', 'add', + 'addStrict', 'all', 'any', + 'argMax', + 'argMin', + 'as1D', + 'as2D', + 'as3D', + 'as4D', + 'as5D', + 'asin', + 'asinh', + 'asScalar', + 'asType', + 'atan', 'atan2', + 'atanh', 'avgPool', 'batchNorm', 'batchToSpaceND', 'broadcastTo', + 'cast', + 'ceil', + 'clipByValue', 'concat', 'conv1d', 'conv2d', - 'cumsum', 'conv2dTranspose', + 'cos', + 'cosh', + 'cumsum', 'depthToSpace', 'depthwiseConv2d', 'depthwiseConv2D', 'dilation2d', 'div', 'divNoNan', + 'divStrict', 'dot', 'elu', 'equal', + 'equalStrict', + 'erf', + 'exp', 'expandDims', + 'expm1', + 'fft', + 'flatten', + 'floor', 'floorDiv', + 'gather', 'greater', 'greaterEqual', + 'greaterEqualStrict', + 'greaterStrict', + 'ifft', + 'irfft', + 'isFinite', + 'isInf', + 'isNaN', 'leakyRelu', 'less', 'lessEqual', + 'lessEqualStrict', + 'lessStrict', 'localResponseNormalization', + 'log', + 'log1p', 'logicalAnd', 'logicalNot', 'logicalOr', 'logicalXor', + 'logSigmoid', + 'logSoftmax', 'logSumExp', 'matMul', 'max', 'maximum', + 'maximumStrict', 'maxPool', + 'mean', + 'min', 'minimum', + 'minimumStrict', 'mod', + 'modStrict', 'mul', + 'mulStrict', + 'neg', + 'norm', 'notEqual', + 'notEqualStrict', 'oneHot', + 'onesLike', 'pad', 'pool', 'pow', + 'powStrict', 'prelu', 'prod', + 'reciprocal', 'relu', + 'relu6', 'reshape', + 'reshapeAs', 'resizeBilinear', 'resizeNearestNeighbor', - 'relu6', 'reverse', + 'rfft', + 'round', + 'rsqrt', 'selu', 'separableConv2d', + 'sigmoid', + 'sign', + 'sin', + 'sinh', + 'slice', + 'softmax', + 'softplus', 'spaceToBatchND', 'split', + 'sqrt', + 'square', 'square', + 'squaredDifferenceStrict', 'squeeze', 'stack', + 'step', + 'stridedSlice', 'sub', + 'subStrict', + 'sum', + 'tan', + 'tanh', 'tile', + 'toBool', + 'toFloat', + 'toInt', + 'topk', 'transpose', + 'unsortedSegmentSum', 'unstack', - 'where' + 'where', + 'zerosLike' ]; describeWithFlags('chained ops', ALL_ENVS, () => { diff --git a/tfjs-core/src/public/chained_ops/reshape_as.ts b/tfjs-core/src/public/chained_ops/reshape_as.ts new file mode 100644 index 00000000000..b78a73444f1 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/reshape_as.ts @@ -0,0 +1,39 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {reshape} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + reshapeAs(x: T): T; + } +} + +/** + * Reshapes the tensor into the shape of the provided tensor. + * + * @param x The tensor of required shape. + */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ +Tensor.prototype.reshapeAs = function(x: T): T { + this.throwIfDisposed(); + return reshape(this, x.shape) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/rfft.ts b/tfjs-core/src/public/chained_ops/rfft.ts new file mode 100644 index 00000000000..2b19513e117 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/rfft.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {rfft} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + rfft(this: Tensor): Tensor; + } +} + +Tensor.prototype.rfft = function(this: Tensor): T { + this.throwIfDisposed(); + return rfft(this) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/round.ts b/tfjs-core/src/public/chained_ops/round.ts new file mode 100644 index 00000000000..f1eba0bcd3f --- /dev/null +++ b/tfjs-core/src/public/chained_ops/round.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {round} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + round(this: T): T; + } +} + +Tensor.prototype.round = function(this: T): T { + this.throwIfDisposed(); + return round(this); +}; diff --git a/tfjs-core/src/public/chained_ops/rsqrt.ts b/tfjs-core/src/public/chained_ops/rsqrt.ts new file mode 100644 index 00000000000..22de240a917 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/rsqrt.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {rsqrt} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + rsqrt(this: T): T; + } +} + +Tensor.prototype.rsqrt = function(this: T): T { + this.throwIfDisposed(); + return rsqrt(this); +}; diff --git a/tfjs-core/src/public/chained_ops/sigmoid.ts b/tfjs-core/src/public/chained_ops/sigmoid.ts new file mode 100644 index 00000000000..c664ecf1c3b --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sigmoid.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sigmoid} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sigmoid(this: T): T; + } +} + +Tensor.prototype.sigmoid = function(this: T): T { + this.throwIfDisposed(); + return sigmoid(this); +}; diff --git a/tfjs-core/src/public/chained_ops/sign.ts b/tfjs-core/src/public/chained_ops/sign.ts new file mode 100644 index 00000000000..e80745f8959 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sign.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sign} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sign(this: T): T; + } +} + +Tensor.prototype.sign = function(this: T): T { + this.throwIfDisposed(); + return sign(this); +}; diff --git a/tfjs-core/src/public/chained_ops/sin.ts b/tfjs-core/src/public/chained_ops/sin.ts new file mode 100644 index 00000000000..9dd5ce2431c --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sin.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sin} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sin(this: T): T; + } +} + +Tensor.prototype.sin = function(this: T): T { + this.throwIfDisposed(); + return sin(this); +}; diff --git a/tfjs-core/src/public/chained_ops/sinh.ts b/tfjs-core/src/public/chained_ops/sinh.ts new file mode 100644 index 00000000000..61ff46ac51a --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sinh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sinh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sinh(this: T): T; + } +} + +Tensor.prototype.sinh = function(this: T): T { + this.throwIfDisposed(); + return sinh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/slice.ts b/tfjs-core/src/public/chained_ops/slice.ts new file mode 100644 index 00000000000..410826654ef --- /dev/null +++ b/tfjs-core/src/public/chained_ops/slice.ts @@ -0,0 +1,35 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {slice} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + slice( + this: T, begin: number|number[], size?: number|number[]): T; + } +} + +Tensor.prototype.slice = function( + this: T, begin: number|number[], size?: number|number[]): T { + this.throwIfDisposed(); + return slice(this, begin, size); +}; diff --git a/tfjs-core/src/public/chained_ops/softmax.ts b/tfjs-core/src/public/chained_ops/softmax.ts new file mode 100644 index 00000000000..3a31877b61d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/softmax.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {softmax} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + softmax(this: T, dim?: number): T; + } +} + +Tensor.prototype.softmax = function(this: T, dim: number): T { + this.throwIfDisposed(); + return softmax(this, dim); +}; diff --git a/tfjs-core/src/public/chained_ops/softplus.ts b/tfjs-core/src/public/chained_ops/softplus.ts new file mode 100644 index 00000000000..7b8fd40ce0a --- /dev/null +++ b/tfjs-core/src/public/chained_ops/softplus.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {softplus} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + softplus(this: T): T; + } +} + +Tensor.prototype.softplus = function(this: T): T { + this.throwIfDisposed(); + return softplus(this); +}; diff --git a/tfjs-core/src/public/chained_ops/sqrt.ts b/tfjs-core/src/public/chained_ops/sqrt.ts new file mode 100644 index 00000000000..b2fdcb9fdca --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sqrt.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sqrt} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sqrt(this: T): T; + } +} + +Tensor.prototype.sqrt = function(this: T): T { + this.throwIfDisposed(); + return sqrt(this); +}; diff --git a/tfjs-core/src/public/chained_ops/square.ts b/tfjs-core/src/public/chained_ops/square.ts new file mode 100644 index 00000000000..5f553be2552 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/square.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {square} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + square(this: T): T; + } +} + +Tensor.prototype.square = function(this: T): T { + this.throwIfDisposed(); + return square(this); +}; diff --git a/tfjs-core/src/public/chained_ops/squared_difference_strict.ts b/tfjs-core/src/public/chained_ops/squared_difference_strict.ts new file mode 100644 index 00000000000..37164cdc322 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/squared_difference_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {squaredDifferenceStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + squaredDifferenceStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.squaredDifferenceStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return squaredDifferenceStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/step.ts b/tfjs-core/src/public/chained_ops/step.ts new file mode 100644 index 00000000000..57a06ce9805 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/step.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {step} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + step(this: T, alpha?: number): T; + } +} + +Tensor.prototype.step = function(this: T, alpha?: number) { + this.throwIfDisposed(); + return step(this, alpha); +}; diff --git a/tfjs-core/src/public/chained_ops/strided_slice.ts b/tfjs-core/src/public/chained_ops/strided_slice.ts new file mode 100644 index 00000000000..296045520e2 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/strided_slice.ts @@ -0,0 +1,41 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {stridedSlice} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + stridedSlice( + this: Tensor, begin: number[], end: number[], strides: number[], + beginMask?: number, endMask?: number, ellipsisMask?: number, + newAxisMask?: number, shrinkAxisMask?: number): Tensor; + } +} + +Tensor.prototype.stridedSlice = function( + this: Tensor, begin: number[], end: number[], strides: number[], + beginMask?: number, endMask?: number, ellipsisMask?: number, + newAxisMask?: number, shrinkAxisMask?: number): T { + this.throwIfDisposed(); + return stridedSlice( + this, begin, end, strides, beginMask, endMask, ellipsisMask, + newAxisMask, shrinkAxisMask) as T; +}; diff --git a/tfjs-core/src/public/chained_ops/sub_strict.ts b/tfjs-core/src/public/chained_ops/sub_strict.ts new file mode 100644 index 00000000000..7197b64bfce --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sub_strict.ts @@ -0,0 +1,37 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {subStrict} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank, TensorLike} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + subStrict(this: T, x: T|TensorLike): T; + } +} + +/** + * @deprecated strict variants of ops have been deprecated + */ +Tensor.prototype.subStrict = function( + this: T, x: T|TensorLike): T { + this.throwIfDisposed(); + return subStrict(this, x); +}; diff --git a/tfjs-core/src/public/chained_ops/sum.ts b/tfjs-core/src/public/chained_ops/sum.ts new file mode 100644 index 00000000000..10470ea9d0d --- /dev/null +++ b/tfjs-core/src/public/chained_ops/sum.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {sum} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + sum(axis?: number|number[], keepDims?: boolean): T; + } +} + +Tensor.prototype.sum = function( + axis?: number|number[], keepDims?: boolean): T { + this.throwIfDisposed(); + return sum(this, axis, keepDims); +}; diff --git a/tfjs-core/src/public/chained_ops/tan.ts b/tfjs-core/src/public/chained_ops/tan.ts new file mode 100644 index 00000000000..f0c5dbd46fc --- /dev/null +++ b/tfjs-core/src/public/chained_ops/tan.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {tan} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + tan(this: T): T; + } +} + +Tensor.prototype.tan = function(this: T): T { + this.throwIfDisposed(); + return tan(this); +}; diff --git a/tfjs-core/src/public/chained_ops/tanh.ts b/tfjs-core/src/public/chained_ops/tanh.ts new file mode 100644 index 00000000000..87b2394476b --- /dev/null +++ b/tfjs-core/src/public/chained_ops/tanh.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {tanh} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + tanh(this: T): T; + } +} + +Tensor.prototype.tanh = function(this: T): T { + this.throwIfDisposed(); + return tanh(this); +}; diff --git a/tfjs-core/src/public/chained_ops/to_bool.ts b/tfjs-core/src/public/chained_ops/to_bool.ts new file mode 100644 index 00000000000..9fc2c736492 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/to_bool.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cast} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + toBool(this: T): T; + } +} + +Tensor.prototype.toBool = function(this: T): T { + this.throwIfDisposed(); + return cast(this, 'bool'); +}; diff --git a/tfjs-core/src/public/chained_ops/to_float.ts b/tfjs-core/src/public/chained_ops/to_float.ts new file mode 100644 index 00000000000..759a04c6e20 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/to_float.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cast} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + toFloat(this: T): T; + } +} + +Tensor.prototype.toFloat = function(this: T): T { + this.throwIfDisposed(); + return cast(this, 'float32'); +}; diff --git a/tfjs-core/src/public/chained_ops/to_int.ts b/tfjs-core/src/public/chained_ops/to_int.ts new file mode 100644 index 00000000000..0777b53216f --- /dev/null +++ b/tfjs-core/src/public/chained_ops/to_int.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {cast} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + toInt(this: T): T; + } +} + +Tensor.prototype.toInt = function(this: T): T { + this.throwIfDisposed(); + return cast(this, 'int32'); +}; diff --git a/tfjs-core/src/public/chained_ops/topk.ts b/tfjs-core/src/public/chained_ops/topk.ts new file mode 100644 index 00000000000..183defac1d8 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/topk.ts @@ -0,0 +1,34 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +import {topk} from '../../ops/topk'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + topk(this: T, k?: number, sorted?: boolean): + {values: T, indices: T}; + } +} + +Tensor.prototype.topk = function( + this: T, k?: number, sorted?: boolean): {values: T, indices: T} { + this.throwIfDisposed(); + return topk(this, k, sorted) as {values: T, indices: T}; +}; diff --git a/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts b/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts new file mode 100644 index 00000000000..5585d2ea297 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts @@ -0,0 +1,35 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {unsortedSegmentSum} from '../../ops/ops'; +import {Tensor, Tensor1D} from '../../tensor'; +import {Rank, TensorLike1D} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + unsortedSegmentSum( + this: T, segmentIds: Tensor1D|TensorLike1D, numSegments: number): T; + } +} + +Tensor.prototype.unsortedSegmentSum = function( + this: T, segmentIds: Tensor1D|TensorLike1D, numSegments: number): T { + this.throwIfDisposed(); + return unsortedSegmentSum(this, segmentIds, numSegments); +}; diff --git a/tfjs-core/src/public/chained_ops/zeros_like.ts b/tfjs-core/src/public/chained_ops/zeros_like.ts new file mode 100644 index 00000000000..4fb2f5a3449 --- /dev/null +++ b/tfjs-core/src/public/chained_ops/zeros_like.ts @@ -0,0 +1,33 @@ + +/** + * @license + * Copyright 2020 Google LLC. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// TODO update import path once op is modularized. +import {zerosLike} from '../../ops/ops'; +import {Tensor} from '../../tensor'; +import {Rank} from '../../types'; + +declare module '../../tensor' { + interface Tensor { + zerosLike(this: T): T; + } +} + +Tensor.prototype.zerosLike = function(this: T): T { + this.throwIfDisposed(); + return zerosLike(this); +}; diff --git a/tfjs-core/src/tensor.ts b/tfjs-core/src/tensor.ts index 72fcb998675..d1f8726ab82 100644 --- a/tfjs-core/src/tensor.ts +++ b/tfjs-core/src/tensor.ts @@ -16,7 +16,7 @@ */ import {tensorToString} from './tensor_format'; -import {ArrayMap, BackendValues, DataType, DataTypeMap, DataValues, NumericDataType, Rank, ShapeMap, SingleValueMap, TensorLike, TensorLike1D, TypedArray} from './types'; +import {ArrayMap, BackendValues, DataType, DataTypeMap, DataValues, NumericDataType, Rank, ShapeMap, SingleValueMap, TypedArray} from './types'; import * as util from './util'; import {computeStrides, toNestedArray} from './util'; @@ -175,85 +175,7 @@ export interface OpHandler { values?: DataTypeMap[D]): TensorBuffer; print(x: T, verbose: boolean): void; clone(x: T): T; - gather(x: T, indices: Tensor|TensorLike, axis: number): T; - norm( - x: Tensor, ord: number|'euclidean'|'fro', axis: number|number[], - keepDims: boolean): Tensor; - slice>( - x: T, begin: number|number[], size?: number|number[]): T; - sum(x: Tensor, axis: number|number[], keepDims: boolean): T; - mean(x: Tensor, axis: number|number[], keepDims: boolean): - T; - min(x: Tensor, axis: number|number[], keepDims: boolean): T; - argMin(x: Tensor, axis: number): T; - argMax(x: Tensor, axis: number): T; - addStrict(a: T, b: T|TensorLike): T; - subStrict(a: T, b: T|TensorLike): T; - powStrict(base: T, exp: Tensor|TensorLike): T; - mulStrict(a: T, b: T|TensorLike): T; - divStrict(a: T, b: T|TensorLike): T; - modStrict(a: T, b: T|TensorLike): T; - minimumStrict(a: T, b: T|TensorLike): T; - maximumStrict(a: T, b: T|TensorLike): T; - squaredDifferenceStrict(a: T, b: T|TensorLike): T; - notEqualStrict(a: T, b: T|TensorLike): T; - lessStrict(a: T, b: T|TensorLike): T; - equalStrict(a: T, b: T|TensorLike): T; - lessEqualStrict(a: T, b: T|TensorLike): T; - greaterStrict(a: T, b: T|TensorLike): T; - greaterEqualStrict(a: T, b: T|TensorLike): T; - neg(x: T): T; - ceil(x: T): T; - floor(x: T): T; - sign(x: T): T; - isNaN(x: T): T; - isInf(x: T): T; - isFinite(x: T): T; - round(x: T): T; - exp(x: T): T; - expm1(x: T): T; - log(x: T): T; - log1p(x: T): T; - sqrt(x: T): T; - rsqrt(x: T): T; - square(x: T): T; - reciprocal(x: T): T; - abs(x: T): T; - clipByValue( - x: T, clipValueMin: number, clipValueMax: number): T; - sigmoid(x: T): T; - logSigmoid(x: T): T; - softplus(x: T): T; - zerosLike(x: T): T; - onesLike(x: T): T; - sin(x: T): T; - cos(x: T): T; - tan(x: T): T; - asin(x: T): T; - acos(x: T): T; - atan(x: T): T; - sinh(x: T): T; - cosh(x: T): T; - tanh(x: T): T; - asinh(x: T): T; - acosh(x: T): T; - atanh(x: T): T; - erf(x: T): T; - step(x: T, alpha: number): T; - softmax(logits: T, dim: number): T; - logSoftmax(logits: T, axis: number): T; - unsortedSegmentSum( - x: T, segmentIds: Tensor1D|TensorLike1D, numSegments: number): T; - topk(x: T, k: number, sorted: boolean): - {values: T, indices: T}; - stridedSlice( - x: Tensor, begin: number[], end: number[], strides: number[], - beginMask: number, endMask: number, ellipsisMask: number, - newAxisMask: number, shrinkAxisMask: number): Tensor; - spectral: { - fft(x: Tensor): Tensor; ifft(x: Tensor): Tensor; rfft(x: Tensor): Tensor; - irfft(x: Tensor): Tensor - }; + // TODO(yassogba) bring reshape back? } // For tracking tensor creation and disposal. @@ -351,95 +273,6 @@ export class Tensor { this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher') as R; } - /** Flatten a Tensor to a 1D array. */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - flatten(): Tensor1D { - this.throwIfDisposed(); - return this.as1D(); - } - - /** Converts a size-1 `tf.Tensor` to a `tf.Scalar`. */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - asScalar(): Scalar { - this.throwIfDisposed(); - util.assert(this.size === 1, () => 'The array must have only 1 element.'); - return this.reshape([]); - } - - /** Converts a `tf.Tensor` to a `tf.Tensor1D`. */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - as1D(): Tensor1D { - this.throwIfDisposed(); - return this.reshape([this.size]); - } - - /** - * Converts a `tf.Tensor` to a `tf.Tensor2D`. - * - * @param rows Number of rows in `tf.Tensor2D`. - * @param columns Number of columns in `tf.Tensor2D`. - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - as2D(rows: number, columns: number): Tensor2D { - this.throwIfDisposed(); - return this.reshape([rows, columns]); - } - - /** - * Converts a `tf.Tensor` to a `tf.Tensor3D`. - * - * @param rows Number of rows in `tf.Tensor3D`. - * @param columns Number of columns in `tf.Tensor3D`. - * @param depth Depth of `tf.Tensor3D`. - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - as3D(rows: number, columns: number, depth: number): Tensor3D { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth]); - } - - /** - * Converts a `tf.Tensor` to a `tf.Tensor4D`. - * - * @param rows Number of rows in `tf.Tensor4D`. - * @param columns Number of columns in `tf.Tensor4D`. - * @param depth Depth of `tf.Tensor4D`. - * @param depth2 4th dimension of `tf.Tensor4D`. - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - as4D(rows: number, columns: number, depth: number, depth2: number): Tensor4D { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth, depth2]); - } - - /** - * Converts a `tf.Tensor` to a `tf.Tensor5D`. - * - * @param rows Number of rows in `tf.Tensor5D`. - * @param columns Number of columns in `tf.Tensor5D`. - * @param depth Depth of `tf.Tensor5D`. - * @param depth2 4th dimension of `tf.Tensor5D`. - * @param depth3 5th dimension of 'tf.Tensor5D' - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - as5D( - rows: number, columns: number, depth: number, depth2: number, - depth3: number): Tensor5D { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth, depth2, depth3]); - } - - /** - * Casts a `tf.Tensor` to a specified dtype. - * - * @param dtype Data-type to cast the tensor to. - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - asType(this: T, dtype: DataType): T { - this.throwIfDisposed(); - return opHandler.cast(this, dtype); - } - get rank(): number { return this.shape.length; } @@ -554,24 +387,6 @@ export class Tensor { } } - /** Casts the array to type `float32` */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - toFloat(this: T): T { - return this.asType('float32'); - } - - /** Casts the array to type `int32` */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - toInt() { - return this.asType('int32'); - } - - /** Casts the array to type `bool` */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - toBool() { - return this.asType('bool'); - } - /** * Prints the `tf.Tensor`. See `tf.print` for details. * @@ -583,17 +398,6 @@ export class Tensor { return opHandler.print(this, verbose); } - /** - * Reshapes the tensor into the shape of the provided tensor. - * - * @param x The tensor of required shape. - */ - /** @doc {heading: 'Tensors', subheading: 'Classes'} */ - reshapeAs(x: T): T { - this.throwIfDisposed(); - return this.reshape(x.shape); - } - /** Returns a copy of the tensor. See `tf.clone` for details. */ /** @doc {heading: 'Tensors', subheading: 'Classes'} */ clone(this: T): T { @@ -610,365 +414,15 @@ export class Tensor { return tensorToString(vals, this.shape, this.dtype, verbose); } - // Below is chain API that is not exposed to docs to avoid repetition. To - // expose a method, move it above this comment and add @doc and jsdoc. - - gather(this: T, indices: Tensor|TensorLike, axis = 0): T { - this.throwIfDisposed(); - return opHandler.gather(this, indices, axis); - } - norm( - ord: number|'euclidean'|'fro' = 'euclidean', axis: number|number[] = null, - keepDims = false): Tensor { - this.throwIfDisposed(); - return opHandler.norm(this, ord, axis, keepDims); - } - slice>( - this: T, begin: number|number[], size?: number|number[]): T { - this.throwIfDisposed(); - return opHandler.slice(this, begin, size); - } - // Reduction ops. - sum(axis: number|number[] = null, keepDims = false): T { - this.throwIfDisposed(); - return opHandler.sum(this, axis, keepDims); - } - mean(axis: number|number[] = null, keepDims = false): T { - this.throwIfDisposed(); - return opHandler.mean(this, axis, keepDims); - } - min(axis: number|number[] = null, keepDims = false): T { - this.throwIfDisposed(); - return opHandler.min(this, axis, keepDims); - } - argMin(axis: number = null): T { - this.throwIfDisposed(); - return opHandler.argMin(this, axis); - } - argMax(axis: number = null): T { - this.throwIfDisposed(); - return opHandler.argMax(this, axis); - } - - // Transformations cast(dtype: DataType): T { this.throwIfDisposed(); return opHandler.cast(this as T, dtype); } - - // Binary ops. - /** - * @deprecated strict variants of ops have been deprecated - */ - addStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.addStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - subStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.subStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - powStrict(exp: Tensor|TensorLike): Tensor { - this.throwIfDisposed(); - return opHandler.powStrict(this, exp); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - mulStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.mulStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - divStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.divStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - minimumStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.minimumStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - maximumStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.maximumStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - modStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.modStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - squaredDifferenceStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.squaredDifferenceStrict(this, x); - } - - // Compare ops. - /** - * @deprecated strict variants of ops have been deprecated - */ - notEqualStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.notEqualStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - lessStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.lessStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - equalStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.equalStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - lessEqualStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.lessEqualStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - greaterStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.greaterStrict(this, x); - } - /** - * @deprecated strict variants of ops have been deprecated - */ - greaterEqualStrict(this: T, x: T|TensorLike): T { - this.throwIfDisposed(); - return opHandler.greaterEqualStrict(this, x); - } - // Unary ops. - neg(this: T): T { - this.throwIfDisposed(); - return opHandler.neg(this); - } - ceil(this: T): T { - this.throwIfDisposed(); - return opHandler.ceil(this); - } - floor(this: T): T { - this.throwIfDisposed(); - return opHandler.floor(this); - } - sign(this: T): T { - this.throwIfDisposed(); - return opHandler.sign(this); - } - isNaN(this: T): T { - this.throwIfDisposed(); - return opHandler.isNaN(this); - } - isInf(this: T): T { - this.throwIfDisposed(); - return opHandler.isInf(this); - } - isFinite(this: T): T { - this.throwIfDisposed(); - return opHandler.isFinite(this); - } - exp(this: T): T { - this.throwIfDisposed(); - return opHandler.exp(this); - } - expm1(this: T): T { - this.throwIfDisposed(); - return opHandler.expm1(this); - } - log(this: T): T { - this.throwIfDisposed(); - return opHandler.log(this); - } - log1p(this: T): T { - this.throwIfDisposed(); - return opHandler.log1p(this); - } - sqrt(this: T): T { - this.throwIfDisposed(); - return opHandler.sqrt(this); - } - rsqrt(this: T): T { - this.throwIfDisposed(); - return opHandler.rsqrt(this); - } - square(this: T): T { - this.throwIfDisposed(); - return opHandler.square(this); - } - reciprocal(this: T): T { - this.throwIfDisposed(); - return opHandler.reciprocal(this); - } - abs(this: T): T { - this.throwIfDisposed(); - return opHandler.abs(this); - } - clipByValue(min: number, max: number): Tensor { - this.throwIfDisposed(); - return opHandler.clipByValue(this, min, max); - } - sigmoid(this: T): T { - this.throwIfDisposed(); - return opHandler.sigmoid(this); - } - logSigmoid(this: T): T { - this.throwIfDisposed(); - return opHandler.logSigmoid(this); - } - softplus(this: T): T { - this.throwIfDisposed(); - return opHandler.softplus(this); - } - zerosLike(this: T): T { - this.throwIfDisposed(); - return opHandler.zerosLike(this); - } - onesLike(this: T): T { - this.throwIfDisposed(); - return opHandler.onesLike(this); - } - sin(this: T): T { - this.throwIfDisposed(); - return opHandler.sin(this); - } - cos(this: T): T { - this.throwIfDisposed(); - return opHandler.cos(this); - } - tan(this: T): T { - this.throwIfDisposed(); - return opHandler.tan(this); - } - asin(this: T): T { - this.throwIfDisposed(); - return opHandler.asin(this); - } - acos(this: T): T { - this.throwIfDisposed(); - return opHandler.acos(this); - } - atan(this: T): T { - this.throwIfDisposed(); - return opHandler.atan(this); - } - sinh(this: T): T { - this.throwIfDisposed(); - return opHandler.sinh(this); - } - cosh(this: T): T { - this.throwIfDisposed(); - return opHandler.cosh(this); - } - tanh(this: T): T { - this.throwIfDisposed(); - return opHandler.tanh(this); - } - asinh(this: T): T { - this.throwIfDisposed(); - return opHandler.asinh(this); - } - acosh(this: T): T { - this.throwIfDisposed(); - return opHandler.acosh(this); - } - atanh(this: T): T { - this.throwIfDisposed(); - return opHandler.atanh(this); - } - erf(this: T): T { - this.throwIfDisposed(); - return opHandler.erf(this); - } - round(this: T): T { - this.throwIfDisposed(); - return opHandler.round(this); - } - step(this: T, alpha = 0.0): T { - this.throwIfDisposed(); - return opHandler.step(this, alpha); - } - softmax(this: T, dim = -1): T { - this.throwIfDisposed(); - return opHandler.softmax(this, dim); - } - logSoftmax(this: T, axis = -1): T { - this.throwIfDisposed(); - return opHandler.logSoftmax(this, axis); - } - // Pooling. variable(trainable = true, name?: string, dtype?: DataType): Variable { this.throwIfDisposed(); return trackerFn().makeVariable(this, trainable, name, dtype) as Variable; } - - unsortedSegmentSum( - this: T, segmentIds: Tensor1D|TensorLike1D, numSegments: number): T { - this.throwIfDisposed(); - return opHandler.unsortedSegmentSum(this, segmentIds, numSegments); - } - - topk(this: T, k = 1, sorted = true): - {values: T, indices: T} { - this.throwIfDisposed(); - return opHandler.topk(this, k, sorted); - } - - stridedSlice( - this: Tensor, begin: number[], end: number[], strides: number[], - beginMask = 0, endMask = 0, ellipsisMask = 0, newAxisMask = 0, - shrinkAxisMask = 0): Tensor { - this.throwIfDisposed(); - return opHandler.stridedSlice( - this, begin, end, strides, beginMask, endMask, ellipsisMask, - newAxisMask, shrinkAxisMask); - } - - fft(this: Tensor): Tensor { - this.throwIfDisposed(); - return opHandler.spectral.fft(this); - } - - ifft(this: Tensor): Tensor { - this.throwIfDisposed(); - return opHandler.spectral.ifft(this); - } - - rfft(this: Tensor): Tensor { - this.throwIfDisposed(); - return opHandler.spectral.rfft(this); - } - - irfft(this: Tensor): Tensor { - this.throwIfDisposed(); - return opHandler.spectral.irfft(this); - } } Object.defineProperty(Tensor, Symbol.hasInstance, { value: (instance: Tensor) => { From 74d0a3d4d4b6670995031c0a634534994810993a Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Tue, 30 Jun 2020 18:50:33 -0400 Subject: [PATCH 2/6] remove circular dep --- tfjs-core/src/engine.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tfjs-core/src/engine.ts b/tfjs-core/src/engine.ts index 164a21af24e..a9c3144d7e5 100644 --- a/tfjs-core/src/engine.ts +++ b/tfjs-core/src/engine.ts @@ -19,7 +19,6 @@ import {BackendTimingInfo, DataMover, KernelBackend} from './backends/backend'; import {Environment, setEnvironmentGlobal} from './environment'; import {getGlobalNamespace} from './global_util'; import {getGradient, getKernel, getKernelsForBackend, GradFunc, NamedAttrMap, TensorInfo} from './kernel_registry'; -import {cast} from './ops/ops'; import {Profiler} from './profiler'; import {backpropagateGradients, getFilteredNodesXToY, TapeNode} from './tape'; import {DataId, setTensorTracker, Tensor, TensorTracker, Variable} from './tensor'; @@ -744,7 +743,7 @@ export class Engine implements TensorTracker, DataMover { dtype?: DataType): Variable { name = name || this.nextVariableId().toString(); if (dtype != null && dtype !== initialValue.dtype) { - initialValue = cast(initialValue, dtype); + initialValue = initialValue.cast(dtype); } const v = new Variable(initialValue, trainable, name, this.nextTensorId()); if (this.state.registeredVariables[v.name] != null) { From 1ffed2df7410a41b01647dab63f47e842ddedcf5 Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Tue, 30 Jun 2020 22:04:33 -0400 Subject: [PATCH 3/6] fix extra newline --- tfjs-core/src/public/chained_ops/abs.ts | 1 - tfjs-core/src/public/chained_ops/acos.ts | 1 - tfjs-core/src/public/chained_ops/acosh.ts | 1 - tfjs-core/src/public/chained_ops/add_strict.ts | 1 - tfjs-core/src/public/chained_ops/as1d.ts | 1 - tfjs-core/src/public/chained_ops/as2d.ts | 1 - tfjs-core/src/public/chained_ops/as3d.ts | 1 - tfjs-core/src/public/chained_ops/as4d.ts | 1 - tfjs-core/src/public/chained_ops/as5d.ts | 1 - tfjs-core/src/public/chained_ops/as_scalar.ts | 1 - tfjs-core/src/public/chained_ops/as_type.ts | 1 - tfjs-core/src/public/chained_ops/asin.ts | 1 - tfjs-core/src/public/chained_ops/asinh.ts | 1 - tfjs-core/src/public/chained_ops/atan.ts | 1 - tfjs-core/src/public/chained_ops/atanh.ts | 1 - tfjs-core/src/public/chained_ops/cast.ts | 1 - tfjs-core/src/public/chained_ops/ceil.ts | 1 - tfjs-core/src/public/chained_ops/clip_by_value.ts | 1 - tfjs-core/src/public/chained_ops/cos.ts | 1 - tfjs-core/src/public/chained_ops/cosh.ts | 1 - tfjs-core/src/public/chained_ops/div_strict.ts | 1 - tfjs-core/src/public/chained_ops/equal_strict.ts | 1 - tfjs-core/src/public/chained_ops/erf.ts | 1 - tfjs-core/src/public/chained_ops/exp.ts | 1 - tfjs-core/src/public/chained_ops/expm1.ts | 1 - tfjs-core/src/public/chained_ops/fft.ts | 1 - tfjs-core/src/public/chained_ops/flatten.ts | 1 - tfjs-core/src/public/chained_ops/floor.ts | 1 - tfjs-core/src/public/chained_ops/gather.ts | 1 - tfjs-core/src/public/chained_ops/greater_equal_strict.ts | 1 - tfjs-core/src/public/chained_ops/greater_strict.ts | 1 - tfjs-core/src/public/chained_ops/ifft.ts | 1 - tfjs-core/src/public/chained_ops/irfft.ts | 1 - tfjs-core/src/public/chained_ops/is_finite.ts | 1 - tfjs-core/src/public/chained_ops/is_inf.ts | 1 - tfjs-core/src/public/chained_ops/is_nan.ts | 1 - tfjs-core/src/public/chained_ops/less_equal_strict.ts | 1 - tfjs-core/src/public/chained_ops/less_strict.ts | 1 - tfjs-core/src/public/chained_ops/log.ts | 1 - tfjs-core/src/public/chained_ops/log1p.ts | 1 - tfjs-core/src/public/chained_ops/log_sigmoid.ts | 1 - tfjs-core/src/public/chained_ops/log_softmax.ts | 1 - tfjs-core/src/public/chained_ops/maximum_strict.ts | 1 - tfjs-core/src/public/chained_ops/minimum_strict.ts | 1 - tfjs-core/src/public/chained_ops/mod_strict.ts | 1 - tfjs-core/src/public/chained_ops/mul_strict.ts | 1 - tfjs-core/src/public/chained_ops/neg.ts | 1 - tfjs-core/src/public/chained_ops/norm.ts | 1 - tfjs-core/src/public/chained_ops/not_equal_strict.ts | 1 - tfjs-core/src/public/chained_ops/ones_like.ts | 1 - tfjs-core/src/public/chained_ops/pow_strict.ts | 1 - tfjs-core/src/public/chained_ops/reciprocal.ts | 1 - tfjs-core/src/public/chained_ops/reshape_as.ts | 1 - tfjs-core/src/public/chained_ops/rfft.ts | 1 - tfjs-core/src/public/chained_ops/round.ts | 1 - tfjs-core/src/public/chained_ops/rsqrt.ts | 1 - tfjs-core/src/public/chained_ops/sigmoid.ts | 1 - tfjs-core/src/public/chained_ops/sign.ts | 1 - tfjs-core/src/public/chained_ops/sin.ts | 1 - tfjs-core/src/public/chained_ops/sinh.ts | 1 - tfjs-core/src/public/chained_ops/slice.ts | 1 - tfjs-core/src/public/chained_ops/softmax.ts | 1 - tfjs-core/src/public/chained_ops/softplus.ts | 1 - tfjs-core/src/public/chained_ops/sqrt.ts | 1 - tfjs-core/src/public/chained_ops/square.ts | 1 - tfjs-core/src/public/chained_ops/squared_difference_strict.ts | 1 - tfjs-core/src/public/chained_ops/step.ts | 1 - tfjs-core/src/public/chained_ops/strided_slice.ts | 1 - tfjs-core/src/public/chained_ops/sub_strict.ts | 1 - tfjs-core/src/public/chained_ops/tan.ts | 1 - tfjs-core/src/public/chained_ops/tanh.ts | 1 - tfjs-core/src/public/chained_ops/to_bool.ts | 1 - tfjs-core/src/public/chained_ops/to_float.ts | 1 - tfjs-core/src/public/chained_ops/to_int.ts | 1 - tfjs-core/src/public/chained_ops/topk.ts | 1 - tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts | 1 - 76 files changed, 76 deletions(-) diff --git a/tfjs-core/src/public/chained_ops/abs.ts b/tfjs-core/src/public/chained_ops/abs.ts index 4e416c5181c..b306a4d2768 100644 --- a/tfjs-core/src/public/chained_ops/abs.ts +++ b/tfjs-core/src/public/chained_ops/abs.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/acos.ts b/tfjs-core/src/public/chained_ops/acos.ts index bddbe5aba0a..a9f16b76e21 100644 --- a/tfjs-core/src/public/chained_ops/acos.ts +++ b/tfjs-core/src/public/chained_ops/acos.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/acosh.ts b/tfjs-core/src/public/chained_ops/acosh.ts index e53b5cb6a8d..5ceae391fa3 100644 --- a/tfjs-core/src/public/chained_ops/acosh.ts +++ b/tfjs-core/src/public/chained_ops/acosh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/add_strict.ts b/tfjs-core/src/public/chained_ops/add_strict.ts index 96b82cf7723..cfd9ec03965 100644 --- a/tfjs-core/src/public/chained_ops/add_strict.ts +++ b/tfjs-core/src/public/chained_ops/add_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as1d.ts b/tfjs-core/src/public/chained_ops/as1d.ts index 8fcc0df46bd..9f8a4d730c3 100644 --- a/tfjs-core/src/public/chained_ops/as1d.ts +++ b/tfjs-core/src/public/chained_ops/as1d.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as2d.ts b/tfjs-core/src/public/chained_ops/as2d.ts index 229fe03b122..ca60767eff6 100644 --- a/tfjs-core/src/public/chained_ops/as2d.ts +++ b/tfjs-core/src/public/chained_ops/as2d.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as3d.ts b/tfjs-core/src/public/chained_ops/as3d.ts index 1364dc4021d..81f372d4b58 100644 --- a/tfjs-core/src/public/chained_ops/as3d.ts +++ b/tfjs-core/src/public/chained_ops/as3d.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as4d.ts b/tfjs-core/src/public/chained_ops/as4d.ts index 88ac7df9cae..3fe7e575a4a 100644 --- a/tfjs-core/src/public/chained_ops/as4d.ts +++ b/tfjs-core/src/public/chained_ops/as4d.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as5d.ts b/tfjs-core/src/public/chained_ops/as5d.ts index f3f970b2b6f..eeafadfc4c0 100644 --- a/tfjs-core/src/public/chained_ops/as5d.ts +++ b/tfjs-core/src/public/chained_ops/as5d.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as_scalar.ts b/tfjs-core/src/public/chained_ops/as_scalar.ts index fbeede9c025..57c4dd8fe20 100644 --- a/tfjs-core/src/public/chained_ops/as_scalar.ts +++ b/tfjs-core/src/public/chained_ops/as_scalar.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/as_type.ts b/tfjs-core/src/public/chained_ops/as_type.ts index 26ad3bf2935..2803aa63c06 100644 --- a/tfjs-core/src/public/chained_ops/as_type.ts +++ b/tfjs-core/src/public/chained_ops/as_type.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/asin.ts b/tfjs-core/src/public/chained_ops/asin.ts index 3d6df5fa399..36fc202e489 100644 --- a/tfjs-core/src/public/chained_ops/asin.ts +++ b/tfjs-core/src/public/chained_ops/asin.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/asinh.ts b/tfjs-core/src/public/chained_ops/asinh.ts index 0e14938749a..3823fac48c2 100644 --- a/tfjs-core/src/public/chained_ops/asinh.ts +++ b/tfjs-core/src/public/chained_ops/asinh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/atan.ts b/tfjs-core/src/public/chained_ops/atan.ts index fe37adec892..d71b38d690b 100644 --- a/tfjs-core/src/public/chained_ops/atan.ts +++ b/tfjs-core/src/public/chained_ops/atan.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/atanh.ts b/tfjs-core/src/public/chained_ops/atanh.ts index c5241795826..a52757f402d 100644 --- a/tfjs-core/src/public/chained_ops/atanh.ts +++ b/tfjs-core/src/public/chained_ops/atanh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/cast.ts b/tfjs-core/src/public/chained_ops/cast.ts index 653df4a2711..9ebabcdb19b 100644 --- a/tfjs-core/src/public/chained_ops/cast.ts +++ b/tfjs-core/src/public/chained_ops/cast.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/ceil.ts b/tfjs-core/src/public/chained_ops/ceil.ts index e1ac3494edd..639d9e46ec5 100644 --- a/tfjs-core/src/public/chained_ops/ceil.ts +++ b/tfjs-core/src/public/chained_ops/ceil.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/clip_by_value.ts b/tfjs-core/src/public/chained_ops/clip_by_value.ts index f4aa819faa1..f9f92410943 100644 --- a/tfjs-core/src/public/chained_ops/clip_by_value.ts +++ b/tfjs-core/src/public/chained_ops/clip_by_value.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/cos.ts b/tfjs-core/src/public/chained_ops/cos.ts index 5241a43c0c1..84e3f686e67 100644 --- a/tfjs-core/src/public/chained_ops/cos.ts +++ b/tfjs-core/src/public/chained_ops/cos.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/cosh.ts b/tfjs-core/src/public/chained_ops/cosh.ts index b53a75cc0d5..f22e771806f 100644 --- a/tfjs-core/src/public/chained_ops/cosh.ts +++ b/tfjs-core/src/public/chained_ops/cosh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/div_strict.ts b/tfjs-core/src/public/chained_ops/div_strict.ts index 1ee330ad412..c1a5bba089f 100644 --- a/tfjs-core/src/public/chained_ops/div_strict.ts +++ b/tfjs-core/src/public/chained_ops/div_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/equal_strict.ts b/tfjs-core/src/public/chained_ops/equal_strict.ts index 4ca91e67196..3f79042d236 100644 --- a/tfjs-core/src/public/chained_ops/equal_strict.ts +++ b/tfjs-core/src/public/chained_ops/equal_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/erf.ts b/tfjs-core/src/public/chained_ops/erf.ts index 941d863fa40..c53a1c3eff8 100644 --- a/tfjs-core/src/public/chained_ops/erf.ts +++ b/tfjs-core/src/public/chained_ops/erf.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/exp.ts b/tfjs-core/src/public/chained_ops/exp.ts index de2837e41ef..44c53485d1a 100644 --- a/tfjs-core/src/public/chained_ops/exp.ts +++ b/tfjs-core/src/public/chained_ops/exp.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/expm1.ts b/tfjs-core/src/public/chained_ops/expm1.ts index 5d36996a053..1638c7adb0e 100644 --- a/tfjs-core/src/public/chained_ops/expm1.ts +++ b/tfjs-core/src/public/chained_ops/expm1.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/fft.ts b/tfjs-core/src/public/chained_ops/fft.ts index ce06dea3a74..235ff5e023a 100644 --- a/tfjs-core/src/public/chained_ops/fft.ts +++ b/tfjs-core/src/public/chained_ops/fft.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/flatten.ts b/tfjs-core/src/public/chained_ops/flatten.ts index 4110ef91aea..1d7ef7d5af9 100644 --- a/tfjs-core/src/public/chained_ops/flatten.ts +++ b/tfjs-core/src/public/chained_ops/flatten.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/floor.ts b/tfjs-core/src/public/chained_ops/floor.ts index 6c123638ca4..89e9dc7af45 100644 --- a/tfjs-core/src/public/chained_ops/floor.ts +++ b/tfjs-core/src/public/chained_ops/floor.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/gather.ts b/tfjs-core/src/public/chained_ops/gather.ts index 5b8c52dc6af..dc444d252f8 100644 --- a/tfjs-core/src/public/chained_ops/gather.ts +++ b/tfjs-core/src/public/chained_ops/gather.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/greater_equal_strict.ts b/tfjs-core/src/public/chained_ops/greater_equal_strict.ts index 3fb276edac2..63430363a61 100644 --- a/tfjs-core/src/public/chained_ops/greater_equal_strict.ts +++ b/tfjs-core/src/public/chained_ops/greater_equal_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/greater_strict.ts b/tfjs-core/src/public/chained_ops/greater_strict.ts index 7fe2c1643b4..cf65288fb1d 100644 --- a/tfjs-core/src/public/chained_ops/greater_strict.ts +++ b/tfjs-core/src/public/chained_ops/greater_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/ifft.ts b/tfjs-core/src/public/chained_ops/ifft.ts index d059cec6181..71f01acdf76 100644 --- a/tfjs-core/src/public/chained_ops/ifft.ts +++ b/tfjs-core/src/public/chained_ops/ifft.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/irfft.ts b/tfjs-core/src/public/chained_ops/irfft.ts index dc26b10c22d..0a76bff285f 100644 --- a/tfjs-core/src/public/chained_ops/irfft.ts +++ b/tfjs-core/src/public/chained_ops/irfft.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/is_finite.ts b/tfjs-core/src/public/chained_ops/is_finite.ts index c93d5be6a35..79f05037665 100644 --- a/tfjs-core/src/public/chained_ops/is_finite.ts +++ b/tfjs-core/src/public/chained_ops/is_finite.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/is_inf.ts b/tfjs-core/src/public/chained_ops/is_inf.ts index 97e35eadfcf..2fb687554b6 100644 --- a/tfjs-core/src/public/chained_ops/is_inf.ts +++ b/tfjs-core/src/public/chained_ops/is_inf.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/is_nan.ts b/tfjs-core/src/public/chained_ops/is_nan.ts index 96f7393d01a..beb61025971 100644 --- a/tfjs-core/src/public/chained_ops/is_nan.ts +++ b/tfjs-core/src/public/chained_ops/is_nan.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/less_equal_strict.ts b/tfjs-core/src/public/chained_ops/less_equal_strict.ts index 9d8b40ecef7..925ced0efe8 100644 --- a/tfjs-core/src/public/chained_ops/less_equal_strict.ts +++ b/tfjs-core/src/public/chained_ops/less_equal_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/less_strict.ts b/tfjs-core/src/public/chained_ops/less_strict.ts index f8b0507606d..5dfefe4403b 100644 --- a/tfjs-core/src/public/chained_ops/less_strict.ts +++ b/tfjs-core/src/public/chained_ops/less_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/log.ts b/tfjs-core/src/public/chained_ops/log.ts index 4df7964e53b..fd69947052b 100644 --- a/tfjs-core/src/public/chained_ops/log.ts +++ b/tfjs-core/src/public/chained_ops/log.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/log1p.ts b/tfjs-core/src/public/chained_ops/log1p.ts index 3deed8de998..d3643356d36 100644 --- a/tfjs-core/src/public/chained_ops/log1p.ts +++ b/tfjs-core/src/public/chained_ops/log1p.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/log_sigmoid.ts b/tfjs-core/src/public/chained_ops/log_sigmoid.ts index 50720581927..40ad6796bc3 100644 --- a/tfjs-core/src/public/chained_ops/log_sigmoid.ts +++ b/tfjs-core/src/public/chained_ops/log_sigmoid.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/log_softmax.ts b/tfjs-core/src/public/chained_ops/log_softmax.ts index a2460dcfb63..4b9c3e959dd 100644 --- a/tfjs-core/src/public/chained_ops/log_softmax.ts +++ b/tfjs-core/src/public/chained_ops/log_softmax.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/maximum_strict.ts b/tfjs-core/src/public/chained_ops/maximum_strict.ts index 6a035f99057..c0449620727 100644 --- a/tfjs-core/src/public/chained_ops/maximum_strict.ts +++ b/tfjs-core/src/public/chained_ops/maximum_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/minimum_strict.ts b/tfjs-core/src/public/chained_ops/minimum_strict.ts index b3486448a3e..df0098effe3 100644 --- a/tfjs-core/src/public/chained_ops/minimum_strict.ts +++ b/tfjs-core/src/public/chained_ops/minimum_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/mod_strict.ts b/tfjs-core/src/public/chained_ops/mod_strict.ts index 74585edb127..91bf0b5925a 100644 --- a/tfjs-core/src/public/chained_ops/mod_strict.ts +++ b/tfjs-core/src/public/chained_ops/mod_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/mul_strict.ts b/tfjs-core/src/public/chained_ops/mul_strict.ts index f3b6825f1c4..b7d42f4c454 100644 --- a/tfjs-core/src/public/chained_ops/mul_strict.ts +++ b/tfjs-core/src/public/chained_ops/mul_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/neg.ts b/tfjs-core/src/public/chained_ops/neg.ts index 86f1b513425..731097bd26f 100644 --- a/tfjs-core/src/public/chained_ops/neg.ts +++ b/tfjs-core/src/public/chained_ops/neg.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/norm.ts b/tfjs-core/src/public/chained_ops/norm.ts index 12d49ebda3f..16b3a77b8d7 100644 --- a/tfjs-core/src/public/chained_ops/norm.ts +++ b/tfjs-core/src/public/chained_ops/norm.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/not_equal_strict.ts b/tfjs-core/src/public/chained_ops/not_equal_strict.ts index 37ba97becaf..3e75b11a0b6 100644 --- a/tfjs-core/src/public/chained_ops/not_equal_strict.ts +++ b/tfjs-core/src/public/chained_ops/not_equal_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/ones_like.ts b/tfjs-core/src/public/chained_ops/ones_like.ts index d1658364bba..f1f25ea424d 100644 --- a/tfjs-core/src/public/chained_ops/ones_like.ts +++ b/tfjs-core/src/public/chained_ops/ones_like.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/pow_strict.ts b/tfjs-core/src/public/chained_ops/pow_strict.ts index 619f933b365..21f8353d74b 100644 --- a/tfjs-core/src/public/chained_ops/pow_strict.ts +++ b/tfjs-core/src/public/chained_ops/pow_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/reciprocal.ts b/tfjs-core/src/public/chained_ops/reciprocal.ts index d9b9467b66c..efc243adc65 100644 --- a/tfjs-core/src/public/chained_ops/reciprocal.ts +++ b/tfjs-core/src/public/chained_ops/reciprocal.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/reshape_as.ts b/tfjs-core/src/public/chained_ops/reshape_as.ts index b78a73444f1..8a5acead929 100644 --- a/tfjs-core/src/public/chained_ops/reshape_as.ts +++ b/tfjs-core/src/public/chained_ops/reshape_as.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/rfft.ts b/tfjs-core/src/public/chained_ops/rfft.ts index 2b19513e117..6ead3f76313 100644 --- a/tfjs-core/src/public/chained_ops/rfft.ts +++ b/tfjs-core/src/public/chained_ops/rfft.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/round.ts b/tfjs-core/src/public/chained_ops/round.ts index f1eba0bcd3f..c256237b34f 100644 --- a/tfjs-core/src/public/chained_ops/round.ts +++ b/tfjs-core/src/public/chained_ops/round.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/rsqrt.ts b/tfjs-core/src/public/chained_ops/rsqrt.ts index 22de240a917..3778ece8d68 100644 --- a/tfjs-core/src/public/chained_ops/rsqrt.ts +++ b/tfjs-core/src/public/chained_ops/rsqrt.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sigmoid.ts b/tfjs-core/src/public/chained_ops/sigmoid.ts index c664ecf1c3b..1a8d1499630 100644 --- a/tfjs-core/src/public/chained_ops/sigmoid.ts +++ b/tfjs-core/src/public/chained_ops/sigmoid.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sign.ts b/tfjs-core/src/public/chained_ops/sign.ts index e80745f8959..cfbb97266c6 100644 --- a/tfjs-core/src/public/chained_ops/sign.ts +++ b/tfjs-core/src/public/chained_ops/sign.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sin.ts b/tfjs-core/src/public/chained_ops/sin.ts index 9dd5ce2431c..db38b2080f8 100644 --- a/tfjs-core/src/public/chained_ops/sin.ts +++ b/tfjs-core/src/public/chained_ops/sin.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sinh.ts b/tfjs-core/src/public/chained_ops/sinh.ts index 61ff46ac51a..ed805595c0e 100644 --- a/tfjs-core/src/public/chained_ops/sinh.ts +++ b/tfjs-core/src/public/chained_ops/sinh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/slice.ts b/tfjs-core/src/public/chained_ops/slice.ts index 410826654ef..5d131a23519 100644 --- a/tfjs-core/src/public/chained_ops/slice.ts +++ b/tfjs-core/src/public/chained_ops/slice.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/softmax.ts b/tfjs-core/src/public/chained_ops/softmax.ts index 3a31877b61d..1a2802f6175 100644 --- a/tfjs-core/src/public/chained_ops/softmax.ts +++ b/tfjs-core/src/public/chained_ops/softmax.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/softplus.ts b/tfjs-core/src/public/chained_ops/softplus.ts index 7b8fd40ce0a..45770791aaa 100644 --- a/tfjs-core/src/public/chained_ops/softplus.ts +++ b/tfjs-core/src/public/chained_ops/softplus.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sqrt.ts b/tfjs-core/src/public/chained_ops/sqrt.ts index b2fdcb9fdca..12a1fbce870 100644 --- a/tfjs-core/src/public/chained_ops/sqrt.ts +++ b/tfjs-core/src/public/chained_ops/sqrt.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/square.ts b/tfjs-core/src/public/chained_ops/square.ts index 5f553be2552..c22ffc8ad70 100644 --- a/tfjs-core/src/public/chained_ops/square.ts +++ b/tfjs-core/src/public/chained_ops/square.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/squared_difference_strict.ts b/tfjs-core/src/public/chained_ops/squared_difference_strict.ts index 37164cdc322..91de2a81baf 100644 --- a/tfjs-core/src/public/chained_ops/squared_difference_strict.ts +++ b/tfjs-core/src/public/chained_ops/squared_difference_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/step.ts b/tfjs-core/src/public/chained_ops/step.ts index 57a06ce9805..d53fa8a9db2 100644 --- a/tfjs-core/src/public/chained_ops/step.ts +++ b/tfjs-core/src/public/chained_ops/step.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/strided_slice.ts b/tfjs-core/src/public/chained_ops/strided_slice.ts index 296045520e2..464b3447b02 100644 --- a/tfjs-core/src/public/chained_ops/strided_slice.ts +++ b/tfjs-core/src/public/chained_ops/strided_slice.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/sub_strict.ts b/tfjs-core/src/public/chained_ops/sub_strict.ts index 7197b64bfce..ffe044210f9 100644 --- a/tfjs-core/src/public/chained_ops/sub_strict.ts +++ b/tfjs-core/src/public/chained_ops/sub_strict.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/tan.ts b/tfjs-core/src/public/chained_ops/tan.ts index f0c5dbd46fc..5c128939630 100644 --- a/tfjs-core/src/public/chained_ops/tan.ts +++ b/tfjs-core/src/public/chained_ops/tan.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/tanh.ts b/tfjs-core/src/public/chained_ops/tanh.ts index 87b2394476b..0d42175c5f5 100644 --- a/tfjs-core/src/public/chained_ops/tanh.ts +++ b/tfjs-core/src/public/chained_ops/tanh.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/to_bool.ts b/tfjs-core/src/public/chained_ops/to_bool.ts index 9fc2c736492..f22c96ef5b5 100644 --- a/tfjs-core/src/public/chained_ops/to_bool.ts +++ b/tfjs-core/src/public/chained_ops/to_bool.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/to_float.ts b/tfjs-core/src/public/chained_ops/to_float.ts index 759a04c6e20..07587bdd204 100644 --- a/tfjs-core/src/public/chained_ops/to_float.ts +++ b/tfjs-core/src/public/chained_ops/to_float.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/to_int.ts b/tfjs-core/src/public/chained_ops/to_int.ts index 0777b53216f..4f4a3ee52bd 100644 --- a/tfjs-core/src/public/chained_ops/to_int.ts +++ b/tfjs-core/src/public/chained_ops/to_int.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/topk.ts b/tfjs-core/src/public/chained_ops/topk.ts index 183defac1d8..6d979187be1 100644 --- a/tfjs-core/src/public/chained_ops/topk.ts +++ b/tfjs-core/src/public/chained_ops/topk.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. diff --git a/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts b/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts index 5585d2ea297..01881dbbae4 100644 --- a/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts +++ b/tfjs-core/src/public/chained_ops/unsorted_segment_sum.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. From 85ffca225bec0db22c9f6b0200e347fc8944fc84 Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Tue, 30 Jun 2020 22:04:37 -0400 Subject: [PATCH 4/6] fix --- tfjs-core/src/public/chained_ops/zeros_like.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tfjs-core/src/public/chained_ops/zeros_like.ts b/tfjs-core/src/public/chained_ops/zeros_like.ts index 4fb2f5a3449..276317a2c04 100644 --- a/tfjs-core/src/public/chained_ops/zeros_like.ts +++ b/tfjs-core/src/public/chained_ops/zeros_like.ts @@ -1,4 +1,3 @@ - /** * @license * Copyright 2020 Google LLC. All Rights Reserved. From 4accc9d80e62d226375246d9cbda0855a1eb159d Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Tue, 30 Jun 2020 22:07:55 -0400 Subject: [PATCH 5/6] fix reshape imports --- tfjs-core/src/public/chained_ops/as1d.ts | 3 +-- tfjs-core/src/public/chained_ops/as2d.ts | 3 +-- tfjs-core/src/public/chained_ops/as3d.ts | 3 +-- tfjs-core/src/public/chained_ops/as4d.ts | 3 +-- tfjs-core/src/public/chained_ops/as5d.ts | 3 +-- tfjs-core/src/public/chained_ops/flatten.ts | 3 +-- tfjs-core/src/public/chained_ops/reshape_as.ts | 3 +-- 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tfjs-core/src/public/chained_ops/as1d.ts b/tfjs-core/src/public/chained_ops/as1d.ts index 9f8a4d730c3..e7c70538d31 100644 --- a/tfjs-core/src/public/chained_ops/as1d.ts +++ b/tfjs-core/src/public/chained_ops/as1d.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/as2d.ts b/tfjs-core/src/public/chained_ops/as2d.ts index ca60767eff6..fcfc57d6045 100644 --- a/tfjs-core/src/public/chained_ops/as2d.ts +++ b/tfjs-core/src/public/chained_ops/as2d.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/as3d.ts b/tfjs-core/src/public/chained_ops/as3d.ts index 81f372d4b58..30ace3e431a 100644 --- a/tfjs-core/src/public/chained_ops/as3d.ts +++ b/tfjs-core/src/public/chained_ops/as3d.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/as4d.ts b/tfjs-core/src/public/chained_ops/as4d.ts index 3fe7e575a4a..74f11aec5d7 100644 --- a/tfjs-core/src/public/chained_ops/as4d.ts +++ b/tfjs-core/src/public/chained_ops/as4d.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/as5d.ts b/tfjs-core/src/public/chained_ops/as5d.ts index eeafadfc4c0..b512a694cd9 100644 --- a/tfjs-core/src/public/chained_ops/as5d.ts +++ b/tfjs-core/src/public/chained_ops/as5d.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/flatten.ts b/tfjs-core/src/public/chained_ops/flatten.ts index 1d7ef7d5af9..b3192313569 100644 --- a/tfjs-core/src/public/chained_ops/flatten.ts +++ b/tfjs-core/src/public/chained_ops/flatten.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; diff --git a/tfjs-core/src/public/chained_ops/reshape_as.ts b/tfjs-core/src/public/chained_ops/reshape_as.ts index 8a5acead929..daf83797490 100644 --- a/tfjs-core/src/public/chained_ops/reshape_as.ts +++ b/tfjs-core/src/public/chained_ops/reshape_as.ts @@ -15,8 +15,7 @@ * ============================================================================= */ -// TODO update import path once op is modularized. -import {reshape} from '../../ops/ops'; +import {reshape} from '../../ops/reshape'; import {Tensor} from '../../tensor'; import {Rank} from '../../types'; From ccbd821f76ed0e1c6351e7292d8b25889ae92da9 Mon Sep 17 00:00:00 2001 From: Yannick Assogba Date: Wed, 1 Jul 2020 13:30:53 -0400 Subject: [PATCH 6/6] add js doc to to_type methods --- tfjs-core/src/public/chained_ops/to_bool.ts | 2 ++ tfjs-core/src/public/chained_ops/to_float.ts | 2 ++ tfjs-core/src/public/chained_ops/to_int.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tfjs-core/src/public/chained_ops/to_bool.ts b/tfjs-core/src/public/chained_ops/to_bool.ts index f22c96ef5b5..700080ce3f5 100644 --- a/tfjs-core/src/public/chained_ops/to_bool.ts +++ b/tfjs-core/src/public/chained_ops/to_bool.ts @@ -26,6 +26,8 @@ declare module '../../tensor' { } } +/** Casts the array to type `bool` */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ Tensor.prototype.toBool = function(this: T): T { this.throwIfDisposed(); return cast(this, 'bool'); diff --git a/tfjs-core/src/public/chained_ops/to_float.ts b/tfjs-core/src/public/chained_ops/to_float.ts index 07587bdd204..765ced0b956 100644 --- a/tfjs-core/src/public/chained_ops/to_float.ts +++ b/tfjs-core/src/public/chained_ops/to_float.ts @@ -26,6 +26,8 @@ declare module '../../tensor' { } } +/** Casts the array to type `float32` */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ Tensor.prototype.toFloat = function(this: T): T { this.throwIfDisposed(); return cast(this, 'float32'); diff --git a/tfjs-core/src/public/chained_ops/to_int.ts b/tfjs-core/src/public/chained_ops/to_int.ts index 4f4a3ee52bd..24a8530df7d 100644 --- a/tfjs-core/src/public/chained_ops/to_int.ts +++ b/tfjs-core/src/public/chained_ops/to_int.ts @@ -26,6 +26,8 @@ declare module '../../tensor' { } } +/** Casts the array to type `int32` */ +/** @doc {heading: 'Tensors', subheading: 'Classes'} */ Tensor.prototype.toInt = function(this: T): T { this.throwIfDisposed(); return cast(this, 'int32');