-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
flipud.py
37 lines (25 loc) · 872 Bytes
/
flipud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from chainer import backend
from chainer import function_node
from chainer.utils import type_check
class FlipUD(function_node.FunctionNode):
"""Flip array in the up/down direction."""
def check_type_forward(self, in_types):
type_check._argname(in_types, ('a',))
a_type = in_types[0]
type_check.expect(
a_type.dtype.kind == 'f',
a_type.ndim >= 1
)
def forward(self, inputs):
xp = backend.get_array_module(*inputs)
return xp.flipud(inputs[0]),
def backward(self, indexes, grad_outputs):
return FlipUD().apply(grad_outputs)
def flipud(a):
"""Flip array in the up/down direction.
Args:
a (:class:`~chainer.Variable` or :ref:`ndarray`): Input variable.
Returns:
~chainer.Variable: Output variable.
"""
return FlipUD().apply((a,))[0]