File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
packages/react-native-executorch/src Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { ResourceFetcher } from '../../utils/ResourceFetcher' ;
2
- import { ResourceSource } from '../../types/common' ;
2
+ import { getArrayConstructor , ResourceSource } from '../../types/common' ;
3
3
import { TensorPtr } from '../../types/common' ;
4
4
import { ETError , getError } from '../../Error' ;
5
5
import { BaseNonStaticModule } from '../BaseNonStaticModule' ;
@@ -16,9 +16,13 @@ export class ImageEmbeddingsModule extends BaseNonStaticModule {
16
16
this . nativeModule = global . loadImageEmbeddings ( paths [ 0 ] || '' ) ;
17
17
}
18
18
19
- async forward ( imageSource : string ) : Promise < TensorPtr > {
19
+ async forward ( imageSource : string ) : Promise < number [ ] > {
20
20
if ( this . nativeModule == null )
21
21
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 ) ;
23
27
}
24
28
}
Original file line number Diff line number Diff line change @@ -7,6 +7,16 @@ export const getTypeIdentifier = (input: ETInput): number => {
7
7
return - 1 ;
8
8
} ;
9
9
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
+
10
20
export type ResourceSource = string | number | object ;
11
21
12
22
export type ETInput =
You can’t perform that action at this time.
0 commit comments