Source code for auto_diff.op.op_placeholder

from typing import Mapping, Union, Sequence
import numpy as np
from .operation import Operation


[docs]class OpPlaceholder(Operation): """The placeholder that represents values to be feed."""
[docs] def __init__(self, shape: Sequence[int], **kwargs): """ :param shape: Shape of the value. :param kwargs: """ self.shape = tuple(shape) super(OpPlaceholder, self).__init__(**kwargs)
[docs] def _get_name(self) -> str: return 'X%s' % str(self.shape)
[docs] def _get_op_name(self) -> str: return 'x_%d' % self._op_index
[docs] def _forward(self, feed_dict: Mapping[Union[str, 'OpPlaceholder'], np.ndarray]): """Finds and returns the value in feed dictionary.""" return feed_dict[self]
[docs] def _backward(self, gradient: Operation) -> None: """No backward operation needed.""" pass