All problems
RoPE Half-Split Rotation
Problem
Apply the half-split RoPE layout: pair coordinate i with coordinate i + d/2, use angle = position * theta_base^(-2i/d), and write out[i] = x[i] * cos - x[i + d/2] * sin and out[i + d/2] = x[i] * sin + x[i + d/2] * cos.
The signature is rope_half_split(x, position, theta_base=10000.0). d must be even; the adjacent-pair layout is a different convention.
Hint
Position 0 rotates every pair by angle 0 and leaves the vector unchanged.
Test cases
case 1
in: [[1,0,0,0],1]
expected: [0.5403023059,0,0.8414709848,0]
case 2
in: [[1,2,3,4],0]
expected: [1,2,3,4]
case 3
in: [[0,1,0,0],1,1]
expected: [0,0.5403023059,0,0.8414709848]
case 4
in: [[1,2,3,4],1]
expected: [-1.9841106486,1.9599006675,2.4623779024,4.0197996683]
Starter codePython
import math
def rope_half_split(x, position, theta_base=10000.0):
# Your code here
pass4 test cases · run your code against them in the editor