-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add swapdims op * add swapdims op * revise * revise * revise * revise op: swapaxes, swapdims, Transpose2dim * revise op: swapaxes, swapdims, Transpose2dim * revise Swapaxes and Swapdims * fix conflic * auto format by CI * fix python/oneflow/framework/docstr/swapdims.py * fix python/oneflow/framework/docstr/swapdims.py * refine Co-authored-by: chengyuma <chengyuma@github.com> Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org> Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com> Co-authored-by: Luyang <flowingsun007@163.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1223d4c
commit 345381a
Showing
12 changed files
with
139 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -143,6 +143,7 @@ oneflow | |
sqrt, | ||
square, | ||
swapaxes, | ||
swapdims, | ||
tan, | ||
tanh, | ||
tensor, | ||
|
This file contains 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 |
---|---|---|
|
@@ -153,6 +153,7 @@ OneFlow Tensor Class | |
stride, | ||
sum, | ||
swapaxes, | ||
swapdims, | ||
sub, | ||
sub_, | ||
tan, | ||
|
This file contains 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 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 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 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 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 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,53 @@ | ||
""" | ||
Copyright 2020 The OneFlow Authors. 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 oneflow | ||
from oneflow.framework.docstr.utils import add_docstr | ||
|
||
add_docstr( | ||
oneflow._C.swapdims, | ||
""" | ||
swapdims(input, dim0, dim1) -> Tensor | ||
This function is equivalent to torch’s swapdims function. | ||
For example: | ||
.. code-block:: python | ||
>>> import oneflow as flow | ||
>>> x = flow.tensor([[[0,1],[2,3]],[[4,5],[6,7]]]) | ||
>>> x | ||
tensor([[[0, 1], | ||
[2, 3]], | ||
<BLANKLINE> | ||
[[4, 5], | ||
[6, 7]]], dtype=oneflow.int64) | ||
>>> flow.swapdims(x, 0, 1) | ||
tensor([[[0, 1], | ||
[4, 5]], | ||
<BLANKLINE> | ||
[[2, 3], | ||
[6, 7]]], dtype=oneflow.int64) | ||
>>> flow.swapdims(x, 0, 2) | ||
tensor([[[0, 4], | ||
[2, 6]], | ||
<BLANKLINE> | ||
[[1, 5], | ||
[3, 7]]], dtype=oneflow.int64) | ||
""", | ||
) |
This file contains 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 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 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,47 @@ | ||
""" | ||
Copyright 2020 The OneFlow Authors. 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 unittest | ||
from collections import OrderedDict | ||
|
||
import numpy as np | ||
|
||
from oneflow.test_utils.automated_test_util import * | ||
from oneflow.test_utils.test_util import GenArgList | ||
|
||
import oneflow as flow | ||
import oneflow.unittest | ||
|
||
|
||
@flow.unittest.skip_unless_1n1d() | ||
class Testswapdims(flow.unittest.TestCase): | ||
@autotest(check_graph=True) | ||
def test_swapdims_flow_with_random_data(test_case): | ||
device = random_device() | ||
x = random_tensor(ndim=3).to(device) | ||
y = torch.swapdims(x, np.random.randint(0, 3), np.random.randint(0, 3)) | ||
return y | ||
|
||
@autotest(check_graph=True) | ||
def test_swapdims_flow_with_random_data2(test_case): | ||
device = random_device() | ||
x = random_tensor(ndim=4).to(device) | ||
y = torch.swapdims(x, np.random.randint(0, 4), np.random.randint(0, 4)) | ||
return y | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains 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