Skip to content

Commit 441faa7

Browse files
committed
fix some bug in vector
1 parent d2087f4 commit 441faa7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cyaron/vector.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def random(num=5, position_range=[10], mode=0, **kwargs):
1212
if(num > 1000000):
1313
raise Exception("num no more than 1e6")
1414
if(not list_like(position_range)):
15-
raise Exception("the 2nd param must be a list, whose length = 1st param")
15+
raise Exception("the 2nd param must be a list")
16+
1617
dimension = len(position_range)
1718
offset = []
1819
vector_space = 1
@@ -27,6 +28,8 @@ def random(num=5, position_range=[10], mode=0, **kwargs):
2728
if(position_range[i] <= 0):
2829
raise Exception("the difference must more than 0")
2930
vector_space *= (position_range[i] + 1)
31+
if(mode == 0 and num > vector_space):
32+
raise Exception("1st param is too large that CYaRon can not generate unique vectors")
3033
result = []
3134

3235
if(mode == 2 or mode == 1):
@@ -45,7 +48,7 @@ def random(num=5, position_range=[10], mode=0, **kwargs):
4548
rand = random.randint(0, vector_space - 1);
4649
if(not rand in num_set):
4750
break
48-
# Todo: 这边效率如何?我认为是logn级别的检查
51+
# Todo: So how to analyse then complexity? I think it is logn
4952
num_set.add(rand)
5053
tmp = Vector.get_vector(dimension, position_range, rand)
5154
for j in range(0, dimension):
@@ -54,7 +57,7 @@ def random(num=5, position_range=[10], mode=0, **kwargs):
5457

5558

5659
else:
57-
# 生成0~vector_space的所有向量空间
60+
# generate 0~vector_space and shuffle
5861
rand_arr = [i for i in range(0, vector_space)]
5962
random.shuffle(rand_arr)
6063
for i in range(0, num):

0 commit comments

Comments
 (0)