Evaluate a dense layer whose weight rows and bias entries correspond to neurons in output order.
a=Wx+bHere x is inputs with length n, W is weight_matrix with shape (m, n), b is biases with length m, and a contains the m preactivations. When nonlinear is true, apply tanh to each preactivation; otherwise return the preactivations. Either width may be zero.
Return a one-dimensional PyTorch tensor of shape (m,) in weight-row order, preserving the common input dtype and device. A one-neuron result remains a vector; zero neurons produce an empty vector.
Input: inputs = [1,2,-1], weight_matrix = [[1,0,1],[0,2,0]], biases = [0.5,-0.5], nonlinear = false
Output: [0.5, 3.5]
Explanation: The first row gives 0.5 after bias, and the second gives 3.5.
Input: inputs = [2,1], weight_matrix = [[1,-1]], biases = [0], nonlinear = true
Output: [0.761594]
Input: inputs = [3,-2], weight_matrix = [[0,0],[0,0]], biases = [0,1], nonlinear = false
Output: [0.0, 1.0]
torch.mv computes a matrix-vector product.
torch.tanh applies independently to every tensor entry.
Avoid squeeze: a one-neuron layer still returns a vector.
Accepts: array
Accepts: array
Accepts: array
Evaluate a dense layer whose weight rows and bias entries correspond to neurons in output order.
a=Wx+bHere x is inputs with length n, W is weight_matrix with shape (m, n), b is biases with length m, and a contains the m preactivations. When nonlinear is true, apply tanh to each preactivation; otherwise return the preactivations. Either width may be zero.
Return a one-dimensional PyTorch tensor of shape (m,) in weight-row order, preserving the common input dtype and device. A one-neuron result remains a vector; zero neurons produce an empty vector.
Input: inputs = [1,2,-1], weight_matrix = [[1,0,1],[0,2,0]], biases = [0.5,-0.5], nonlinear = false
Output: [0.5, 3.5]
Explanation: The first row gives 0.5 after bias, and the second gives 3.5.
Input: inputs = [2,1], weight_matrix = [[1,-1]], biases = [0], nonlinear = true
Output: [0.761594]
Input: inputs = [3,-2], weight_matrix = [[0,0],[0,0]], biases = [0,1], nonlinear = false
Output: [0.0, 1.0]
torch.mv computes a matrix-vector product.
torch.tanh applies independently to every tensor entry.
Avoid squeeze: a one-neuron layer still returns a vector.
Accepts: array
Accepts: array
Accepts: array