-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from toslunar/use-matmul
Use F.matmul instead of F.batch_matmul
- Loading branch information
Showing
3 changed files
with
35 additions
and
6 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
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,26 @@ | ||
try: | ||
from packaging import version | ||
except ImportError: | ||
from pip._vendor.packaging import version | ||
|
||
import chainer | ||
import chainer.functions as F | ||
|
||
|
||
chainer_version = version.parse(chainer.__version__) | ||
|
||
if chainer_version < version.parse('3.0.0a1'): | ||
"""Chainer's PR #2426 changed the behavior of matmul | ||
Simulate the newer behavior by functions in Chainer v2 | ||
""" | ||
def matmul_v3(a, b, **kwargs): | ||
if (a.ndim, b.ndim) == (3, 3): | ||
return F.batch_matmul(a, b, **kwargs) | ||
elif (a.ndim, b.ndim) == (2, 2): | ||
return F.matmul(a, b, **kwargs) | ||
else: | ||
raise Exception("unsupported shapes: {}, {}".format( | ||
a.shape, b.shape)) | ||
else: | ||
matmul_v3 = F.matmul |
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