1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import * as tfc from '@tensorflow/tfjs-core';
|
18 | import { NodeValueImpl } from './custom_op/node_value_impl';
|
19 | import { getRegisteredOp } from './custom_op/register';
|
20 | import * as arithmetic from './executors/arithmetic_executor';
|
21 | import * as basicMath from './executors/basic_math_executor';
|
22 | import * as control from './executors/control_executor';
|
23 | import * as convolution from './executors/convolution_executor';
|
24 | import * as creation from './executors/creation_executor';
|
25 | import * as dynamic from './executors/dynamic_executor';
|
26 | import * as evaluation from './executors/evaluation_executor';
|
27 | import * as graph from './executors/graph_executor';
|
28 | import * as hashTable from './executors/hash_table_executor';
|
29 | import * as image from './executors/image_executor';
|
30 | import * as logical from './executors/logical_executor';
|
31 | import * as matrices from './executors/matrices_executor';
|
32 | import * as normalization from './executors/normalization_executor';
|
33 | import * as reduction from './executors/reduction_executor';
|
34 | import * as sliceJoin from './executors/slice_join_executor';
|
35 | import * as sparse from './executors/sparse_executor';
|
36 | import * as spectral from './executors/spectral_executor';
|
37 | import * as string from './executors/string_executor';
|
38 | import * as transformation from './executors/transformation_executor';
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export function executeOp(node, tensorMap, context, resourceManager) {
|
47 | const value = ((node, tensorMap, context) => {
|
48 | switch (node.category) {
|
49 | case 'arithmetic':
|
50 | return tfc.tidy(() => arithmetic.executeOp(node, tensorMap, context));
|
51 | case 'basic_math':
|
52 | return tfc.tidy(() => basicMath.executeOp(node, tensorMap, context));
|
53 | case 'control':
|
54 | return control.executeOp(node, tensorMap, context);
|
55 | case 'convolution':
|
56 | return tfc.tidy(() => convolution.executeOp(node, tensorMap, context));
|
57 | case 'creation':
|
58 | return tfc.tidy(() => creation.executeOp(node, tensorMap, context));
|
59 | case 'dynamic':
|
60 | return dynamic.executeOp(node, tensorMap, context);
|
61 | case 'evaluation':
|
62 | return tfc.tidy(() => evaluation.executeOp(node, tensorMap, context));
|
63 | case 'image':
|
64 | return tfc.tidy(() => image.executeOp(node, tensorMap, context));
|
65 | case 'graph':
|
66 | return tfc.tidy(() => graph.executeOp(node, tensorMap, context));
|
67 | case 'logical':
|
68 | return tfc.tidy(() => logical.executeOp(node, tensorMap, context));
|
69 | case 'matrices':
|
70 | return tfc.tidy(() => matrices.executeOp(node, tensorMap, context));
|
71 | case 'normalization':
|
72 | return tfc.tidy(() => normalization.executeOp(node, tensorMap, context));
|
73 | case 'reduction':
|
74 | return tfc.tidy(() => reduction.executeOp(node, tensorMap, context));
|
75 | case 'slice_join':
|
76 | return tfc.tidy(() => sliceJoin.executeOp(node, tensorMap, context));
|
77 | case 'sparse':
|
78 | return tfc.tidy(() => sparse.executeOp(node, tensorMap, context));
|
79 | case 'spectral':
|
80 | return tfc.tidy(() => spectral.executeOp(node, tensorMap, context));
|
81 | case 'string':
|
82 | return tfc.tidy(() => string.executeOp(node, tensorMap, context));
|
83 | case 'transformation':
|
84 | return tfc.tidy(() => transformation.executeOp(node, tensorMap, context));
|
85 | case 'hash_table':
|
86 | return hashTable.executeOp(node, tensorMap, context, resourceManager);
|
87 | case 'custom':
|
88 | const opMapper = getRegisteredOp(node.op);
|
89 | if (opMapper && opMapper.customExecutor) {
|
90 | return opMapper.customExecutor(new NodeValueImpl(node, tensorMap, context));
|
91 | }
|
92 | else {
|
93 | throw TypeError(`Custom op ${node.op} is not registered.`);
|
94 | }
|
95 | default:
|
96 | throw TypeError(`Unknown op '${node.op}'. File an issue at ` +
|
97 | `https://github.com/tensorflow/tfjs/issues so we can add it` +
|
98 | `, or register a custom execution with tf.registerOp()`);
|
99 | }
|
100 | })(node, tensorMap, context);
|
101 | if (tfc.util.isPromise(value)) {
|
102 | return value.then((data) => [].concat(data));
|
103 | }
|
104 | return [].concat(value);
|
105 | }
|
106 |
|
\ | No newline at end of file |