Skip to content

Commit f2e5572

Browse files
[tfjs-node] replace deprecated utils (#8425)
Co-authored-by: Matthew Soulanille <msoulanille@google.com>
1 parent 407c6e5 commit f2e5572

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

tfjs-node/src/kernels/TopK.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import {KernelConfig, scalar, TopK, TopKAttrs, TopKInputs} from '@tensorflow/tfjs';
19-
import {isNullOrUndefined} from 'util';
2019

2120
import {createTensorsTypeOpAttr, NodeJSKernelBackend} from '../nodejs_kernel_backend';
2221

@@ -28,8 +27,8 @@ export const topKConfig: KernelConfig = {
2827
const backend = args.backend as NodeJSKernelBackend;
2928
const {k, sorted} = args.attrs as unknown as TopKAttrs;
3029

31-
const kCount = isNullOrUndefined(k) ? 1 : k;
32-
const isSorted = isNullOrUndefined(sorted) ? true : sorted;
30+
const kCount = k ?? 1;
31+
const isSorted = sorted ?? true;
3332
const opAttrs = [
3433
{name: 'sorted', type: backend.binding.TF_ATTR_BOOL, value: isSorted},
3534
createTensorsTypeOpAttr('T', x.dtype),

tfjs-node/src/nodejs_kernel_backend.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import * as tf from '@tensorflow/tfjs';
1919
import {backend_util, BackendTimingInfo, DataId, DataType, KernelBackend, ModelTensorInfo, Rank, Scalar, scalar, ScalarLike, Tensor, Tensor1D, Tensor2D, Tensor3D, Tensor4D, TensorInfo, tidy, util} from '@tensorflow/tfjs';
20-
import {isArray, isNullOrUndefined} from 'util';
2120

2221
import {encodeInt32ArrayAsInt64, Int64Scalar} from './int64_tensors';
2322
import {TensorMetadata, TFEOpAttr, TFJSBinding} from './tfjs_binding';
@@ -740,7 +739,7 @@ export function getTFDType(dataType: tf.DataType): number {
740739
export function createTensorsTypeOpAttr(
741740
attrName: string,
742741
tensorsOrDtype: tf.Tensor|tf.Tensor[]|tf.DataType): TFEOpAttr {
743-
if (isNullOrUndefined(tensorsOrDtype)) {
742+
if (tensorsOrDtype === null || tensorsOrDtype === undefined) {
744743
throw new Error('Invalid input tensors value.');
745744
}
746745
return {
@@ -757,18 +756,18 @@ export function createTensorsTypeOpAttr(
757756
export function createOpAttr(
758757
attrName: string, tensorsOrDtype: tf.Tensor|tf.Tensor[]|tf.DataType,
759758
value: ScalarLike): TFEOpAttr {
760-
if (isNullOrUndefined(tensorsOrDtype)) {
759+
if (tensorsOrDtype === null || tensorsOrDtype === undefined) {
761760
throw new Error('Invalid input tensors value.');
762761
}
763762
return {name: attrName, type: nodeBackend().binding.TF_BOOL, value};
764763
}
765764

766765
/** Returns the dtype number for a single or list of input Tensors. */
767766
function getTFDTypeForInputs(tensors: tf.Tensor|tf.Tensor[]): number {
768-
if (isNullOrUndefined(tensors)) {
767+
if (tensors === null || tensors === undefined) {
769768
throw new Error('Invalid input tensors value.');
770769
}
771-
if (isArray(tensors)) {
770+
if (Array.isArray(tensors)) {
772771
for (let i = 0; i < tensors.length; i++) {
773772
return getTFDType(tensors[i].dtype);
774773
}

0 commit comments

Comments
 (0)