2025-07-02 16:16:19 -07:00
|
|
|
/**
|
|
|
|
|
* Utility functions for TensorFlow.js compatibility
|
|
|
|
|
* This module provides utility functions that TensorFlow.js might need
|
|
|
|
|
* and avoids the need to use globalThis.util
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Import the TensorFlowUtilObject interface
|
|
|
|
|
import type {
|
|
|
|
|
TensorFlowUtilObject,
|
|
|
|
|
PlatformNodeObject
|
|
|
|
|
} from '../types/tensorflowTypes.js'
|
|
|
|
|
|
2025-07-04 14:42:33 -07:00
|
|
|
// Import the unified text encoding utilities
|
|
|
|
|
import { applyTensorFlowPatch } from './textEncoding.js'
|
2025-07-02 16:16:19 -07:00
|
|
|
|
2025-07-04 14:42:33 -07:00
|
|
|
// Apply the TensorFlow.js platform patch if needed
|
|
|
|
|
// This will define a global PlatformNode class that uses our text encoding utilities
|
|
|
|
|
applyTensorFlowPatch()
|
2025-07-02 16:16:19 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if an array is a Float32Array
|
|
|
|
|
* @param arr - The array to check
|
|
|
|
|
* @returns True if the array is a Float32Array
|
|
|
|
|
*/
|
|
|
|
|
export function isFloat32Array(arr: unknown): boolean {
|
|
|
|
|
return !!(
|
|
|
|
|
arr instanceof Float32Array ||
|
|
|
|
|
(arr && Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if an array is a TypedArray
|
|
|
|
|
* @param arr - The array to check
|
|
|
|
|
* @returns True if the array is a TypedArray
|
|
|
|
|
*/
|
|
|
|
|
export function isTypedArray(arr: unknown): boolean {
|
|
|
|
|
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
|
|
|
|
|
}
|