File tree Expand file tree Collapse file tree
packages/react-native-executorch/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { ResourceFetcher } from '../../utils/ResourceFetcher' ;
2- import { ResourceSource } from '../../types/common' ;
2+ import { getArrayConstructor , ResourceSource } from '../../types/common' ;
33import { TensorPtr } from '../../types/common' ;
44import { ETError , getError } from '../../Error' ;
55import { BaseNonStaticModule } from '../BaseNonStaticModule' ;
@@ -16,9 +16,13 @@ export class ImageEmbeddingsModule extends BaseNonStaticModule {
1616 this . nativeModule = global . loadImageEmbeddings ( paths [ 0 ] || '' ) ;
1717 }
1818
19- async forward ( imageSource : string ) : Promise < TensorPtr > {
19+ async forward ( imageSource : string ) : Promise < number [ ] > {
2020 if ( this . nativeModule == null )
2121 throw new Error ( getError ( ETError . ModuleNotLoaded ) ) ;
22- return await this . nativeModule . generate ( imageSource ) ;
22+ const tensor : TensorPtr = await this . nativeModule . generate ( imageSource ) ;
23+
24+ const resultArray = getArrayConstructor ( tensor . scalarType ) ( tensor . dataPtr ) ;
25+
26+ return Array . from ( resultArray ) ;
2327 }
2428}
Original file line number Diff line number Diff line change @@ -7,6 +7,16 @@ export const getTypeIdentifier = (input: ETInput): number => {
77 return - 1 ;
88} ;
99
10+ export const getArrayConstructor = (
11+ scalarType : ScalarType
12+ ) : ( ( arr : TensorBuffer ) => Float32Array ) => {
13+ if ( scalarType === ScalarType . FLOAT )
14+ return ( arr : TensorBuffer ) => new Float32Array ( arr as Float32Array ) ;
15+ // todo add more types?
16+
17+ throw Error ( "We don't handle this type of output array" ) ;
18+ } ;
19+
1020export type ResourceSource = string | number | object ;
1121
1222export type ETInput =
You can’t perform that action at this time.
0 commit comments