Skip to content

Commit 1c04be6

Browse files
committed
Added jagged_array(a) conversion function.
1 parent bb6c8cd commit 1c04be6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/jagged_array.jl

+18
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,22 @@ The returned object stores references to the given inputs.
195195
jagged_array(data,ptrs) = GenericJaggedArray(data,ptrs)
196196
jagged_array(data::Vector,ptrs::Vector) = JaggedArray(data,ptrs)
197197

198+
"""
199+
jagged_array(a)
200+
201+
Create a `JaggedArray` or a `GenericJaggedArray` from a given vector of vectors `a`.
202+
Return `a` if it is already a `JaggedArray` or a `GenericJaggedArray`.
203+
"""
204+
function jagged_array(a)
205+
JaggedArray(a)
206+
end
207+
function jagged_array(a::GenericJaggedArray)
208+
a
209+
end
210+
211+
212+
213+
214+
215+
198216

test/jagged_array_tests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ a = [[1,2],[3,4,5],Int[],[3,4]]
77
b = JaggedArray(a)
88
@test a == b
99
@test b === JaggedArray(b)
10+
b2 = jagged_array(b)
11+
@test b2 === b
1012
T = typeof(b)
1113
c = T(b.data,b.ptrs)
1214
@test c == b
@@ -16,10 +18,13 @@ d = collect(c)
1618
a = [[1,2],[3,4,5],Int[],[3,4]]
1719
b = JaggedArray(a)
1820
c = GenericJaggedArray(b.data,b.ptrs)
21+
c2 = jagged_array(c)
22+
@test c2 === c
1923
@test a == c
2024
T = typeof(c)
2125
d = T(c.data,c.ptrs)
2226
@test c == b
2327

28+
2429
end
2530

0 commit comments

Comments
 (0)