@@ -162,6 +162,38 @@ f2 = VectorOfArray([[1.0, 2.0], [3.0]])
162162@test collect (view (f2, :, 1 )) == f2[:, 1 ]
163163@test collect (view (f2, :, 2 )) == f2[:, 2 ]
164164
165+ # Broadcasting of heterogeneous arrays (issue #454)
166+ u = VectorOfArray ([[1.0 ], [2.0 , 3.0 ]])
167+ @test length (view (u, :, 1 )) == 1
168+ @test length (view (u, :, 2 )) == 2
169+ # broadcast assignment into selected column (last index Int)
170+ u[:, 2 ] .= [10.0 , 11.0 ]
171+ @test u. u[2 ] == [10.0 , 11.0 ]
172+
173+ # 2D inner arrays (matrices) with ragged second dimension
174+ u = VectorOfArray ([zeros (1 , n) for n in (2 , 3 )])
175+ @test length (view (u, 1 , :, 1 )) == 2
176+ @test length (view (u, 1 , :, 2 )) == 3
177+ u[1 , :, 2 ] .= [1.0 , 2.0 , 3.0 ]
178+ @test u. u[2 ] == [1.0 2.0 3.0 ]
179+ # partial column selection by indices
180+ u[1 , [1 , 3 ], 2 ] .= [7.0 , 9.0 ]
181+ @test u. u[2 ] == [7.0 2.0 9.0 ]
182+
183+ # 3D inner arrays (tensors) with ragged third dimension
184+ u = VectorOfArray ([zeros (2 , 1 , n) for n in (2 , 3 )])
185+ @test size (view (u, :, :, :, 1 )) == (2 , 1 , 2 )
186+ @test size (view (u, :, :, :, 2 )) == (2 , 1 , 3 )
187+ # assign into a slice of the second inner array using last index Int
188+ u[2 , 1 , :, 2 ] .= [7.0 , 8.0 , 9.0 ]
189+ @test vec (u. u[2 ][2 , 1 , :]) == [7.0 , 8.0 , 9.0 ]
190+ # check mixed slicing with range on front dims
191+ u[1 : 2 , 1 , [1 , 3 ], 2 ] .= [1.0 3.0 ; 2.0 4.0 ]
192+ @test u. u[2 ][1 , 1 , 1 ] == 1.0
193+ @test u. u[2 ][2 , 1 , 1 ] == 2.0
194+ @test u. u[2 ][1 , 1 , 3 ] == 3.0
195+ @test u. u[2 ][2 , 1 , 3 ] == 4.0
196+
165197# Test that views can be modified
166198f3 = VectorOfArray ([[1.0 , 2.0 ], [3.0 , 4.0 , 5.0 ]])
167199v = view (f3, :, 2 )
@@ -259,14 +291,14 @@ a[1:8]
259291a[[1 , 3 , 8 ]]
260292
261293# ###################################################################
262- # test when VectorOfArray is constructed from a linearly indexed
294+ # test when VectorOfArray is constructed from a linearly indexed
263295# multidimensional array of arrays
264296# ###################################################################
265297
266298u_matrix = VectorOfArray ([[1 , 2 ] for i in 1 : 2 , j in 1 : 3 ])
267299u_vector = VectorOfArray ([[1 , 2 ] for i in 1 : 6 ])
268300
269- # test broadcasting
301+ # test broadcasting
270302function foo! (u)
271303 @. u += 2 * u * abs (u)
272304 return u
@@ -281,7 +313,7 @@ foo!(u_vector)
281313@test typeof (parent (similar (u_matrix))) == typeof (parent (u_matrix))
282314@test typeof (parent ((x -> x). (u_matrix))) == typeof (parent (u_matrix))
283315
284- # test efficiency
316+ # test efficiency
285317num_allocs = @allocations foo! (u_matrix)
286318@test num_allocs == 0
287319
0 commit comments