From ea274acd520abd3b7236618ec6774d268d6b8d67 Mon Sep 17 00:00:00 2001 From: tosemml <97384583+tosemml@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:16:31 -0700 Subject: [PATCH 1/2] use np.cumsum --- artificial_detection/models/smr/sais.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/artificial_detection/models/smr/sais.py b/artificial_detection/models/smr/sais.py index 252690b..7255728 100644 --- a/artificial_detection/models/smr/sais.py +++ b/artificial_detection/models/smr/sais.py @@ -1,3 +1,4 @@ +import numpy as np def construct_suffix_array(string): ta = construct_type_array(string) mapping = construct_alphabet_mapping(string) @@ -174,7 +175,5 @@ def get_bucket_heads(buckets): def get_bucket_tails(buckets): - tails = [0] - for bucket_size in buckets[1:]: - tails.append(tails[-1] + bucket_size) + tails = [0] + np.cumsum(buckets[1:]).tolist() return tails From d6f68bbe61addc77d666e517e79e1574f0a32319 Mon Sep 17 00:00:00 2001 From: tosemml <97384583+tosemml@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:19:51 -0700 Subject: [PATCH 2/2] use np.cumsum --- artificial_detection/models/smr/sais.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/artificial_detection/models/smr/sais.py b/artificial_detection/models/smr/sais.py index 7255728..e2d3027 100644 --- a/artificial_detection/models/smr/sais.py +++ b/artificial_detection/models/smr/sais.py @@ -168,9 +168,7 @@ def construct_buckets(encoded_string, mapping): def get_bucket_heads(buckets): - heads = [0] - for bucket_size in buckets[:-1]: - heads.append(heads[-1] + bucket_size) + heads = [0] + np.cumsum(buckets[:-1]).tolist() return heads