📘
Bidirectional Scan for Vision
MediumArray, Algorithms
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]:
- 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 N: 1≤N≤1000
- Values are floats
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.