Linear

class Linear(in_features, out_features, bias=True, compute_mode='default', **kwargs)[source]

Applies a linear transformation to the input. For instance, if input is x, then output y is:

\[y = xW^T + b\]

where \(y_i= \sum_j W_{ij} x_j + b_i\)

Parameters
  • in_features (int) – size of each input sample.

  • out_features (int) – size of each output sample.

  • bias (bool) – if it’s False, the layer will not learn an additional bias. Default: True.

Shape:
  • x: \((*, H_{in})\), where * means any number of dimensions including none where \(H_{in}\) = in_features.

  • y: \((*, H_{out})\), where all but the last dimension are the same shape as the input where :math:`H_{out} = out_features.

Examples

>>> import numpy as np
>>> m = M.Linear(in_features=3, out_features=1)
>>> inp = mge.tensor(np.arange(0, 6).astype("float32").reshape(2, 3))
>>> oup = m(inp)
>>> oup.numpy().shape
(2, 1)