This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 144
EncodeBase64 and DecodeBase64 ops #376
Open
vabarbosa
wants to merge
15
commits into
tensorflow:master
Choose a base branch
from
vabarbosa:va_encode-decode-base64
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4e2e007
add encodeBase64
vabarbosa 0804b37
test encodeBase64
vabarbosa 7b0a333
add decodeBase64
vabarbosa 7f8e2f8
test decodeBase64
vabarbosa b16f0ba
add encodeBase64
vabarbosa 2106e9f
test encodeBase64
vabarbosa d469df0
add decodeBase64
vabarbosa ec81469
test decodeBase64
vabarbosa 93b528d
Merge branch 'va_encode-decode-base64' of https://github.com/vabarbos…
vabarbosa c9ba5f6
copyright 2019
vabarbosa c40b65c
remove tslint comment
vabarbosa 7663a37
remove empty line
vabarbosa fb065c7
copyright 2019
vabarbosa 8c0796e
Merge branch 'master' into va_encode-decode-base64
vabarbosa 8b4b740
Merge branch 'master' into va_encode-decode-base64
pyu10055 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ============================================================================= | ||
*/ | ||
|
||
import * as tfc from '@tensorflow/tfjs-core'; | ||
|
||
import {NamedTensorsMap} from '../../data/types'; | ||
import {ExecutionContext} from '../../executor/execution_context'; | ||
import {InternalOpExecutor, Node} from '../types'; | ||
|
||
import {getParamValue} from './utils'; | ||
|
||
export let executeOp: InternalOpExecutor = | ||
(node: Node, tensorMap: NamedTensorsMap, | ||
context: ExecutionContext): tfc.Tensor[] => { | ||
switch (node.op) { | ||
case 'DecodeBase64': { | ||
const input = | ||
getParamValue('str', node, tensorMap, context) as tfc.Tensor; | ||
return [tfc.decodeBase64(input)]; | ||
} | ||
case 'EncodeBase64': { | ||
const input = | ||
getParamValue('str', node, tensorMap, context) as tfc.Tensor; | ||
const pad = getParamValue('pad', node, tensorMap, context) as boolean; | ||
return [tfc.encodeBase64(input, pad)]; | ||
} | ||
default: | ||
throw TypeError(`Node type ${node.op} is not implemented`); | ||
} | ||
}; | ||
|
||
export const CATEGORY = 'string'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ============================================================================= | ||
*/ | ||
import * as tfc from '@tensorflow/tfjs-core'; | ||
|
||
import {ExecutionContext} from '../../executor/execution_context'; | ||
import {Node} from '../types'; | ||
|
||
import {executeOp} from './string_executor'; | ||
// tslint:disable-next-line:max-line-length | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed (c40b65c) |
||
import {createBoolAttr, createTensorAttr} from './test_helper'; | ||
|
||
describe('string', () => { | ||
let node: Node; | ||
const input1 = [tfc.tensor(['a'], [1], 'string')]; | ||
const context = new ExecutionContext({}, {}); | ||
|
||
beforeEach(() => { | ||
node = { | ||
name: 'test', | ||
op: '', | ||
category: 'string', | ||
inputNames: ['input1'], | ||
inputs: [], | ||
inputParams: {str: createTensorAttr(0)}, | ||
attrParams: {}, | ||
children: [] | ||
}; | ||
}); | ||
|
||
describe('executeOp', () => { | ||
describe('DecodeBase64', () => { | ||
it('should call tfc.decodeBase64', () => { | ||
spyOn(tfc, 'decodeBase64'); | ||
node.op = 'DecodeBase64'; | ||
executeOp(node, {input1}, context); | ||
expect(tfc.decodeBase64).toHaveBeenCalledWith(input1[0]); | ||
}); | ||
}); | ||
describe('EncodeBase64', () => { | ||
it('should call tfc.encodeBase64', () => { | ||
spyOn(tfc, 'encodeBase64'); | ||
node.op = 'EncodeBase64'; | ||
node.attrParams.pad = createBoolAttr(true); | ||
executeOp(node, {input1}, context); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the empty line here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done (7663a37) |
||
expect(tfc.encodeBase64).toHaveBeenCalledWith(input1[0], true); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {OpMapper} from '../types'; | ||
|
||
/** | ||
* @license | ||
* Copyright 2018 Google LLC. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ============================================================================= | ||
*/ | ||
|
||
export const json: OpMapper[] = [ | ||
{ | ||
'tfOpName': 'DecodeBase64', | ||
'category': 'string', | ||
'inputs': [{'start': 0, 'name': 'input', 'type': 'tensor'}] | ||
}, | ||
{ | ||
'tfOpName': 'EncodeBase64', | ||
'category': 'string', | ||
'inputs': [{'start': 0, 'name': 'input', 'type': 'tensor'}], | ||
'attrs': [{'tfName': 'pad', 'name': 'pad', 'type': 'bool'}] | ||
} | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update to 2019 for all files, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated (c9ba5f6, fb065c7)