PIXELBANKv9.1.0
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: 1≤N≤10001 \leq N \leq 1000
  • Values are floats
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.