{"id":297193,"date":"2020-01-16T03:00:13","date_gmt":"2020-01-16T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297193"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297193","title":{"rendered":"Python (+numba) \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0441\u0438 \u2014 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e?! \u0427\u0430\u0441\u0442\u044c 2. \u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484142\/\">\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e numba. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/484136\/\">\u043f\u0435\u0440\u0432\u043e\u0439<\/a> \u0431\u044b\u043b\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438 numba. \u0417\u0434\u0435\u0441\u044c \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0441\u043b\u0435\u0433\u043a\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u0445\u0430\u0441\u043a\u0435\u043b\u043b \u00ab<a href=\"https:\/\/habr.com\/ru\/post\/483864\/\">\u0411\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c C++; \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c PHP<\/a>\u00bb \u0441 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u043c\u0438, \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 \u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438. \u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u044f \u0432\u0438\u0434\u0435\u043b \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/484002\/\">\u041e\u0445 \u0443\u0436 \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 C\/C++<\/a> \u0438, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u0434 \u043d\u0430 \u0441\u0438 \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u043a\u0438, \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u043d\u043e \u0434\u0430\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e, \u0447\u0442\u043e \u043f\u0438\u0442\u043e\u043d \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043f\u0440\u0435\u0432\u044b\u0441\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0441\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cq\/5p\/li\/cq5plijfdhg-zrez6jf9ruggab4.jpeg\"><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0417\u0430\u043c\u0435\u043d\u0438\u043b \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430 numpy-\u043c\u0430\u0441\u0441\u0438\u0432 (\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <code>v0[:]<\/code> \u043d\u0430 <code>v0.copy()<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 numpy <code>a[:]<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>view<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u0434\u0435\u043b\u0430\u043b \u00ab\u0440\u0430\u0437\u0432\u0451\u0440\u0442\u043a\u0443\u00bb \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u043e\u043c \u043a\u043e\u0434\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u043b <code>time.monotonic<\/code> \u043d\u0430 <code>time.perf_counter<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0442\u043e\u0447\u043d\u0435\u0435 (1us \u043f\u0440\u043e\u0442\u0438\u0432 1ms \u0443 monotonic).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 numba \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f jit-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f, \u044d\u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432 (\u043f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u043b\u0438 \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043c\u0438\u043d \u0432\u0440\u0435\u043c\u044f \u0438\u0437 \u0442\u0440\u0451\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0449\u0443\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0431\u043e\u0440\u044c\u0431\u044b \u0441 \u044d\u0442\u0438\u043c \u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c:<\/p>\n<p>  <\/p>\n<p>1) \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0430 \u0434\u0438\u0441\u043a:<\/p>\n<p>  <\/p>\n<p>@njit(cache=True)<br \/>  def lev_dist(s1: AnyStr, s2: AnyStr) -&gt; int:<\/p>\n<p>  <\/p>\n<p>\u0442\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0434\u0438\u0441\u043a\u0430. <\/p>\n<p>  <\/p>\n<p>2) \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 <\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0442\u043e\u043d \u043f\u0430\u0440\u0441\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 (\u0442\u043e\u0447\u043d\u0435\u0435, bytes), \u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0435\u0434\u0430\u0432\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043e\u043d\u0441\u0442\u0440\u0443\u043e\u0437\u043d\u0430\u044f (\u0441\u043c. \u043d\u0438\u0436\u0435). \u041e\u0431\u044b\u0447\u043d\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u043f\u043e\u043f\u0440\u043e\u0449\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@njit(nb.int64(nb.uint8[:], nb.uint8[:])) def lev_dist(s1, s2):<\/code><\/pre>\n<p>  <\/p>\n<p>\u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c bytes \u0432 numpy-\u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">s1_py = [int(x) for x in b\"a\" * 15000] s1 = np.array(s1_py, dtype=np.uint8)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">s1 = np.full(15000, ord('a'), dtype=np.uint8)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c bytes \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0432\u043e\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@njit(nb.int64(nb.bytes(nb.uint8, nb.1d, nb.C), nb.bytes(nb.uint8, nb.1d, nb.C))) def lev_dist(s1: AnyStr, s2: AnyStr) -&gt; int:<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f bytes \u0438 numpy-\u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 uint8 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435) \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f.<\/p>\n<p>  <\/p>\n<p>3) \u043f\u043e\u0434\u043e\u0433\u0440\u0435\u0432\u0430\u0442\u044c \u043a\u044d\u0448<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    s1 = b\"a\" * 15     # 15 \u0432\u043c\u0435\u0441\u0442\u043e 15000     s2 = s1     s3 = b\"b\" * 15      exec_time = -clock()      print(lev_dist(s1, s2))     print(lev_dist(s1, s3))      exec_time += clock()     print(f\"Finished in {exec_time:.3f}s\", file=sys.stderr)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u043c.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">#!\/usr\/bin\/env python3 import sys import time from numba import njit import numpy as np, numba as nb from time import perf_counter as clock  @njit(nb.int64(nb.uint8[::1], nb.uint8[::1])) def lev_dist(s1, s2):     m = len(s1)     n = len(s2)      # Edge cases.     if m == 0: return n     elif n == 0: return m      v0 = np.arange(n + 1)     v1 = v0.copy()      for i, c1 in enumerate(s1):         v1[0] = i + 1          for j, c2 in enumerate(s2):             subst_cost = v0[j] if c1 == c2 else (v0[j] + 1)             del_cost = v0[j + 1] + 1             ins_cost = v1[j] + 1              min_cost = min(subst_cost, del_cost, ins_cost)             v1[j + 1] = min_cost          v0, v1 = v1, v0      return v0[n]  if __name__ == \"__main__\":      fout = open('py.txt', 'w')         for n in 1000, 2000, 5000, 10000, 15000, 20000, 25000:             s1 = np.full(n, ord('a'), dtype=np.uint8)         s2 = s1         s3 = np.full(n, ord('b'), dtype=np.uint8)          exec_time = -clock()          print(lev_dist(s1, s2))         print(lev_dist(s1, s3))          exec_time += clock()         print(f'{n} {exec_time:.6f}', file=fout)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 \u0441\u0438 (clang -O3 -march=native)<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt;  static long lev_dist (const char *s1, unsigned long m,           const char *s2, unsigned long n) { \/\/    unsigned long m, n;     unsigned long i, j;     long *v0, *v1;     long ret, *temp;      \/* Edge cases. *\/     if (m == 0) {         return n;     } else if (n == 0) {         return m;     }      v0 = malloc (sizeof (long) * (n + 1));     v1 = malloc (sizeof (long) * (n + 1));      if (v0 == NULL || v1 == NULL) {         fprintf (stderr, \"failed to allocate memory\\n\");         exit (-1);     }      for (i = 0; i &lt;= n; ++i) {         v0[i] = i;     }     memcpy (v1, v0, sizeof(long) * (n + 1));      for (i = 0; i &lt; m; ++i) {         v1[0] = i + 1;          for (j = 0; j &lt; n; ++j) {             const long subst_cost = (s1[i] == s2[j]) ? v0[j] : (v0[j] + 1);             const long del_cost = v0[j + 1] + 1;             const long ins_cost = v1[j] + 1;  #if !defined(__GNUC__) || defined(__llvm__)             if (subst_cost &lt; del_cost) {                 v1[j + 1] = subst_cost;             } else {                 v1[j + 1] = del_cost;             } #else             v1[j + 1] = (subst_cost &lt; del_cost) ? subst_cost : del_cost; #endif             if (ins_cost &lt; v1[j + 1]) {                 v1[j + 1] = ins_cost;             }         }          temp = v0;         v0 = v1;         v1 = temp;     }      ret = v0[n];     free (v0);     free (v1);     return ret; }  int main () {     char s1[25001], s2[25001], s3[25001];     int lengths[] = {1000, 2000, 5000, 10000, 15000, 20000, 25000};     FILE *fout;     fopen_s(&amp;fout, \"c.txt\", \"w\");     for(int j = 0; j &lt; sizeof(lengths)\/sizeof(lengths[0]); j++){         int len = lengths[j];         int i;         clock_t start_time, exec_time;          for (i = 0; i &lt; len; ++i) {             s1[i] = 'a';             s2[i] = 'a';             s3[i] = 'b';         }         s1[len] = s2[len] = s3[len] = '\\0';          start_time = clock ();          printf (\"%ld\\n\", lev_dist (s1, len, s2, len));         printf (\"%ld\\n\", lev_dist (s1, len, s3, len));          exec_time = clock () - start_time;         fprintf(fout, \"%d %.6f\\n\", len,                  ((double) exec_time) \/ CLOCKS_PER_SEC);         fprintf (stderr,                 \"Finished in %.3fs\\n\",                 ((double) exec_time) \/ CLOCKS_PER_SEC);     }     return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u043f\u043e\u0434 windows (windows 10 x64, python 3.7.3, numba 0.45.1, clang 9.0.0, intel m5-6y54 skylake): \u0438 \u043f\u043e\u0434 linux (debian 4.9.30, python 3.7.4, numba 0.45.1, clang 9.0.0).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e x \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043f\u043e y \u0432\u0440\u0435\u043c\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.<\/p>\n<p>  <\/p>\n<p>Windows, \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043c\u0430\u0441\u0448\u0442\u0430\u0431:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fr\/tg\/bx\/frtgbxy6mdkyhjsbwebvqkdkww0.png\"><\/p>\n<p>  <\/p>\n<p>Windows, \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0430\u0441\u0448\u0442\u0430\u0431:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ic\/5f\/-u\/ic5f-ug_4gsdecruhdwzxzisslk.png\"><\/p>\n<p>  <\/p>\n<p>Linux, \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u043c\u0430\u0441\u0448\u0442\u0430\u0431:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qp\/k5\/u5\/qpk5u5ydo_4px2r7d0sb5vs-c7e.png\"><\/p>\n<p>  <\/p>\n<p>Linux, \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0430\u0441\u0448\u0442\u0430\u0431<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-4\/p8\/vo\/-4p8vogjaoud-g065w72v5mfrvk.png\"><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 clang \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432, \u0447\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0432\u044b\u0448\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u042f \u043d\u0435\u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u044d\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0435\u0441\u043b\u0438 numba \u043c\u043e\u0436\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0437\u043e\u0433\u043d\u0430\u0442\u044c, \u043e\u043d\u0430 \u044d\u0442\u043e \u0440\u0430\u0437\u0433\u043e\u043d\u044f\u0435\u0442 \u0434\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u0441\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e C (\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u0432\u0441\u0442\u0430\u0432\u043e\u043a). <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u0434 \u043d\u0430 \u0421 \u043f\u0440\u0430\u0432\u043a\u0438 \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/post\/484002\/\">\u041e\u0445 \u0443\u0436 \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 C\/C++<\/a> \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. <\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>PS \u041f\u0440\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u0434\u0430\u0442\u044c \u044f\u0432\u043d\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0435\u0440\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\/\u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432:<br \/>  \u0447\u0442\u043e\u0431\u044b numba \u043d\u0435 \u0440\u0430\u0437\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0430 &#8216;C&#8217; (\u0441\u0438) \u044d\u0442\u043e \u0438\u043b\u0438 &#8216;A'(\u0430\u0432\u0442\u043e\u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\/\u0444\u043e\u0440\u0442\u0440\u0430\u043d) \u2014 \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 uint8[:,:] \u044d\u0442\u043e &#8216;A&#8217; (\u0430\u0432\u0442\u043e\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435), nb.uint8[:, ::1] \u2013 \u044d\u0442\u043e &#8216;C&#8217; (\u0441\u0438), np.uint8[::1, :] \u2013 \u044d\u0442\u043e &#8216;F&#8217; (\u0444\u043e\u0440\u0442\u0440\u0430\u043d).<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">@njit(nb.int64(nb.uint8[::1], nb.uint8[::1])) def lev_dist(s1, s2):<\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/484142\/\"> https:\/\/habr.com\/ru\/post\/484142\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484142\/\">\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e numba. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/484136\/\">\u043f\u0435\u0440\u0432\u043e\u0439<\/a> \u0431\u044b\u043b\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438 numba. \u0417\u0434\u0435\u0441\u044c \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0441\u043b\u0435\u0433\u043a\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u0445\u0430\u0441\u043a\u0435\u043b\u043b \u00ab<a href=\"https:\/\/habr.com\/ru\/post\/483864\/\">\u0411\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c C++; \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c PHP<\/a>\u00bb \u0441 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u043c\u0438, \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 \u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438. \u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u044f \u0432\u0438\u0434\u0435\u043b \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habr.com\/ru\/post\/484002\/\">\u041e\u0445 \u0443\u0436 \u044d\u0442\u043e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 C\/C++<\/a> \u0438, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u0434 \u043d\u0430 \u0441\u0438 \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u043a\u0438, \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u043d\u043e \u0434\u0430\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e, \u0447\u0442\u043e \u043f\u0438\u0442\u043e\u043d \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043f\u0440\u0435\u0432\u044b\u0441\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0441\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u0441\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cq\/5p\/li\/cq5plijfdhg-zrez6jf9ruggab4.jpeg\"><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297193","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297193"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297193\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}