MCPcopy Create free account
hub / github.com/alibaba/animate-anything / get_aligned_sequences

Function get_aligned_sequences

utils/seq_aligner.py:79–104  ·  view source on GitHub ↗
(x, y, trace_back)

Source from the content-addressed store, hash-verified

77
78
79def get_aligned_sequences(x, y, trace_back):
80 x_seq = []
81 y_seq = []
82 i = len(x)
83 j = len(y)
84 mapper_y_to_x = []
85 while i > 0 or j > 0:
86 if trace_back[i, j] == 3:
87 x_seq.append(x[i-1])
88 y_seq.append(y[j-1])
89 i = i-1
90 j = j-1
91 mapper_y_to_x.append((j, i))
92 elif trace_back[i][j] == 1:
93 x_seq.append('-')
94 y_seq.append(y[j-1])
95 j = j-1
96 mapper_y_to_x.append((j, -1))
97 elif trace_back[i][j] == 2:
98 x_seq.append(x[i-1])
99 y_seq.append('-')
100 i = i-1
101 elif trace_back[i][j] == 4:
102 break
103 mapper_y_to_x.reverse()
104 return x_seq, y_seq, torch.tensor(mapper_y_to_x, dtype=torch.int64)
105
106
107def get_mapper(x: str, y: str, tokenizer, max_len=77):

Callers 1

get_mapperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected