PIXELBANKv8.2.1
Menu

Bidirectional Scan for Vision

Vision Mamba processes image patches bidirectionally to capture both forward and backward context, unlike the causal (left-to-right only) scanning in language models.

For a 1D sequence x=[x1,x2,...,xN]x = [x_1, x_2, ..., x_N]:

  • Forward scan: Cumulative sum from left to right
  • Backward scan: Cumulative sum from right to left
  • Output: Element-wise sum of forward and backward scans

This bidirectional approach ensures each patch attends to information from both directions, crucial for non-causal tasks like image classification.

Task: Implement the bidirectional scan fusion.

Example:

Input:
x = [1.0, 2.0, 3.0, 4.0]
Output:
[11.0, 12.0, 13.0, 14.0]
Reasoning:

Forward: [1, 3, 6, 10]. Backward: [10, 9, 7, 4]. Sum: [11, 12, 13, 14]. Each position aggregates information from all positions.

Constraints:

  • Sequence length NN: 1N10001 \leq N \leq 1000
  • Values are floats
Editor

Test Results

0/0
Run code to see test results.