Skip to content

Commit 0de1d8d

Browse files
ahmedsabiepyu10055
andauthored
Add missing op categories in converter and tests (tensorflow#5114)
BUG Co-authored-by: Ping Yu <[email protected]>
1 parent d18351b commit 0de1d8d

File tree

6 files changed

+50
-37
lines changed

6 files changed

+50
-37
lines changed

tfjs-converter/scripts/gen_doc.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ import * as matrices from '../src/operations/op_list/matrices';
3131
import * as normalization from '../src/operations/op_list/normalization';
3232
import * as reduction from '../src/operations/op_list/reduction';
3333
import * as sliceJoin from '../src/operations/op_list/slice_join';
34+
import * as sparse from '../src/operations/op_list/sparse';
3435
import * as spectral from '../src/operations/op_list/spectral';
36+
import * as string from '../src/operations/op_list/string';
3537
import * as transformation from '../src/operations/op_list/transformation';
3638
import {OpMapper} from '../src/operations/types';
3739

3840
// tfjs-core api file is generated by tfjs-website project and should be
3941
// manually copied over before running this script.
4042
const JSON_DIR = './tfjs-core.json';
4143
const DOC_DIR = './docs/';
42-
4344
const ops = [
4445
arithmetic, basicMath, control, convolution, creation, dynamic, evaluation,
45-
logical, image, graph, matrices, normalization, reduction, sliceJoin,
46-
spectral, transformation
46+
graph, hashtable, image, logical, matrices, normalization, reduction,
47+
sliceJoin, sparse, spectral, string, transformation
4748
];
4849

4950
async function genDoc() {
@@ -86,15 +87,17 @@ async function genDoc() {
8687
generateTable(
8788
'Tensorflow', 'Graph', (graph.json as {}) as OpMapper[], output,
8889
coreApis);
89-
generateTable(
90-
'Operations', 'Logical', (logical.json as {}) as OpMapper[], output,
91-
coreApis);
9290
generateTable(
9391
'Operations', 'Hashtable', (hashtable.json as {}) as OpMapper[], output,
9492
coreApis);
9593
generateTable(
9694
'Operations', 'Images', (image.json as {}) as OpMapper[], output,
9795
coreApis);
96+
generateTable(
97+
'Operations', 'Linear Algebra', [] as OpMapper[], output, coreApis);
98+
generateTable(
99+
'Operations', 'Logical', (logical.json as {}) as OpMapper[], output,
100+
coreApis);
98101
generateTable(
99102
'Operations', 'Matrices', (matrices.json as {}) as OpMapper[], output,
100103
coreApis);
@@ -109,15 +112,19 @@ async function genDoc() {
109112
generateTable('Tensors', 'RNN', [] as OpMapper[], output, coreApis);
110113
generateTable('Operations', 'Scan', [] as OpMapper[], output, coreApis);
111114
generateTable('Operations', 'Segment', [] as OpMapper[], output, coreApis);
115+
generateTable('Operations', 'Signal', [] as OpMapper[], output, coreApis);
112116
generateTable(
113117
'Tensors', 'Slicing and Joining', (sliceJoin.json as {}) as OpMapper[],
114118
output, coreApis);
119+
generateTable(
120+
'Operations', 'Sparse', (sparse.json as {}) as OpMapper[], output,
121+
coreApis);
115122
generateTable(
116123
'Operations', 'Spectral', (spectral.json as {}) as OpMapper[], output,
117124
coreApis);
118-
generateTable('Operations', 'Signal', [] as OpMapper[], output, coreApis);
119125
generateTable(
120-
'Operations', 'Linear Algebra', [] as OpMapper[], output, coreApis);
126+
'Operations', 'String', (string.json as {}) as OpMapper[], output,
127+
coreApis);
121128
generateTable(
122129
'Tensors', 'Transformations', (transformation.json as {}) as OpMapper[],
123130
output, coreApis);

tfjs-converter/src/operations/op_list/op_list_test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import * as matrices from './matrices';
3232
import * as normalization from './normalization';
3333
import * as reduction from './reduction';
3434
import * as sliceJoin from './slice_join';
35+
import * as sparse from './sparse';
36+
import * as spectral from './spectral';
37+
import * as string from './string';
3538
import * as transformation from './transformation';
3639

3740
describe('OpListTest', () => {
@@ -45,16 +48,19 @@ describe('OpListTest', () => {
4548
basicMath,
4649
control,
4750
convolution,
51+
creation,
4852
dynamic,
4953
evaluation,
50-
creation,
51-
logical,
52-
image,
5354
graph,
55+
image,
56+
logical,
5457
matrices,
5558
normalization,
5659
reduction,
5760
sliceJoin,
61+
sparse,
62+
spectral,
63+
string,
5864
transformation
5965
};
6066
Object.keys(mappersJson).forEach(key => {

tfjs-converter/src/operations/operation_executor_test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import * as matrices from './executors/matrices_executor';
3737
import * as normalization from './executors/normalization_executor';
3838
import * as reduction from './executors/reduction_executor';
3939
import * as slice_join from './executors/slice_join_executor';
40+
import * as sparse from './executors/sparse_executor';
4041
import * as spectral from './executors/spectral_executor';
42+
import * as string from './executors/string_executor';
4143
import * as transformation from './executors/transformation_executor';
4244
import {executeOp} from './operation_executor';
4345
import {Node} from './types';
@@ -60,9 +62,9 @@ describe('OperationExecutor', () => {
6062
});
6163

6264
describe('executeOp', () => {
63-
[arithmetic, basic_math, convolution, control, creation, dynamic,
64-
evaluation, image, graph, logical, matrices, normalization, reduction,
65-
slice_join, spectral, transformation]
65+
[arithmetic, basic_math, control, convolution, creation, dynamic,
66+
evaluation, graph, image, logical, matrices, normalization, reduction,
67+
slice_join, sparse, spectral, string, transformation]
6668
.forEach(category => {
6769
it('should call ' + category.CATEGORY + ' executor', () => {
6870
spyOn(category, 'executeOp');
@@ -71,9 +73,9 @@ describe('OperationExecutor', () => {
7173
expect(category.executeOp).toHaveBeenCalledWith(node, {}, context);
7274
});
7375
});
74-
[arithmetic, basic_math, convolution, creation, evaluation, image, graph,
75-
logical, matrices, normalization, reduction, slice_join, spectral,
76-
transformation]
76+
[arithmetic, basic_math, convolution, creation, evaluation, graph, image,
77+
logical, matrices, normalization, reduction, slice_join, sparse, spectral,
78+
string, transformation]
7779
.forEach(category => {
7880
it('should call tidy around executor', () => {
7981
spyOn(tfc, 'tidy');

tfjs-converter/src/operations/operation_mapper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import * as matrices from './op_list/matrices';
3636
import * as normalization from './op_list/normalization';
3737
import * as reduction from './op_list/reduction';
3838
import * as sliceJoin from './op_list/slice_join';
39+
import * as sparse from './op_list/sparse';
3940
import * as spectral from './op_list/spectral';
41+
import * as string from './op_list/string';
4042
import * as transformation from './op_list/transformation';
4143
import {Graph, InputParamValue, Node, OpMapper, ParamValue} from './types';
4244

@@ -54,8 +56,8 @@ export class OperationMapper {
5456
private constructor() {
5557
const ops = [
5658
arithmetic, basicMath, control, convolution, creation, dynamic,
57-
evaluation, logical, image, graph, matrices, normalization, reduction,
58-
sliceJoin, spectral, transformation, hashTable
59+
evaluation, graph, hashTable, image, logical, matrices, normalization,
60+
reduction, sliceJoin, sparse, spectral, string, transformation
5961
];
6062
const mappersJson: OpMapper[] = [].concat(...ops.map(op => op.json));
6163

tfjs-converter/src/operations/operation_mapper_test.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ import * as creation from './op_list/creation';
2525
import * as dynamic from './op_list/dynamic';
2626
import * as evaluation from './op_list/evaluation';
2727
import * as graph from './op_list/graph';
28+
import * as hashTable from './op_list/hash_table';
2829
import * as image from './op_list/image';
2930
import * as logical from './op_list/logical';
3031
import * as matrices from './op_list/matrices';
3132
import * as normalization from './op_list/normalization';
3233
import * as reduction from './op_list/reduction';
3334
import * as sliceJoin from './op_list/slice_join';
35+
import * as sparse from './op_list/sparse';
3436
import * as spectral from './op_list/spectral';
37+
import * as string from './op_list/string';
3538
import * as transformation from './op_list/transformation';
3639
import {OperationMapper} from './operation_mapper';
3740
import {Graph} from './types';
3841

3942
const ops = [
4043
arithmetic, basicMath, control, convolution, creation, dynamic, evaluation,
41-
logical, image, graph, matrices, normalization, reduction, sliceJoin,
42-
spectral, transformation
44+
graph, hashTable, image, logical, matrices, normalization, reduction,
45+
sliceJoin, sparse, spectral, string, transformation
4346
];
4447
const mapper: OperationMapper = OperationMapper.Instance;
4548
let convertedGraph: Graph;
@@ -53,8 +56,7 @@ const SIMPLE_MODEL: tensorflow.IGraphDef = {
5356
dtype: {
5457
type: tensorflow.DataType.DT_FLOAT,
5558
},
56-
shape:
57-
{shape: {dim: [{size: '3'}, {size: 3}, {size: '3'}, {size: 1}]}}
59+
shape: {shape: {dim: [{size: '3'}, {size: 3}, {size: '3'}, {size: 1}]}}
5860
}
5961
},
6062
{
@@ -107,10 +109,8 @@ const SIMPLE_MODEL: tensorflow.IGraphDef = {
107109
name: 'BiasAdd',
108110
op: 'BiasAdd',
109111
input: ['Conv2D', 'Shape'],
110-
attr: {
111-
T: {type: tensorflow.DataType.DT_FLOAT},
112-
dataFormat: {s: 'TkhXQw=='}
113-
}
112+
attr:
113+
{T: {type: tensorflow.DataType.DT_FLOAT}, dataFormat: {s: 'TkhXQw=='}}
114114
},
115115
{
116116
name: 'Cast',
@@ -254,11 +254,8 @@ const SIGNATURE: tensorflow.ISignatureDef = {
254254
}
255255
},
256256
outputs: {
257-
squeeze: {
258-
name: 'Squeeze',
259-
dtype: tensorflow.DataType.DT_FLOAT,
260-
tensorShape: {}
261-
}
257+
squeeze:
258+
{name: 'Squeeze', dtype: tensorflow.DataType.DT_FLOAT, tensorShape: {}}
262259
}
263260
};
264261

@@ -372,8 +369,7 @@ describe('operationMapper without signature', () => {
372369
}
373370
},
374371
outputs: {
375-
identity:
376-
{name: 'Less:z:0', dtype: tensorflow.DataType.DT_BOOL}
372+
identity: {name: 'Less:z:0', dtype: tensorflow.DataType.DT_BOOL}
377373
}
378374
});
379375
});

tfjs-converter/src/operations/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import {ResourceManager} from '../executor/resource_manager';
2424
export type ParamType = 'number'|'string'|'string[]'|'number[]'|'bool'|'bool[]'|
2525
'shape'|'shape[]'|'tensor'|'tensors'|'dtype'|'dtype[]'|'func';
2626
export type Category = 'arithmetic'|'basic_math'|'control'|'convolution'|
27-
'custom'|'dynamic'|'evaluation'|'image'|'creation'|'graph'|'logical'|
28-
'matrices'|'normalization'|'reduction'|'slice_join'|'spectral'|
29-
'transformation'|'hash_table'|'sparse'|'string';
27+
'creation'|'custom'|'dynamic'|'evaluation'|'graph'|'hash_table'|'image'|
28+
'logical'|'matrices'|'normalization'|'reduction'|'slice_join'|'sparse'|
29+
'spectral'|'string'|'transformation';
3030

3131
// For mapping input or attributes of NodeDef into TensorFlow.js op param.
3232
export declare interface ParamMapper {

0 commit comments

Comments
 (0)