Skip to content

Commit 9b007b8

Browse files
committed
Shortcut S[i1, i2, ...] for creating a vector
And implement test for it.
1 parent 0462ee6 commit 9b007b8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/AbstractAlgebra.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,16 @@ include("KnownProperties.jl")
366366

367367
###############################################################################
368368
#
369-
# Syntax S[i] for all parents S as a shortcut for gen(S, i)
369+
# getindex methods
370370
#
371371
################################################################################
372372

373+
# Syntax S[i] for all parents S as a shortcut for gen(S, i)
373374
getindex(S::Set, i::Int) = gen(S, i)
374375

376+
# Syntax S[i1, i2, ...] for a vector
377+
getindex(S::Set, i...) = [S(ix) for ix in i]
378+
375379
###############################################################################
376380
#
377381
# Load error objects
@@ -392,7 +396,6 @@ include("broadcasting.jl")
392396

393397
include("Deprecations.jl")
394398

395-
396399
###############################################################################
397400
#
398401
# Set domain for ZZ, QQ
@@ -470,6 +473,7 @@ end
470473
# Utils
471474
#
472475
###############################################################################
476+
473477
include("utils.jl")
474478

475479
###############################################################################

test/AbstractAlgebra-test.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
@testset "getindex" begin
2+
Zxy, (x, y) = ZZ[:x, :y]
3+
v = Zxy[x^3, 3 * x^2 * y + 1, -3, ZZ(12)]
4+
5+
@test v == Zxy([x^3, 3 * x^2 * y + 1, -3, ZZ(12)])
6+
end
7+
18
include("error-test.jl")
29
include("AliasMacro-test.jl")
310
include("Attributes-test.jl")

0 commit comments

Comments
 (0)