r""" Compute the layer output on a single minibatch. Parameters ---------- X : :py:class:`ndarray ` Input volume to flatten. retain_derived : bool Whether to retain the variables calculated during the forward pass
(self, X, retain_derived=True)
| 910 | } |
| 911 | |
| 912 | def forward(self, X, retain_derived=True): |
| 913 | r""" |
| 914 | Compute the layer output on a single minibatch. |
| 915 | |
| 916 | Parameters |
| 917 | ---------- |
| 918 | X : :py:class:`ndarray <numpy.ndarray>` |
| 919 | Input volume to flatten. |
| 920 | retain_derived : bool |
| 921 | Whether to retain the variables calculated during the forward pass |
| 922 | for use later during backprop. If False, this suggests the layer |
| 923 | will not be expected to backprop through wrt. this input. Default |
| 924 | is True. |
| 925 | |
| 926 | Returns |
| 927 | ------- |
| 928 | Y : :py:class:`ndarray <numpy.ndarray>` of shape `(*out_dims)` |
| 929 | Flattened output. If `keep_dim` is `'first'`, `X` is reshaped to |
| 930 | ``(X.shape[0], -1)``, otherwise ``(-1, X.shape[0])``. |
| 931 | """ |
| 932 | if retain_derived: |
| 933 | self.derived_variables["in_dims"].append(X.shape) |
| 934 | if self.keep_dim == -1: |
| 935 | return X.flatten().reshape(1, -1) |
| 936 | rs = (X.shape[0], -1) if self.keep_dim == "first" else (-1, X.shape[-1]) |
| 937 | return X.reshape(*rs) |
| 938 | |
| 939 | def backward(self, dLdy, retain_grads=True): |
| 940 | r""" |
nothing calls this directly
no outgoing calls
no test coverage detected