MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / mark_utf8_units

Function mark_utf8_units

common/train.cpp:806–819  ·  view source on GitHub ↗

mark each byte with its utf8 unit number. returns the number of utf8 characters. e.g. when bytes == '\x61\xD0\xB0\x62', then utf8_units will become [0,0,1,0] utf8_nunits will become [1,2,2,1] and 3 is returned. bytes where utf8_units is zero, are the begin of an utf8 character.

Source from the content-addressed store, hash-verified

804// utf8_nunits will become [1,2,2,1] and 3 is returned.
805// bytes where utf8_units is zero, are the begin of an utf8 character.
806static size_t mark_utf8_units(const char* bytes, int * utf8_units, int * utf8_nunits, size_t count) {
807 size_t offs = 0;
808 size_t count_utf8 = 0;
809 while(offs < count) {
810 int len = (int) utf8_len(bytes[offs]);
811 for (int i=0; i<len; ++i) {
812 utf8_units[offs+i] = i;
813 utf8_nunits[offs+i] = len;
814 }
815 offs += len;
816 ++count_utf8;
817 }
818 return count_utf8;
819}
820
821size_t tokenize_file(
822 struct llama_context * lctx,

Callers 1

tokenize_fileFunction · 0.85

Calls 1

utf8_lenFunction · 0.70

Tested by

no test coverage detected