license import { Shape , util } from '@tensorflow/tfjs' ; import { endianness } from 'os' ; const INT32_MAX = 2147483648 ; /**
 * Node.js-specific tensor type: int64-type scalar.
 *
 * This class is created for a specific purpose: to support
 * writing `step`s to TensorBoard via op-kernel bindings.
 * `step` is required to have an int64 dtype, but TensorFlow.js
 * (tfjs-core) doesn't have a built-in int64 dtype. This is
 * related to a lack of `Int64Array` or `Uint64Array` typed
 * array in basic JavaScript.
 *
 * This class is introduced as a workaround.
 */ export class Int64Scalar { readonly dtype : string = 'int64' ; readonly rank : number = 1 ; private valueArray_ : Int32Array ; private static endiannessOkay_ : boolean ; constructor ( readonly value ) { if ( Int64Scalar . endiannessOkay_ == null ) { if ( endianness ( ) !== 'LE' ) { throw new Error ( `Int64Scalar does not support endianness of this machine: ` + `${ endianness ( ) }` ) ; } Int64Scalar . endiannessOkay_ = true ; } util . assert ( value > - INT32_MAX && value < INT32_MAX - 1 , ( ) => `Got a value outside of the bound of values supported for int64 ` + `dtype ([-${ INT32_MAX }, ${ INT32_MAX - 1 }]): ${ value }` ) ; util . assert ( Number . isInteger ( value ) , ( ) => `Expected value to be an integer, but got ${ value }` ) ; const highPart = value >= 0 ? 0 : - 1 ; const lowPart = value % INT32_MAX ; this . valueArray_ = new Int32Array ( [ lowPart , highPart ] ) ; } get shape ( ) : Shape { return [ ] ; } /** Get the Int32Array that represents the int64 value. */ get valueArray ( ) : Int32Array { return this . valueArray_ ; } }