-
Notifications
You must be signed in to change notification settings - Fork 3.8k
SparseFillEmptyRows Op #7442
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
Merged
Merged
SparseFillEmptyRows Op #7442
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a14842c
Initial Commit
cf4f0bd
Fix formats
e50c7f3
Remove comments
43fc9ac
Black
09a8c5b
THreeops
6dba7f0
Add Frontend Code
d593612
Add Default Value to feed dict
326ba03
Add Frontend Code
54d64cb
New test Cases and new code to handle them
af86e6f
Add Python Implementation'
7281a75
Remove stuff
d432a19
Remove unused imports
7dff190
Pylint
58df4a8
Pylint
7013289
PyLint Shape Func
1c83857
Make tests cpu only
b6d3603
Add unsorted tests
f3fdc0a
Add frontend code
07062f6
Row Major Sorting Only Test
8316494
Handle Dynamic Shapes
e2781c1
Add dynamic input shapes
856bd6c
Dynamic Shape Tests
008d8d9
Add documentation
bdf9ab2
Dtypes
23d3f44
PR Comments
666eb71
Added comments and changed naming
d6b8964
Add comments
f1db781
Comments to Shape Func
e2d3d45
Documentation
dcc2d38
PR Changes
dd055b3
PR Comments
c43cda2
Resolve input and output dtype compat
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
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
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
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,109 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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, WITHnew_sparse_indices WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # pylint: disable=no-else-return, too-many-locals, too-many-arguments, too-many-branches | ||
| # pylint: disable=undefined-variable, invalid-name | ||
codeislife99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """SparseFillEmptyRows operator""" | ||
| from ..te import hybrid | ||
|
|
||
|
|
||
| @hybrid.script | ||
| def _sparse_fill_empty_rows( | ||
| sparse_indices, | ||
| sparse_values, | ||
| dense_shape, | ||
| default_value, | ||
| new_sparse_indices_shape, | ||
| new_sparse_values_shape, | ||
| empty_row_indicator_shape, | ||
| ): | ||
| default_value_ = int64(default_value[0]) | ||
| new_sparse_indices = output_tensor(new_sparse_indices_shape, "int64") | ||
codeislife99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new_sparse_values = output_tensor(new_sparse_values_shape, "int64") | ||
| empty_row_indicator = output_tensor(empty_row_indicator_shape, "int64") | ||
| new_sparse_indices_row_id = 0 | ||
|
|
||
| if int64(sparse_indices.shape[0]) == int64(0): # Handle Empty Case | ||
| # Fill all rows with default values | ||
| for i in range(0, new_sparse_indices_shape[0]): | ||
| new_sparse_indices[i, 0] = int64(i) | ||
| new_sparse_values[i] = default_value_ | ||
| empty_row_indicator[i] = int64(1) | ||
| for k in range(1, int64(new_sparse_indices_shape[1])): | ||
| new_sparse_indices[i, k] = int64(0) | ||
|
|
||
| return (new_sparse_indices, new_sparse_values, empty_row_indicator) | ||
|
|
||
| else: | ||
| # Iterate through sparse_indices and add rows if/when required | ||
| for i in range(0, int64(sparse_indices.shape[0])): | ||
| if i == 0: | ||
| prev_row_id = int64(0) | ||
| else: | ||
| prev_row_id = int64(sparse_indices[i - 1, 0] + 1) | ||
| row_id = int64(sparse_indices[i, 0]) | ||
|
|
||
| # Since input is in row-major order, add rows between prev_row_id and row_id | ||
| for j in range(prev_row_id, row_id): | ||
| new_sparse_indices[new_sparse_indices_row_id, 0] = int64(j) | ||
| for k in range(1, int64(new_sparse_indices_shape[1])): | ||
| new_sparse_indices[new_sparse_indices_row_id, k] = int64(0) | ||
| empty_row_indicator[prev_row_id] = int64(1) | ||
| new_sparse_values[new_sparse_indices_row_id] = default_value_ | ||
| new_sparse_indices_row_id += 1 | ||
|
|
||
| # Add current element to output | ||
| new_sparse_indices[new_sparse_indices_row_id, 0] = row_id | ||
| for k in range(1, int64(new_sparse_indices_shape[1])): | ||
| new_sparse_indices[new_sparse_indices_row_id, k] = int64(sparse_indices[i, k]) | ||
| new_sparse_values[new_sparse_indices_row_id] = int64(sparse_values[i]) | ||
| empty_row_indicator[row_id] = int64(0) | ||
| new_sparse_indices_row_id += 1 | ||
|
|
||
| # Add rows with default value if last row id of sparse_indices is not dense_shape[0] - 1 | ||
| for i in range( | ||
| int64(sparse_indices[sparse_indices.shape[0] - 1, 0] + 1), int64(dense_shape[0]) | ||
codeislife99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): | ||
|
|
||
| new_sparse_indices[new_sparse_indices_row_id, 0] = int64(i) | ||
| for k in range(1, int64(new_sparse_indices_shape[1])): | ||
| new_sparse_indices[new_sparse_indices_row_id, k] = int64(0) | ||
| empty_row_indicator[i] = int64(1) | ||
| new_sparse_values[new_sparse_indices_row_id] = default_value_ | ||
| new_sparse_indices_row_id += 1 | ||
|
|
||
| return (new_sparse_indices, new_sparse_values, empty_row_indicator) | ||
|
|
||
|
|
||
| def sparse_fill_empty_rows( | ||
| sparse_indices, | ||
| sparse_values, | ||
| dense_shape, | ||
| default_value, | ||
| new_sparse_indices_shape, | ||
| new_sparse_values_shape, | ||
| empty_row_indicator_shape, | ||
| ): | ||
| return _sparse_fill_empty_rows( | ||
| sparse_indices, | ||
| sparse_values, | ||
| dense_shape, | ||
| default_value, | ||
| new_sparse_indices_shape, | ||
| new_sparse_values_shape, | ||
| empty_row_indicator_shape, | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.