Skip to main content

Linear

Struct Linear 

Source
pub struct Linear<D: Dtype, IT, OT, const RANK: usize> {
    pub in_features: usize,
    pub out_features: usize,
    pub has_bias: bool,
    /* private fields */
}
Expand description

Fully-connected linear layer: output = input × Wᵀ [+ b]

Operates on the last dimension of an N-D tensor, passing all leading dimensions through unchanged (e.g. a batch dimension).

Type parameters:

  • D — element dtype
  • IT — input tensor type (any rank, last dim = in_features)
  • OT — output tensor type (same rank, last dim = out_features)
  • RANK — tensor rank (1 = unbatched, 2 = batched, etc.)

Tensor bounds are on impls, not the struct, so SymTensor can have its own Layer impl without a coherence conflict.

Fields§

§in_features: usize

Size of the last input dimension.

§out_features: usize

Size of the last output dimension.

§has_bias: bool

Whether to add a learned bias.

Implementations§

Source§

impl<D: Dtype, IT, OT, const RANK: usize> Linear<D, IT, OT, RANK>

Source

pub fn new(in_features: usize, out_features: usize, has_bias: bool) -> Self

Creates a new Linear layer.

Trait Implementations§

Source§

impl<D: Dtype, IT: Tensor<D, RANK> + EagerTensor, OT: Tensor<D, RANK>, const RANK: usize> Layer<IT> for Linear<D, IT, OT, RANK>

Source§

type Output = OT

This layer’s output type.
Source§

fn call(&self, _input: IT) -> Self::Output

Applies this layer to input.
Source§

impl<D: Dtype, const RANK: usize> Layer<SymTensor> for Linear<D, SymTensor, SymTensor, RANK>

Source§

type Output = SymTensor

This layer’s output type.
Source§

fn call(&self, input: SymTensor) -> SymTensor

Applies this layer to input.

Auto Trait Implementations§

§

impl<D, IT, OT, const RANK: usize> Freeze for Linear<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> RefUnwindSafe for Linear<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> Send for Linear<D, IT, OT, RANK>
where D: Send, IT: Send, OT: Send,

§

impl<D, IT, OT, const RANK: usize> Sync for Linear<D, IT, OT, RANK>
where D: Sync, IT: Sync, OT: Sync,

§

impl<D, IT, OT, const RANK: usize> Unpin for Linear<D, IT, OT, RANK>
where D: Unpin, IT: Unpin, OT: Unpin,

§

impl<D, IT, OT, const RANK: usize> UnsafeUnpin for Linear<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> UnwindSafe for Linear<D, IT, OT, RANK>
where D: UnwindSafe, IT: UnwindSafe, OT: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.