@@ -305,3 +305,52 @@ def test_jax_len():
305305
306306 for row in t_i :
307307 assert len (row ) == 4
308+
309+
310+ def test_jax_dimension_addition ():
311+ """Test jax_getitem with dimension addition via None indexing."""
312+ i = defop (jax .Array , name = "i" )
313+ i2 = defop (i )
314+
315+ # Basic case: indexing with slice and defop
316+ x = jax_getitem (jnp .eye (3 ), (i (), slice (None )))
317+ assert x .shape == (3 ,)
318+ assert fvsof (x ) >= {i }
319+
320+ # Multiple defops with None - this should work fine
321+ x2 = jax_getitem (jnp .eye (3 ), (i (), i2 (), None ))
322+ assert x2 .shape == (1 ,)
323+ assert fvsof (x2 ) >= {i , i2 }
324+
325+ # The problematic case: indexing a Term with defop and None
326+ # This should work but may currently fail
327+ x3 = jax_getitem (x , (i2 (), None ))
328+ assert x3 .shape == (1 ,)
329+ assert fvsof (x3 ) >= {i , i2 }
330+
331+ # Additional test cases for dimension addition
332+ # Test with multiple None dimensions
333+ x4 = jax_getitem (x , (i2 (), None , None ))
334+ assert x4 .shape == (1 , 1 )
335+ assert fvsof (x4 ) >= {i , i2 }
336+
337+ # Test with slice and None
338+ x5 = jax_getitem (x , (slice (None ), None ))
339+ assert x5 .shape == (3 , 1 )
340+ assert fvsof (x5 ) >= {i }
341+
342+ # Test with Ellipsis and None
343+ x6 = jax_getitem (x , (..., None ))
344+ assert x6 .shape == (3 , 1 )
345+ assert fvsof (x6 ) >= {i }
346+
347+ # Test nested indexing with dimension addition
348+ base = jnp .ones ((2 , 3 , 4 ))
349+ y = jax_getitem (base , (i (), slice (None ), slice (None )))
350+ assert y .shape == (3 , 4 )
351+ assert fvsof (y ) >= {i }
352+
353+ # Index the result with another defop and add dimension
354+ y2 = jax_getitem (y , (i2 (), slice (None ), None ))
355+ assert y2 .shape == (4 , 1 )
356+ assert fvsof (y2 ) >= {i , i2 }
0 commit comments