Compute a dimension-safe LoRA forward pass
Implement lora_forward(W,A,B,x,scale=1.0) returning W*x + scale*B*(A*x). Require nonempty rectangular matrices, finite numeric entries, W shaped out by in, A shaped rank by in, B shaped out by rank, and x length in. Reject booleans as numbers and any incompatible dimension. Inputs must not be mutated. Standard-library loops are sufficient.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
EXAMPLE 1
InputW=[[1,0],[0,1]], A=[[1,-1]], B=[[2],[1]], x=[3,1], scale=0.5
Output[5.0,2.0]
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor