UNPKG

clustering-tfjs

Version:

High-performance TypeScript clustering algorithms (K-Means, Spectral, Agglomerative) with TensorFlow.js acceleration and scikit-learn compatibility

31 lines (30 loc) 905 B
"use strict"; /** * Utility functions for working with tensors across different environments */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isTensor = isTensor; exports.isTensor2D = isTensor2D; /** * Check if a value is a TensorFlow.js tensor * Works across different environments where tf.Tensor might not be directly available */ function isTensor(value) { if (!value || typeof value !== 'object') { return false; } // Check for tensor-like properties const obj = value; return (typeof obj.dtype === 'string' && typeof obj.shape === 'object' && Array.isArray(obj.shape) && typeof obj.rank === 'number' && typeof obj.dataSync === 'function' && typeof obj.dispose === 'function'); } /** * Check if a value is a 2D tensor */ function isTensor2D(value) { return isTensor(value) && value.rank === 2; }