88/**
99 * @param {TypedArray } input
1010 */
11- function interpolate ( input , [ in_channels , in_height , in_width ] , [ out_height , out_width ] , mode = 'bilinear' , align_corners = false ) {
11+ export function interpolate ( input , [ in_channels , in_height , in_width ] , [ out_height , out_width ] , mode = 'bilinear' , align_corners = false ) {
1212 // TODO use mode and align_corners
1313
1414 // Output image dimensions
@@ -86,7 +86,7 @@ function interpolate(input, [in_channels, in_height, in_width], [out_height, out
8686 * @param {number[] } axes
8787 * @returns {[T, number[]] } The transposed array and the new shape.
8888 */
89- function transpose_data ( array , dims , axes ) {
89+ export function transpose_data ( array , dims , axes ) {
9090 // Calculate the new shape of the transposed array
9191 // and the stride of the original array
9292 const shape = new Array ( axes . length ) ;
@@ -125,7 +125,7 @@ function transpose_data(array, dims, axes) {
125125 * @param {number[] } arr - The array of numbers to compute the softmax of.
126126 * @returns {number[] } The softmax array.
127127 */
128- function softmax ( arr ) {
128+ export function softmax ( arr ) {
129129 // Compute the maximum value in the array
130130 const maxVal = max ( arr ) [ 0 ] ;
131131
@@ -146,7 +146,7 @@ function softmax(arr) {
146146 * @param {number[] } arr - The input array to calculate the log_softmax function for.
147147 * @returns {any } - The resulting log_softmax array.
148148 */
149- function log_softmax ( arr ) {
149+ export function log_softmax ( arr ) {
150150 // Compute the softmax values
151151 const softmaxArr = softmax ( arr ) ;
152152
@@ -162,7 +162,7 @@ function log_softmax(arr) {
162162 * @param {number[] } arr2 - The second array.
163163 * @returns {number } - The dot product of arr1 and arr2.
164164 */
165- function dot ( arr1 , arr2 ) {
165+ export function dot ( arr1 , arr2 ) {
166166 return arr1 . reduce ( ( acc , val , i ) => acc + val * arr2 [ i ] , 0 ) ;
167167}
168168
@@ -174,7 +174,7 @@ function dot(arr1, arr2) {
174174 * @param {number } [top_k=0] - The number of top items to return (default: 0 = return all)
175175 * @returns {Array } - The top k items, sorted by descending order
176176 */
177- function getTopItems ( items , top_k = 0 ) {
177+ export function getTopItems ( items , top_k = 0 ) {
178178 // if top == 0, return all
179179
180180 items = Array . from ( items )
@@ -195,7 +195,7 @@ function getTopItems(items, top_k = 0) {
195195 * @param {number[] } arr2 - The second array.
196196 * @returns {number } The cosine similarity between the two arrays.
197197 */
198- function cos_sim ( arr1 , arr2 ) {
198+ export function cos_sim ( arr1 , arr2 ) {
199199 // Calculate dot product of the two arrays
200200 const dotProduct = dot ( arr1 , arr2 ) ;
201201
@@ -216,7 +216,7 @@ function cos_sim(arr1, arr2) {
216216 * @param {number[] } arr - The array to calculate the magnitude of.
217217 * @returns {number } The magnitude of the array.
218218 */
219- function magnitude ( arr ) {
219+ export function magnitude ( arr ) {
220220 return Math . sqrt ( arr . reduce ( ( acc , val ) => acc + val * val , 0 ) ) ;
221221}
222222
@@ -227,7 +227,7 @@ function magnitude(arr) {
227227 * @returns {number[] } - the value and index of the minimum element, of the form: [valueOfMin, indexOfMin]
228228 * @throws {Error } If array is empty.
229229 */
230- function min ( arr ) {
230+ export function min ( arr ) {
231231 if ( arr . length === 0 ) throw Error ( 'Array must not be empty' ) ;
232232 let min = arr [ 0 ] ;
233233 let indexOfMin = 0 ;
@@ -247,7 +247,7 @@ function min(arr) {
247247 * @returns {number[] } - the value and index of the maximum element, of the form: [valueOfMax, indexOfMax]
248248 * @throws {Error } If array is empty.
249249 */
250- function max ( arr ) {
250+ export function max ( arr ) {
251251 if ( arr . length === 0 ) throw Error ( 'Array must not be empty' ) ;
252252 let max = arr [ 0 ] ;
253253 let indexOfMax = 0 ;
@@ -265,7 +265,7 @@ function max(arr) {
265265 * FFT class provides functionality for performing Fast Fourier Transform on arrays
266266 * Code adapted from https://www.npmjs.com/package/fft.js
267267 */
268- class FFT {
268+ export class FFT {
269269 /**
270270 * @param {number } size - The size of the input array. Must be a power of two and bigger than 1.
271271 * @throws {Error } FFT size must be a power of two and bigger than 1.
@@ -757,16 +757,3 @@ class FFT {
757757 }
758758}
759759
760- module . exports = {
761- interpolate,
762- transpose : transpose_data ,
763- softmax,
764- log_softmax,
765- getTopItems,
766- dot,
767- cos_sim,
768- magnitude,
769- min,
770- max,
771- FFT
772- }
0 commit comments