{"id":481162,"date":"2026-05-27T03:44:12","date_gmt":"2026-05-27T03:44:12","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=481162"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=481162","title":{"rendered":"\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c numpy, pandas, scipy \u0438 sklearn"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0421 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u00ab<a href=\"https:\/\/habr.com\/ru\/articles\/752762\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043c\u043f\u043e\u0440\u0442\u043e\u0437\u0430\u043c\u0435\u0449\u0430\u0435\u043c numpy, pandas, scipy \u0438 sklearn<\/a>\u00bb \u043f\u0440\u043e\u0448\u043b\u043e \u043f\u043e\u0447\u0442\u0438 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430. \u0412 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0438\u0437-\u0437\u0430 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u0441\u0438\u043b. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0435\u043d\u044f \u0440\u0430\u0441\u0441\u0442\u0440\u043e\u0438\u043b\u043e, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u044c\u0431\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <a class=\"mention\" href=\"\/users\/n-cube\">@N-Cube<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0441\u044f \u043c\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0438 \u0445\u043e\u0442\u0435\u043b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0432\u043e\u0435\u0433\u043e Jupyter Notebook.<\/p>\n<p>\u0412 \u0441\u0430\u043c\u044b\u0439 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0448\u0435\u043b \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 AI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0445\u043e\u0442\u044c \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u043b \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u0441 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u043b \u0432\u0441\u0435 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0445\u043e\u0437\u044f\u0438\u043d\u0430. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u0447\u0430\u043b \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434.<\/p>\n<p>\u0417\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 CUDA, \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0443\u0447\u043d\u044b\u0445 SIMD-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c SIMD, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430.<\/p>\n<p>\u042f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0434\u0432\u0443\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445: \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AVX-2 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435 Intel\u00ae Core\u2122 i7-4790K \u0438 AVX-512 \u043d\u0430 Intel\u00ae Xeon. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GPU, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c Python \u0438 \u043c\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u0440\u0430\u0432\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u2013 Ubuntu 24.04, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u2013 GNU 13.3.0.<\/p>\n<h2>\u041c\u0435\u0442\u043e\u0434 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u03c0<\/h2>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442: \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442: rx \u0438 ry, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1. \u042d\u0442\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f: \u0422\u043e\u0447\u043a\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u0439\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0440\u0443\u0433\u0430, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 dist \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 (0, 0) \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0434\u0438\u0443\u0441\u0430, \u0440\u0430\u0432\u043d\u043e\u0433\u043e 1. \u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b: rx\u00b2 + ry\u00b2 &lt; 1.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435: \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u03c0 (pi_est) \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0442\u043e\u0447\u0435\u043a, \u043f\u043e\u043f\u0430\u0432\u0448\u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u0440\u0443\u0433\u0430, \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: <a href=\"https:\/\/github.com\/mgorshkov\/np\/blob\/main\/samples\/monte-carlo\/compare_python_monte_carlo.py\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/np\/blob\/main\/samples\/monte-carlo\/compare_python_monte_carlo.py<\/a><\/p>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0439 \u043a\u043e\u0434<\/p>\n<pre><code class=\"python\">rx = np.random.rand(size)ry = np.random.rand(size)dist = rx * rx + ry * ryinside = np.sum(dist &lt; 1.0)pi_est = 4.0 * inside \/ size<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<pre><code class=\"cpp\">auto rx = random::rand(size);auto ry = random::rand(size);auto dist = rx * rx + ry * ry;auto inside = sum(\"dist&lt;1\", dist);double pi_est = 4 * static_cast&lt;double&gt;(inside) \/ size;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-2<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">Size<\/p>\n<\/td>\n<td>\n<p align=\"left\">Py time (us) <\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">Py mem (MiB)  <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ time (us)<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">C++ mem (MiB)<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">Speedup<\/p>\n<\/td>\n<td>\n<p align=\"left\">Mem ratio<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">100000<\/p>\n<\/td>\n<td>\n<p align=\"left\">4222<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">2.3<\/p>\n<\/td>\n<td>\n<p align=\"left\">638<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">1.5<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>6.62x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">19760<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">22.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">3386<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">15.3<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>5.84x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">10000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">181804<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">228.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">29889<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">152.6<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>6.08x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">100000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">1770601<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">2288.8<\/p>\n<\/td>\n<td>\n<p align=\"left\">313803<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">1525.9<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>5.64x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-512<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">Size<\/p>\n<\/td>\n<td>\n<p align=\"left\">Py time (us) <\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">Py mem (MiB)  <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ time (us)<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">C++ mem (MiB)<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">Speedup<\/p>\n<\/td>\n<td>\n<p align=\"left\">Mem ratio<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">100000<\/p>\n<\/td>\n<td>\n<p align=\"left\">7538<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">2.3<\/p>\n<\/td>\n<td>\n<p align=\"left\">2371<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">1.5<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>3.18x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">30011<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">22.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">3782<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">15.3<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>7.94x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">10000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">235035<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">228.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">23761<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">152.6<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>9.89x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">100000000<\/p>\n<\/td>\n<td>\n<p align=\"left\">6192049<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\">2288.8<\/p>\n<\/td>\n<td>\n<p align=\"left\">285586<\/p>\n<\/td>\n<td data-colwidth=\"105\" width=\"105\">\n<p align=\"left\">1525.9<\/p>\n<\/td>\n<td data-colwidth=\"106\" width=\"106\">\n<p align=\"left\"><strong>21.68x<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u041d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/h2>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f?<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0435\u043f\u043e\u043b\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u0443\u044e. \u041f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f $\\(B(a, b)\\)$ \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u043e\u0442 \u043d\u0443\u043b\u044f \u0434\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 $\\(a\\)$ \u0438 $\\(b\\)$:<\/p>\n<p>$$\\(B(a, b) = \\int_{0}^{1} t^{a-1} (1-t)^{b-1} \\, dt\\)$$<\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f?<\/p>\n<p>\u0412 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0439 \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0435\u043b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0430 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $\\(x\\)$ (\u0433\u0434\u0435 $\\(0 \\le x \\le 1\\))$. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u043e\u0442 $\\(0\\)$ \u0434\u043e $\\(x\\)$.<\/p>\n<p>\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u043d\u0430 \u043a\u0430\u043a $\\(B_x(a, b)\\)$ \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>$$\\(B_x(a, b) = \\int_{0}^{x} t^{a-1} (1-t)^{b-1} \\, dt\\)$$<\/p>\n<\/div>\n<\/details>\n<p>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: <a href=\"https:\/\/github.com\/mgorshkov\/scipy\/tree\/main\/benchmarks\/betainc\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/scipy\/tree\/main\/benchmarks\/betainc<\/a><\/p>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/env python3\"\"\"Python scipy betainc benchmark - called by the C++ comparison benchmark.Uses the same test parameters as the C++ benchmark for fair comparison.\"\"\"import timeimport sysimport scipy.specialdef benchmark_python_scipy():    a = 0.5 * 99997    b = 0.5 * 99997    x = 0.4    count = 0    res = 0.0    start = time.perf_counter_ns()    while x &lt; 0.6:        count += 1        res += scipy.special.betainc(a, b, x)        x += 0.000001    stop = time.perf_counter_ns()    diff = stop - start    print(f\"Result = {res}\")    print(f\"Time = {diff} ns\")    print(f\"Loops = {count}\")if __name__ == \"__main__\":    benchmark_python_scipy()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<pre><code class=\"cpp\">timespec start;clock_gettime(CLOCK_MONOTONIC, &amp;start);np::float_ a = 0.5 * 99997;np::float_ b = 0.5 * 99997;np::float_ x = 0.4;int count = 0;np::float_ res = 0;while (x &lt; 0.6) {    ++count;    res += scipy::special::betainc(a, b, x);    x += 0.000001;}timespec stop;clock_gettime(CLOCK_MONOTONIC, &amp;stop);std::uint64_t diff = 1000000000L * (stop.tv_sec - start.tv_sec) + stop.tv_nsec - start.tv_nsec;std::cout &lt;&lt; \"Result = \" &lt;&lt; res &lt;&lt; std::endl;std::cout &lt;&lt; \"Time = \" &lt;&lt; diff &lt;&lt; \" ns\" &lt;&lt; std::endl;std::cout &lt;&lt; \"Loops = \" &lt;&lt; count &lt;&lt; std::endl;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-2<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">Implementation<\/p>\n<\/td>\n<td>\n<p align=\"left\">Time (ns)<\/p>\n<\/td>\n<td>\n<p align=\"left\">Loops<\/p>\n<\/td>\n<td>\n<p align=\"left\">Speedup vs Python<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">C++ scipy (AVX2)<\/p>\n<\/td>\n<td>\n<p align=\"left\">115882110<\/p>\n<\/td>\n<td>\n<p align=\"left\">200000<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>2.26x<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Python scipy<\/p>\n<\/td>\n<td>\n<p align=\"left\">262307821<\/p>\n<\/td>\n<td>\n<p align=\"left\">200000<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.00x<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-512<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">Implementation<\/p>\n<\/td>\n<td>\n<p align=\"left\">Time (ns)<\/p>\n<\/td>\n<td>\n<p align=\"left\">Loops<\/p>\n<\/td>\n<td>\n<p align=\"left\">Speedup vs Python<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">C++ scipy (AVX512)<\/p>\n<\/td>\n<td>\n<p align=\"left\">113440191<\/p>\n<\/td>\n<td>\n<p align=\"left\">200000<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>2.75x<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Python scipy<\/p>\n<\/td>\n<td>\n<p align=\"left\">311787699<\/p>\n<\/td>\n<td>\n<p align=\"left\">200000<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.00x<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0411\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e Jupyter Notebook (\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b &#8212; \u043d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f)<\/h2>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"https:\/\/habr.com\/ru\/articles\/752762\/#comment_25829022\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/articles\/752762\/#comment_25829022<\/a><\/p>\n<p>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: <a href=\"https:\/\/github.com\/mgorshkov\/sklearn\/blob\/main\/samples\/gmt_trend_2d\/benchmark.cpp\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/sklearn\/blob\/main\/samples\/gmt_trend_2d\/benchmark.cpp<\/a><\/p>\n<p>\u041a\u043e\u0434 \u043d\u0430 Python<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from tabulate import tabulateimport numpy as npdef generate_data(rank, num_points, noise_level):    np.random.seed(42)    x = np.linspace(-10, 10, num_points)    y = np.linspace(-10, 10, num_points)    if rank == 1:        z = 3 * x + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    elif rank == 2:        z = 2 * x + 3 * y + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    elif rank == 3:        z = 2 * x**2 + 3 * y**2 + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    return datadef GMT_trend2d(data, rank):    import numpy as np    from sklearn.linear_model import LinearRegression    # scale factor for normally distributed data is 1.4826    # https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.median_abs_deviation.html    MAD_NORMALIZE = 1.4826    # significance value    sig_threshold = 0.51    if rank not in [1,2,3]:        raise Exception('Number of model parameters \"rank\" should be 1, 2, or 3')    #see gmt_stat.c    def gmtstat_f_q (chisq1, nu1, chisq2, nu2):        import scipy.special as sc        if chisq1 == 0.0:            return 1        if chisq2 == 0.0:            return 0        return sc.betainc(0.5*nu2, 0.5*nu1, chisq2\/(chisq2+chisq1))    if rank in [2,3]:        x = data[:,0]        x = np.interp(x, (x.min(), x.max()), (-1, +1))    if rank == 3:        y = data[:,1]        y = np.interp(y, (y.min(), y.max()), (-1, +1))    z = data[:,2]    w = np.ones(z.shape)    if rank == 1:        xy = np.expand_dims(np.zeros(z.shape),1)    elif rank == 2:        xy = np.expand_dims(x,1)    elif rank == 3:        xy = np.stack([x,y]).transpose()    # create linear regression object    mlr = LinearRegression()    chisqs = []    coeffs = []    while True:        # fit linear regression        mlr.fit(xy, z, sample_weight=w)        r = np.abs(z - mlr.predict(xy))        chisq = np.sum((r**2*w))\/(z.size-3)        chisqs.append(chisq)        k = 1.5 * MAD_NORMALIZE * np.median(r)        w = np.where(r &lt;= k, 1, (2*k\/r) - (k * k\/(r**2)))        sig = 1 if len(chisqs)==1 else gmtstat_f_q(chisqs[-1], z.size-3, chisqs[-2], z.size-3)        # Go back to previous model only if previous chisq &lt; current chisq        if len(chisqs)==1 or chisqs[-2] &gt; chisqs[-1]:            coeffs = [mlr.intercept_, *mlr.coef_]        #print ('chisq', chisq, 'significant', sig)        if sig &lt; sig_threshold:            break    # get the slope and intercept of the line best fit    return (coeffs[:rank])def calculate_mse(data, coeffs, rank):    z_actual = data[:, 2]    if rank == 1:        z_predicted = coeffs[0]    elif rank == 2:        # Interpolate x the same way as in GMT_trend2d        x = data[:, 0]        x_interp = np.interp(x, (x.min(), x.max()), (-1, +1))        z_predicted = coeffs[0] + coeffs[1] * x_interp    elif rank == 3:        # Interpolate x and y the same way as in GMT_trend2d        x = data[:, 0]        x_interp = np.interp(x, (x.min(), x.max()), (-1, +1))        y = data[:, 1]        y_interp = np.interp(y, (y.min(), y.max()), (-1, +1))        z_predicted = coeffs[0] + coeffs[1] * x_interp + coeffs[2] * y_interp    mse = np.mean((z_actual - z_predicted) ** 2)    return msedef test_mse(num_points = 100*1000, ranks = [1, 2, 3], noise_levels = [0, 1, 10, 50]):    import warnings    results = []    # Suppress the specific warning    with warnings.catch_warnings():        warnings.simplefilter(\"ignore\", category=RuntimeWarning)        for rank in ranks:            for noise_level in noise_levels:                data = generate_data(rank, num_points, noise_level)                # round the output                coeffs_gmt = [v.round(8) for v in GMT_trend2d(data, rank)]                mse_gmt = np.round(calculate_mse(data, coeffs_gmt, rank), 0)                results.append([rank, noise_level, mse_gmt])    headers = [\"Rank\", \"Noise Level\", \"GMT_trend2d, MSE\"]    print(tabulate(results, headers=headers))test_mse()<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">using namespace np;using namespace scipy;using namespace sklearn;auto generate_data(auto rank, auto num_points, auto noise_level) {    random::seed(42);    auto x = linspace(-10.0, 10.0, num_points);    auto y = linspace(-10.0, 10.0, num_points);    if (rank == 1) {        auto z = 3 * x + 5 + noise_level * random::randn(num_points);        return column_stack(x, y, z);    }    if (rank == 2) {        auto z = 2 * x + 3 * y + 5 + noise_level * random::randn(num_points);        return column_stack(x, y, z);    }    auto z = 2 * x * x + 3 * y * y + 5 + noise_level * random::randn(num_points);    return column_stack(x, y, z);}auto GMT_trend2d(const Array&lt;float_&gt; &amp;data, int rank) {    float_ MAD_NORMALIZE = 1.4826;    float_ sig_threshold = 0.51;    if (rank != 1 &amp;&amp; rank != 2 &amp;&amp; rank != 3) {        throw sklearn::RuntimeError(\"Number of model parameters \\\"rank\\\" should be 1, 2, or 3\");    }    auto gmtstat_f_q = [](float_ chisq1, float_ nu1, float_ chisq2, float_ nu2) {        if (chisq1 == 0.0) return 1.0;        if (chisq2 == 0.0) return 0.0;        return scipy::special::betainc(0.5 * nu2, 0.5 * nu1, chisq2 \/ (chisq2 + chisq1));    };    Array&lt;float_&gt; x;    if (rank == 2 || rank == 3) {        auto x_ = data[\":,0\"];        x = interp(x_, Array&lt;float_&gt;{x_.min(), x_.max()}, Array&lt;float_&gt;{-1, +1});    }    Array&lt;float_&gt; y;    if (rank == 3) {        auto y_ = data[\":,1\"];        y = interp(y_, Array&lt;float_&gt;{y_.min(), y_.max()}, Array&lt;float_&gt;{-1, +1});    }    auto z = data[\":, 2\"].copy();    Array&lt;float_&gt; w = ones(z.shape()).copy();    Array&lt;float_&gt; xy;    if (rank == 1) {        xy = expand_dims(zeros(z.shape()), 1);    } else if (rank == 2) {        xy = expand_dims(x, 1);    } else if (rank == 3) {        xy = stack(x, y).transpose();    }    auto mlr = linear_model::LinearRegression{};    std::vector&lt;float_&gt; chisqs;    Array&lt;float_&gt; coeffs;    while (true) {        mlr.fit(xy, z, w);        auto r = abs_sub(z, mlr.predict(xy));        auto chisq = sum_sq_weighted(r, w) \/ static_cast&lt;float_&gt;(z.size() - 3);        chisqs.push_back(chisq);        auto k = 1.5 * MAD_NORMALIZE * median(r);        w = where_tukey(r, k);        auto sig = (chisqs.size() == 1 ? 1 : gmtstat_f_q(chisqs[chisqs.size() - 1], static_cast&lt;float_&gt;(z.size() - 3), chisqs[chisqs.size() - 2], static_cast&lt;float_&gt;(z.size() - 3)));        if (chisqs.size() == 1 or chisqs[chisqs.size() - 2] &gt; chisqs[chisqs.size() - 1]) {            coeffs = mlr.coeffs_();        }        if (sig &lt; sig_threshold) {            break;        }    }    auto result = Array&lt;float_&gt;{};    for (int i = 0; i &lt; rank; ++i) {        result = append(result, Array&lt;float_&gt;{coeffs.get(i)});    }    return result;auto calculate_mse(const Array&lt;float_&gt; &amp;data, const Array&lt;float_&gt; &amp;coeffs, int rank) {    auto z_actual = data[\":,2\"].copy();    Array&lt;float_&gt; z_predicted;    if (rank == 1) {        z_predicted = coeffs.get(0) * ones(z_actual.shape());    } else if (rank == 2) {        \/\/ Interpolate x the same way as in GMT_trend2d        auto x_ = data[\":,0\"];        auto x = interp(x_, Array&lt;float_&gt;{x_.min(), x_.max()}, Array&lt;float_&gt;{-1, +1});        z_predicted = coeffs.get(0) + coeffs.get(1) * x;    } else if (rank == 3) {        \/\/ Interpolate x and y the same way as in GMT_trend2d        auto x_ = data[\":,0\"];        auto x = interp(x_, Array&lt;float_&gt;{x_.min(), x_.max()}, Array&lt;float_&gt;{-1, +1});        auto y_ = data[\":,1\"];        auto y = interp(y_, Array&lt;float_&gt;{y_.min(), y_.max()}, Array&lt;float_&gt;{-1, +1});        z_predicted = coeffs.get(0) + coeffs.get(1) * x + coeffs.get(2) * y;    }    using sklearn::metrics::mean_squared_error;    using sklearn::metrics::MeanSquaredErrorParameters;    MeanSquaredErrorParameters&lt;Array&lt;float_&gt;&gt; params{.y_true = z_actual, .y_pred = z_predicted};    return mean_squared_error(params);}void test_mse(int num_points = 100 * 1000, const std::vector&lt;int&gt; &amp;ranks = {1, 2, 3}, const std::vector&lt;int&gt; &amp;noise_levels = {0, 1, 10, 50}) {    std::vector&lt;std::tuple&lt;int, int, float_&gt;&gt; results;    for (auto rank: ranks) {        for (auto noise_level: noise_levels) {            auto data = generate_data(rank, num_points, noise_level);            auto coeffs_gmt = GMT_trend2d(data, rank);            \/\/ round coefficients to 8 decimal places            auto coeffs_rounded = coeffs_gmt.copy();            for (std::size_t i = 0; i &lt; coeffs_rounded.size(); ++i) {                coeffs_rounded.set(i, std::round(coeffs_rounded.get(i) * 1e8) \/ 1e8);            }            auto mse_gmt = calculate_mse(data, coeffs_rounded, rank);            \/\/ round MSE to zero decimal places            mse_gmt = std::round(mse_gmt);            results.emplace_back(rank, noise_level, mse_gmt);        }    }    \/\/ print table    std::cout &lt;&lt; \"Rank\\tNoise Level\\tGMT_trend2d, MSE\\n\";    for (const auto &amp;[rank, noise_level, mse]: results) {        std::cout &lt;&lt; rank &lt;&lt; \"\\t\" &lt;&lt; noise_level &lt;&lt; \"\\t\" &lt;&lt; mse &lt;&lt; \"\\n\";    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-2<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">Rank<\/p>\n<\/td>\n<td>\n<p align=\"left\">Noise Level<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\">C++ Time [ms]<\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">Python Time [ms]<\/p>\n<\/td>\n<td>\n<p align=\"left\">Speedup (C++ vs Py)<\/p>\n<\/td>\n<td>\n<p align=\"left\">Result<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>6.623<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">12.580<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.9x (+90%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>6.326<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">11.698<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.8x (+85%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1                                          <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>8.351<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">17.884<\/p>\n<\/td>\n<td>\n<p align=\"left\">2.1x (+114%)          <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>8.423<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">17.564<\/p>\n<\/td>\n<td>\n<p align=\"left\">2.1x (+109%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\"> 2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>11.848<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">24.378<\/p>\n<\/td>\n<td>\n<p align=\"left\">2.1x (+106%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">1 <\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>13.988<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">21.392<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x (+53%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>14.298<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">21.454<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x (+50%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>13.892<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">21.267<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x (+53%) <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                      <\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>22.118<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">27.332<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.2x (+24%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                      <\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>21.651<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">26.097<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.2x (+21%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>22.267<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">25.905<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.2x (+16%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>24.563<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">33.731<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.4x (+37%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-512<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">Rank<\/p>\n<\/td>\n<td>\n<p align=\"left\">Noise Level<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\">C++ Time [ms]<\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">Python Time [ms]<\/p>\n<\/td>\n<td>\n<p align=\"left\">Speedup (C++ vs Py)<\/p>\n<\/td>\n<td>\n<p align=\"left\">Result<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>10.465<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">14.564<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.4x (+39%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1<\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>8.728<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">13.618<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.6x (+56%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1                                          <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>11.995<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">20.686<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.7x (+72%)          <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">1                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>12.432<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">19.809<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.6x (+59%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\"> 2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>13.804<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">16.047<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.2x (+16%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">1 <\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>16.994<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">26.332<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x (+55%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>16.816<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">25.047<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.5x (+49%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">2                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>15.862<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">25.106<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.6x (+58%) <\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                      <\/p>\n<\/td>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>22.385<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">29.881<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.3x (+33%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                      <\/p>\n<\/td>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>21.063<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">29.933<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.4x (+42%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                     <\/p>\n<\/td>\n<td>\n<p align=\"left\">10<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>21.285<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">30.517<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.4x (+43%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">3                                                    <\/p>\n<\/td>\n<td>\n<p align=\"left\">50<\/p>\n<\/td>\n<td data-colwidth=\"185\" width=\"185\">\n<p align=\"left\"><strong>25.981<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"111\" width=\"111\">\n<p align=\"left\">36.520<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.4x (+41%)<\/p>\n<\/td>\n<td>\n<p align=\"left\">C++ FASTER<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 1.5 \u0440\u0430\u0437\u0430. \u0427\u0442\u043e \u043d\u0430\u0441 \u0436\u0434\u0435\u0442 \u0434\u0430\u043b\u044c\u0448\u0435? \u0412 \u043f\u043b\u0430\u043d\u0430\u0445 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u0442\u0435\u043c\u044b \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0434\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043e \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0441 API \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043d\u0430 Python. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438, \u0441\u043a\u0430\u0436\u0435\u043c, \u0430\u043d\u0430\u043b\u043e\u0433 PyTorch \u0438\u043b\u0438 Tensorflow.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0430\u0439\u0431\u043a\u043e\u0434\u0438\u043d\u0433\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u0442\u0438\u043d\u0435 \u0431\u0435\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c\u0438.<\/p>\n<h2>\u0412\u043e\u043f\u0440\u043e\u0441\u044b<\/h2>\n<ul>\n<li>\n<p>\u042f \u0441 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043d\u0438\u0435\u043c \u0436\u0434\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043e\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u044d\u0442\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u043b\u0438 \u043e\u043d\u0430 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0443\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0448\u0438\u0440\u043e\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445?<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u0442\u044c \u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c\u0443 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e \u044d\u0442\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u043c\u0443-\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 Jupyter \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430? \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u0430 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043e\u043a\u043e\u043b\u043e 2 \u041c\u0431. \u041d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f!<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u043e\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 numpy, pandas, scipy, sklearn, \u0438\u043b\u0438 \u0441\u0442\u043e\u0438\u0442 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044f\u0445?<\/p>\n<\/li>\n<li>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043f\u043e\u043c\u043e\u0447\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u0445 AMX. \u0423 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0442\u0430\u043a\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c, \u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u043c\u0430\u0448\u0438\u043d\u044b \u0441 CPU 4-\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f Intel Xeon Scalable (Sapphire Rapids), 5-\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f Intel Xeon Scalable (Emerald Rapids) \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 Intel Xeon 6 (Granite Rapids \/ Sierra Forest).<\/p>\n<\/li>\n<li>\n<p>\u0418\u0449\u0435\u043c \u043f\u043e\u043c\u043e\u0449\u044c \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0431\u043e\u0440\u043a\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u043e\u0434 Windows. \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u0441 \u044d\u0442\u043e\u0439 \u041e\u0421, \u043d\u043e \u044f \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u0435\u0433\u043e, \u0438, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0441\u0431\u043e\u0440\u043a\u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u0432\u043d\u0435\u0441\u0442\u0438 \u0441\u0432\u043e\u0439 \u0432\u043a\u043b\u0430\u0434, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0430\u0448\u0435\u043c\u0443 \u043e\u0442\u043a\u043b\u0438\u043a\u0443! \u041f\u0438\u0448\u0438\u0442\u0435 \u043c\u043d\u0435 \u0432 \u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/p>\n<\/li>\n<\/ul>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<ul>\n<li>\n<p>\u26a1 NumPy-style arrays in C++ | CUDA GPU + SIMD (AVX2\/AVX512\/AMX) CPU:\u00a0<a href=\"https:\/\/github.com\/mgorshkov\/np\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/np<\/a><\/p>\n<\/li>\n<li>\n<p>\u26a1 Data manipulation and analysis library in C++ | CUDA GPU + SIMD (AVX2\/AVX512\/AMX) CPU:\u00a0<a href=\"https:\/\/github.com\/mgorshkov\/pd\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/pd<\/a><\/p>\n<\/li>\n<li>\n<p>\u26a1 SciPy methods in C++ | CUDA GPU + SIMD (AVX2\/AVX512\/AMX) CPU:\u00a0<a href=\"https:\/\/github.com\/mgorshkov\/scipy\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/scipy<\/a><\/p>\n<\/li>\n<li>\n<p>\u26a1 ML methods in C++ | CUDA GPU + SIMD (AVX2\/AVX512\/AMX) CPU:\u00a0<a href=\"https:\/\/github.com\/mgorshkov\/sklearn\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/mgorshkov\/sklearn<\/a><\/p>\n<\/li>\n<\/ul>\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\/articles\/1039866\/\">https:\/\/habr.com\/ru\/articles\/1039866\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u00ab\u0418\u043c\u043f\u043e\u0440\u0442\u043e\u0437\u0430\u043c\u0435\u0449\u0430\u0435\u043c numpy, pandas, scipy \u0438 sklearn\u00bb \u043f\u0440\u043e\u0448\u043b\u043e \u043f\u043e\u0447\u0442\u0438 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430. \u0412 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c \u0438\u0437-\u0437\u0430 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u0441\u0438\u043b. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043c\u0435\u043d\u044f \u0440\u0430\u0441\u0441\u0442\u0440\u043e\u0438\u043b\u043e, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u044c\u0431\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f @N-Cube, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0441\u044f \u043c\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0438 \u0445\u043e\u0442\u0435\u043b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0432\u043e\u0435\u0433\u043e Jupyter Notebook.\u0412 \u0441\u0430\u043c\u044b\u0439 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0448\u0435\u043b \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 AI, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0445\u043e\u0442\u044c \u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u043b \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u0441 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u043b \u0432\u0441\u0435 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0445\u043e\u0437\u044f\u0438\u043d\u0430. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u0447\u0430\u043b \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434.\u0417\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 CUDA, \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0443\u0447\u043d\u044b\u0445 SIMD-\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c SIMD, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430.\u042f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0434\u0432\u0443\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445: \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c AVX-2 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435 Intel\u00ae Core\u2122 i7-4790K \u0438 AVX-512 \u043d\u0430 Intel\u00ae Xeon. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GPU, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c Python \u0438 \u043c\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u0440\u0430\u0432\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u2013 Ubuntu 24.04, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u2013 GNU 13.3.0.\u041c\u0435\u0442\u043e\u0434 \u041c\u043e\u043d\u0442\u0435-\u041a\u0430\u0440\u043b\u043e \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u03c0\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442: \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u0432\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442: rx \u0438 ry, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1. \u042d\u0442\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438.\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f: \u0422\u043e\u0447\u043a\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u0439\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u0440\u0443\u0433\u0430, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 dist \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 (0, 0) \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0434\u0438\u0443\u0441\u0430, \u0440\u0430\u0432\u043d\u043e\u0433\u043e 1. \u042d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b: rx\u00b2 + ry\u00b2 &lt; 1.\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435: \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 \u03c0 (pi_est) \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0442\u043e\u0447\u0435\u043a, \u043f\u043e\u043f\u0430\u0432\u0448\u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u0440\u0443\u0433\u0430, \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: https:\/\/github.com\/mgorshkov\/np\/blob\/main\/samples\/monte-carlo\/compare_python_monte_carlo.py\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0439 \u043a\u043e\u0434rx = np.random.rand(size)ry = np.random.rand(size)dist = rx * rx + ry * ryinside = np.sum(dist &lt; 1.0)pi_est = 4.0 * inside \/ size\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438auto rx = random::rand(size);auto ry = random::rand(size);auto dist = rx * rx + ry * ry;auto inside = sum(&#171;dist&lt;1&#8243;, dist);double pi_est = 4 * static_cast&lt;double&gt;(inside) \/ size;\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-2SizePy time (us) Py mem (MiB)  C++ time (us)C++ mem (MiB)SpeedupMem ratio10000042222.36381.56.62&#215;1.5&#215;10000001976022.9338615.35.84&#215;1.5&#215;10000000181804228.929889152.66.08&#215;1.5&#215;10000000017706012288.83138031525.95.64&#215;1.5x\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-512SizePy time (us) Py mem (MiB)  C++ time (us)C++ mem (MiB)SpeedupMem ratio10000075382.323711.53.18&#215;1.5&#215;10000003001122.9378215.37.94&#215;1.5&#215;10000000235035228.923761152.69.89&#215;1.5&#215;10000000061920492288.82855861525.921.68&#215;1.5x\u041d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f?\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0435\u043f\u043e\u043b\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u0443\u044e. \u041f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f $\\(B(a, b)\\)$ \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b \u043e\u0442 \u043d\u0443\u043b\u044f \u0434\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 $\\(a\\)$ \u0438 $\\(b\\)$:$$\\(B(a, b) = \\int_{0}^{1} t^{a-1} (1-t)^{b-1} \\, dt\\)$$\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f?\u0412 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0439 \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0435\u043b \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u0430 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e $\\(x\\)$ (\u0433\u0434\u0435 $\\(0 \\le x \\le 1\\))$. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u043e\u0442 $\\(0\\)$ \u0434\u043e $\\(x\\)$.\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u043d\u0430 \u043a\u0430\u043a $\\(B_x(a, b)\\)$ \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:$$\\(B_x(a, b) = \\int_{0}^{x} t^{a-1} (1-t)^{b-1} \\, dt\\)$$\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: https:\/\/github.com\/mgorshkov\/scipy\/tree\/main\/benchmarks\/betainc\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python#!\/usr\/bin\/env python3&#8243;&#187;&#187;Python scipy betainc benchmark &#8212; called by the C++ comparison benchmark.Uses the same test parameters as the C++ benchmark for fair comparison.&#187;&#187;&#187;import timeimport sysimport scipy.specialdef benchmark_python_scipy():    a = 0.5 * 99997    b = 0.5 * 99997    x = 0.4    count = 0    res = 0.0    start = time.perf_counter_ns()    while x &lt; 0.6:        count += 1        res += scipy.special.betainc(a, b, x)        x += 0.000001    stop = time.perf_counter_ns()    diff = stop &#8212; start    print(f&#187;Result = {res}&#187;)    print(f&#187;Time = {diff} ns&#187;)    print(f&#187;Loops = {count}&#187;)if __name__ == &#171;__main__&#187;:    benchmark_python_scipy()\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438timespec start;clock_gettime(CLOCK_MONOTONIC, &amp;start);np::float_ a = 0.5 * 99997;np::float_ b = 0.5 * 99997;np::float_ x = 0.4;int count = 0;np::float_ res = 0;while (x &lt; 0.6) {    ++count;    res += scipy::special::betainc(a, b, x);    x += 0.000001;}timespec stop;clock_gettime(CLOCK_MONOTONIC, &amp;stop);std::uint64_t diff = 1000000000L * (stop.tv_sec &#8212; start.tv_sec) + stop.tv_nsec &#8212; start.tv_nsec;std::cout &lt;&lt; &#171;Result = &#187; &lt;&lt; res &lt;&lt; std::endl;std::cout &lt;&lt; &#171;Time = &#187; &lt;&lt; diff &lt;&lt; &#187; ns&#187; &lt;&lt; std::endl;std::cout &lt;&lt; &#171;Loops = &#187; &lt;&lt; count &lt;&lt; std::endl;\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-2ImplementationTime (ns)LoopsSpeedup vs PythonC++ scipy (AVX2)1158821102000002.26xPython scipy2623078212000001.00x\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 AVX-512ImplementationTime (ns)LoopsSpeedup vs PythonC++ scipy (AVX512)1134401912000002.75xPython scipy3117876992000001.00x\u0411\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e Jupyter Notebook (\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b &#8212; \u043d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0442\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f)\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Python \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: https:\/\/habr.com\/ru\/articles\/752762\/#comment_25829022\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a: https:\/\/github.com\/mgorshkov\/sklearn\/blob\/main\/samples\/gmt_trend_2d\/benchmark.cpp\u041a\u043e\u0434 \u043d\u0430 Python\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442from tabulate import tabulateimport numpy as npdef generate_data(rank, num_points, noise_level):    np.random.seed(42)    x = np.linspace(-10, 10, num_points)    y = np.linspace(-10, 10, num_points)    if rank == 1:        z = 3 * x + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    elif rank == 2:        z = 2 * x + 3 * y + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    elif rank == 3:        z = 2 * x**2 + 3 * y**2 + 5 + noise_level * np.random.randn(num_points)        data = np.column_stack((x, y, z))    return datadef GMT_trend2d(data, rank):    import numpy as np    from sklearn.linear_model import LinearRegression    # scale factor for normally distributed data is 1.4826    # https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.median_abs_deviation.html    MAD_NORMALIZE = 1.4826    # significance value    sig_threshold = 0.51    if rank not in [1,2,3]:        raise Exception(&#8216;Number of model parameters &#171;rank&#187; should be 1, 2, or 3&#8217;)    #see gmt_stat.c    def gmtstat_f_q (chisq1, nu1, chisq2, nu2):        import scipy.special as sc        if chisq1 == 0.0:            return 1        if chisq2 == 0.0:            return 0        return sc.betainc(0.5*nu2, 0.5*nu1, chisq2\/(chisq2+chisq1))    if rank in [2,3]:        x = data[:,0]        x = np.interp(x, (x.min(), x.max()), (-1, +1))    if rank == 3:        y = data[:,1]        y = np.interp(y, (y.min(), y.max()), (-1, +1))    z = data[:,2]    w = np.ones(z.shape)    if rank == 1:        xy = np.expand_dims(np.zeros(z.shape),1)    elif rank == 2:        xy = np.expand_dims(x,1)    elif rank == 3:        xy = np.stack([x,y]).transpose()    # create linear regression object    mlr = LinearRegression()    chisqs = []    coeffs = []    while True:        # fit linear regression        mlr.fit(xy, z, sample_weight=w)        r = np.abs(z &#8212; mlr.predict(xy))        chisq = np.sum((r**2*w))\/(z.size-3)        chisqs.append(chisq)        k = 1.5 * MAD_NORMALIZE * np.median(r)        w = np.where(r &lt;= k, 1, (2*k\/r) &#8212; (k * k\/(r**2)))        sig = 1 if len(chisqs)==1 else gmtstat_f_q(chisqs[-1], z.size-3, chisqs[-2], z.size-3)        # Go back to previous model only if previous chisq &lt; current chisq        if len(chisqs)==1 or chisqs[-2] &gt; chisqs[-1]:            coeffs = [mlr.intercept_, *mlr.coef_]        #print (&#8216;chisq&#8217;, chisq, &#8216;significant&#8217;, sig)        if sig &lt; sig_threshold:            break    # get the slope and intercept of the line best fit    return (coeffs[:rank])def calculate_mse(data, coeffs, rank):    z_actual = data[:, 2]    if rank == 1:        z_predicted = coeffs[0]    elif rank == 2:        # Interpolate x the same way as in GMT_trend2d        x = data[:, 0]        x_interp = np.interp(x, (x.min(), x.max()), (-1, +1))        z_predicted = coeffs[0] + coeffs[1] * x_interp    elif rank == 3:        # Interpolate x and y the same way as in GMT_trend2d        x = data[:, 0]        x_interp = np.interp(x, (x.min(), x.max()), (-1, +1))        y = data[:, 1]        y_interp = np.interp(y, (y.min(), y.max()), (-1, +1))        z_predicted = coeffs[0] + coeffs[1] * x_interp + coeffs[2] * y_interp    mse = np.mean((z_actual &#8212; z_predicted) ** 2)    return msedef test_mse(num_points = 100*1000, ranks = [1, 2, 3], noise_levels = [0, 1, 10, 50]):    import warnings    results = []    # Suppress the specific warning    with warnings.catch_warnings():        warnings.simplefilter(&#171;ignore&#187;, category=RuntimeWarning)        for rank in ranks:            for noise_level in noise_levels:                data = generate_data(rank, num_points, noise_level)                # round the output                coeffs_gmt = [v.round(8) for v in GMT_trend2d(data, rank)]                mse_gmt = np.round(calculate_mse(data, coeffs_gmt, rank), 0)                results.append([rank, noise_level, mse_gmt])    headers = [&#171;Rank&#187;, &#171;Noise Level&#187;, &#171;GMT_trend2d, MSE&#187;]    print(tabulate(results, headers=headers))test_mse()\u041a\u043e\u0434 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442using namespace np;using namespace scipy;using namespace sklearn;auto generate_data(auto rank, auto num_points, auto noise_level) {    random::seed(42);    auto x = linspace(-10.0, 10.0, num_points);    auto y = linspace(-10.0, 10.0, num_points);    if (rank == 1) {        auto z = 3 * x + 5 + noise_level * random::randn(num_points);        return column_stack(x, y, z);    }    if (rank == 2) {        auto z = 2 * x + 3 * y + 5 +&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-481162","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/481162","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=481162"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/481162\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=481162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=481162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=481162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}