Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for complex64 data type in parseDtypeParam function #8083

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tfjs-converter/src/operations/operation_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ export function parseDtypeParam(value: string|tensorflow.DataType): DataType {
return 'float32';
case tensorflow.DataType.DT_STRING:
return 'string';
case tensorflow.DataType.DT_COMPLEX64:
case tensorflow.DataType.DT_COMPLEX128:
return 'complex64';
default:
// Unknown dtype error will happen at runtime (instead of parse time),
// since these nodes might not be used by the actual subgraph execution.
Expand Down
20 changes: 17 additions & 3 deletions tfjs-converter/src/operations/operation_mapper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ const SIMPLE_MODEL: tensorflow.IGraphDef = {
input: ['BiasAdd'],
attr: {DstT: {type: tensorflow.DataType.DT_HALF}}
},
{
name: 'Cast4',
op: 'Cast',
input: ['BiasAdd'],
attr: {DstT: {type: tensorflow.DataType.DT_COMPLEX64}}
}
],
library: {
function: [
Expand Down Expand Up @@ -310,7 +316,7 @@ describe('operationMapper without signature', () => {
it('should find the graph output nodes', () => {
expect(convertedGraph.outputs.map(node => node.name)).toEqual([
'Fill', 'Squeeze', 'Squeeze2', 'Split', 'LogicalNot',
'FusedBatchNorm', 'Cast2', 'Cast3'
'FusedBatchNorm', 'Cast2', 'Cast3', 'Cast4'
]);
});

Expand All @@ -324,7 +330,7 @@ describe('operationMapper without signature', () => {
expect(Object.keys(convertedGraph.nodes)).toEqual([
'image_placeholder', 'Const', 'Shape', 'Value', 'Fill', 'Conv2D',
'BiasAdd', 'Cast', 'Squeeze', 'Squeeze2', 'Split', 'LogicalNot',
'FusedBatchNorm', 'Cast2', 'Cast3'
'FusedBatchNorm', 'Cast2', 'Cast3', 'Cast4'
]);
});
});
Expand Down Expand Up @@ -447,6 +453,10 @@ describe('operationMapper without signature', () => {
expect(convertedGraph.nodes['Cast'].attrParams['dtype'].value)
.toEqual('int32');
});
it('should map params with complex64 dtype', () => {
expect(convertedGraph.nodes['Cast4'].attrParams['dtype'].value)
.toEqual('complex64');
});
});
});
});
Expand Down Expand Up @@ -486,7 +496,7 @@ describe('operationMapper with signature', () => {
expect(Object.keys(convertedGraph.nodes)).toEqual([
'image_placeholder', 'Const', 'Shape', 'Value', 'Fill', 'Conv2D',
'BiasAdd', 'Cast', 'Squeeze', 'Squeeze2', 'Split', 'LogicalNot',
'FusedBatchNorm', 'Cast2', 'Cast3'
'FusedBatchNorm', 'Cast2', 'Cast3', 'Cast4'
]);
});
});
Expand Down Expand Up @@ -552,6 +562,10 @@ describe('operationMapper with signature', () => {
expect(convertedGraph.nodes['Cast3'].attrParams['dtype'].value)
.toEqual('float32');
});
it('should map params with complex64 dtype', () => {
expect(convertedGraph.nodes['Cast4'].attrParams['dtype'].value)
.toEqual('complex64');
});
});
});
});