{"id":378448,"date":"2024-06-09T15:16:21","date_gmt":"2024-06-09T15:16:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=378448"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=378448","title":{"rendered":"<span>\u0423\u0447\u0438\u043c\u0441\u044f \u043b\u0435\u0442\u0430\u0442\u044c: \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u0438 \u043d\u0430 Rust. 2\/5<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ok\/13\/y9\/ok13y9vlz-qasq8lvjgusd0lpyk.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ok\/13\/y9\/ok13y9vlz-qasq8lvjgusd0lpyk.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/strong> \u0438 <strong>\u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/817585\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u043b\u043e\u0436\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e FFNN (feedforward neural network \u2014 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u043e\u0437\u0433\u043e\u043c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0434\u0438\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0435 Rust, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435\u0441\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b? \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"nastroyka\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">mkdir shorelark cd shorelark<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043d\u0430\u0431\u043e\u0440\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (toolchain) \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u2014 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043d\u0430 \u043c\u0430\u0440\u0442 2024 \u0433\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 Rust \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>1.76<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>rust-toolchain<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">1.76.0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u2014 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u0435\u0439 (\u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u0438 \u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c), \u043d\u0430\u043c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c (workspace):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># Cargo.toml [workspace] resolver = \"2\"  members = [     \"libs\/*\", ]<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e <code>src\/main.rs<\/code>, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>libs<\/code> \u0438 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0442\u0443\u0434\u0430 \u043d\u0430\u0448\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u043a\u0440\u0435\u0439\u0442\u044b):<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">mkdir libs cd libs cargo new neural-network --name lib-neural-network --lib<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>libs<\/code>, \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>crates<\/code>. \u0418\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0432\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438: \u043e\u0434\u043d\u0443 \u0434\u043b\u044f \u043a\u0440\u0435\u0439\u0442\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u0440\u0443\u0433\u0443\u044e \u2014 \u0434\u043b\u044f \u043a\u0440\u0435\u0439\u0442\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"plaintext\">project \u251c\u2500 Cargo.toml \u251c\u2500 app \u2502  \u251c\u2500 Cargo.toml \u2502  \u2514\u2500 src \u2502      \u2514\u2500 main.rs \u2514\u2500 libs    \u251c\u2500 subcrate-a    \u2502  \u251c\u2500 Cargo.toml    \u2502  \u2514\u2500 src    \u2502     \u2514\u2500 lib.rs    \u2514\u2500 subcrate-b       \u251c\u2500 Cargo.toml       \u2514\u2500 src          \u2514\u2500 lib.rs<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"razrabotka-propagate\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 <code>propagate()<\/code><\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0440\u0430 \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u0435\u043b\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0441\u0435\u0442\u044c \u2014 \u043e\u043d\u0430 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043d\u0430\u0448 \u043a\u0440\u0435\u0439\u0442. \u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c <code>lib.rs<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ libs\/neural-network\/src\/lib.rs #[derive(Debug)] pub struct Network;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u2014 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 (\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430) \u0447\u0438\u0441\u0435\u043b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/nj\/mn\/jd\/njmnjd6x3ff_rl4keit4saupdsa.png\" data-src=\"https:\/\/habrastorage.org\/webt\/nj\/mn\/jd\/njmnjd6x3ff_rl4keit4saupdsa.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct Network;  impl Network {     pub fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0443\u0441\u0442\u044b\u043c\u0438:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"plaintext\">int get_berry_number() {     \/\/ TODO \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u0434\u043e\u043a\u0441 }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 Rust \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn berry_number() -> usize {     \/\/ TODO \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u0434\u043e\u043a\u0441 }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">error[E0308]: mismatched types  --> src\/lib.rs   | 1 | fn berry_number() -> usize {   |    ------------      ^^^^^ expected `usize`, found `()`   |    |   |    implicitly returns `()` as its body has no tail or `return`   |    expression<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0432 Rust \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ \u044d\u0442\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 let value = if condition {     \"computer says yass\" } else {     \"computer says no\" };  \/\/ \u0438 \u044d\u0442\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 let value = loop {     break 123; };  let value = {     \/\/ \u043f\u0443\u0441\u0442\u043e\u0439 \u0431\u043b\u043e\u043a - \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 };<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Rust \u0432\u0438\u0434\u0438\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn berry_number() -> usize {     return (); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p><code>()<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/doc.rust-lang.org\/std\/primitive.unit.html\">\u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c<\/a> (unit value) (\u0438\u043b\u0438 <strong>\u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c<\/strong> (unit type), \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430).<\/p>\n<p>  Rust \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0432\u0430 \u043c\u0430\u043a\u0440\u043e\u0441\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u043a \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0443\u044e\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438: <code>todo!()<\/code> \u0438 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439 <code>unimplemented!()<\/code>.<\/p>\n<p>  \u041e\u0431\u0430 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438, \u0435\u0441\u043b\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c\u0443 \u0441\u0431\u043e\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"bash\">thread 'main' panicked at 'not yet implemented'<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u043e \u043e\u043a\u0435\u0430\u043d\u0443, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0438\u0437 \u043a\u0430\u043f\u0435\u043b\u044c, \u0441\u0435\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u043b\u043e\u0435\u0432:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/l_\/0g\/on\/l_0gonan6cycv72ivhdvljdqotw.png\" data-src=\"https:\/\/habrastorage.org\/webt\/l_\/0g\/on\/l_0gonan6cycv72ivhdvljdqotw.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct Network {     layers: Vec&lt;Layer>, }  #[derive(Debug)] struct Layer;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/th\/bt\/m4\/thbtm4dlc7i4qs9r3b0lyvbu8hu.png\" data-src=\"https:\/\/habrastorage.org\/webt\/th\/bt\/m4\/thbtm4dlc7i4qs9r3b0lyvbu8hu.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Layer {     neurons: Vec&lt;Neuron>, }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043d\u0435\u0439\u0440\u043e\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f (biases) \u0438 <strong>\u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 (output)<\/strong> \u0432\u0435\u0441\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/wq\/pl\/zh\/wqplzh50dhe8zahwmfqaigist7q.png\" data-src=\"https:\/\/habrastorage.org\/webt\/wq\/pl\/zh\/wqplzh50dhe8zahwmfqaigist7q.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Neuron {     bias: f32,     weights: Vec&lt;f32>, }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043d\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct Network {     layers: Vec&lt;Layer>, }  impl Network {     pub fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         todo!()     } }  #[derive(Debug)] struct Layer {     neurons: Vec&lt;Neuron>, }  #[derive(Debug)] struct Neuron {     bias: f32,     weights: Vec&lt;f32>, }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e.<\/p>\n<p>  <\/p>\n<blockquote><p>\u0412\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 (<code>pub<\/code>): <code>Network<\/code> \u0438 <code>Network:propagate()<\/code>.<\/p>\n<p>  \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e <code>Layer<\/code> \u0438 <code>Neuron<\/code> \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f <strong>\u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/strong>, \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438.<\/p>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u0435 \u043d\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u0440\u0435\u0439\u0442\u0430\u043c (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438).<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0442\u0440\u0438\u0446 \u2014 \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u044d\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c: \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 <code>Network:propagate()<\/code> \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0435\u0439, \u0430 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a <code>Layer<\/code> \u0438 <code>Neuron<\/code>, \u043e\u043d\u0438 \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u044f\u0442 \u0438\u0445 \u0438\u0441\u0447\u0435\u0437\u043d\u043e\u0432\u0435\u043d\u0438\u044f.<\/p><\/blockquote>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0447\u0438\u0441\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439, \u0432 \u043d\u0438\u0445 \u043d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <code>propagate()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u044f <code>Layer::propagate()<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <code>Network::propagate()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         let mut inputs = inputs;          for layer in &amp;self.layers {             inputs = layer.propagate(inputs);         }          inputs     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430, \u043d\u043e \u043e\u043d <strong>\u043d\u0435 \u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u043d<\/strong> \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u0431\u043e\u043b\u0435\u0435 <strong>rustic<\/strong>!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ln\/td\/su\/lntdsujttq-u0gcmpymbostdtho.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ln\/td\/su\/lntdsujttq-u0gcmpymbostdtho.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u044d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u043e\u0439 (\u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u043e\u0439, rebinding) (\u0438\u043b\u0438 \u0437\u0430\u0442\u0435\u043d\u0435\u043d\u0438\u0435\u043c (shadowing)):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">let mut inputs = inputs;<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 <code>mut<\/code> \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn propagate(&amp;self, mut inputs: Vec&lt;f32>) -> Vec&lt;f32> {         for layer in &amp;self.layers {             inputs = layer.propagate(inputs);         }          inputs     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041d\u043e \u043d\u0435 \u043e\u0431\u044f\u0436\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 (\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f? \u041d\u0435\u0430!<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn process(mut items: Vec&lt;f32>) {     \/\/ ... }  fn main() {     let items = vec![1.2, 3.4, 5.6];     \/\/ ^ `mut` \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d      process(items);     \/\/      ^ \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u0422\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 <code>mut<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 <strong>\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438<\/strong> (binding position):<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ \u0438\u043c\u043c\u0443\u0442. - \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439, \u043c\u0443\u0442. - \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 fn foo_1(items: &amp;[f32]) {     \/\/   ^^^^^  ------     \/\/  \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430  \u0442\u0438\u043f     \/\/  (\u0438\u043c\u043c\u0443\u0442.) (\u0438\u043c\u043c\u0443\u0442.) }  fn foo_2(mut items: &amp;[f32]) {     \/\/   ^^^^^^^^^  ------     \/\/    \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430   \u0442\u0438\u043f     \/\/     (\u043c\u0443\u0442.)  (\u0438\u043c\u043c\u0443\u0442.) }  fn foo_3(items: &amp;mut [f32]) {     \/\/   ^^^^^  ----------     \/\/  \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430   \u0442\u0438\u043f     \/\/  (\u0438\u043c\u043c\u0443\u0442.)  (\u043c\u0443\u0442.) }  fn foo_4(mut items: &amp;mut [f32]) {     \/\/   ^^^^^^^^^  ----------     \/\/    \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430    \u0442\u0438\u043f     \/\/     (\u043c\u0443\u0442.)    (\u043c\u0443\u0442.) }  struct Person {     name: String,     eyeball_radius: usize, }  fn decompose(Person { name, mut eyeball_radius }: Person) {     \/\/       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ------     \/\/                     \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430                \u0442\u0438\u043f     \/\/         (\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0438\u043c\u043c\u0443\u0442., \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043c\u0443\u0442.)  (\u0438\u043c\u043c\u0443\u0442.) }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0442\u0438\u043f\u043e\u0432, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn foo(items: &amp;mut Vec&lt;usize>) {     \/\/ \u041a\u043e\u0433\u0434\u0430 \u0442\u0438\u043f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e,     \/\/ \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430:     items.push(1234);      \/\/ \u041d\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439, \u043c\u044b \u041d\u0415 \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c     \/\/ \u0441\u0430\u043c\u0443 \u0441\u0441\u044b\u043b\u043a\u0443:     items = some_another_vector;     \/\/    ^ error: cannot assign to immutable argument }  fn bar(mut items: &amp;Vec&lt;usize>) {     \/\/ \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c     \/\/ \u0441\u0430\u043c\u0443 \u0441\u0441\u044b\u043b\u043a\u0443:     items = some_another_vector;      \/\/ \u041d\u043e \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e,     \/\/ \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430:     items.push(1234);     \/\/   ^^^^^ error: cannot borrow `*items` as mutable, as it is     \/\/         behind a `&amp;` reference }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0432\u0435\u0449\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u0434\u0443 \u2014 \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u0430\u043a <strong>\u0441\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 (folding)<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">for layer in &amp;self.layers {     inputs = layer.propagate(inputs); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Rust \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         self.layers             .iter()             .fold(inputs, |inputs, layer| layer.propagate(inputs))     } }<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041d\u0430 \u0432\u043a\u0443\u0441 \u0438 \u0446\u0432\u0435\u0442, \u043a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0442\u043e\u0432\u0430\u0440\u0438\u0449\u0430 \u043d\u0435\u0442.<\/em><\/p>\n<p>  <\/p>\n<p>\u0412\u0443\u0430\u043b\u044f \u2014 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044e \u043d\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d <code>mut inputs<\/code> \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 Haskell (\u0442.\u0435. \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e \u0434\u0443\u0445\u0443).<\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043d\u0435\u0439\u0440\u043e\u043d\u0430\u043c \u2014 \u043e\u0434\u0438\u043d \u043d\u0435\u0439\u0440\u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Neuron {     bias: f32,     weights: Vec&lt;f32>, }  impl Neuron {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> f32 {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Layer::propagate()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Layer {     neurons: Vec&lt;Neuron>, }  impl Layer {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         let mut outputs = Vec::new();          for neuron in &amp;self.neurons {             let output = neuron.propagate(inputs);             outputs.push(output);         }          outputs     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0431\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">error[E0382]: use of moved value: `inputs`   --> src\/lib.rs    |    |     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {    |                         ------ move occurs because `inputs` has    |                                type `Vec&lt;f32>`, which does not    |                                implement the `Copy` trait   ...    |             let output = neuron.propagate(inputs);    |                                           ^^^^^^    |                                value moved here, in previous    |                                iteration of loop<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0430\u0432: \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>neuron.propagate(inputs)<\/code> \u043c\u044b \u0442\u0435\u0440\u044f\u0435\u043c \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0434 <code>inputs<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0446\u0438\u043a\u043b\u0430.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b <code>neuron::propagate()<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 <strong>\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438<\/strong> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         \/* ... *\/          for neuron in &amp;self.neurons {             let output = neuron.propagate(&amp;inputs);             \/* ... *\/         }          \/* ... *\/     } }  \/* ... *\/  impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0448 \u043a\u043e\u0434 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         let mut outputs = Vec::new();          for neuron in &amp;self.neurons {             let output = neuron.propagate(&amp;inputs);             outputs.push(output);         }          outputs     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438, \u0432\u0435\u0440\u0438\u0442\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442, \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c (mapping)<\/strong>, \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434!<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn propagate(&amp;self, inputs: Vec&lt;f32>) -> Vec&lt;f32> {         self.neurons             .iter()             .map(|neuron| neuron.propagate(&amp;inputs))             .collect()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c <code>neuron::propagate()<\/code> \u2014 \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u044b\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         let mut output = 0.0;          for i in 0..inputs.len() {             output += inputs[i] * self.weights[i];         }          output += self.bias;          if output > 0.0 {             output         } else {             0.0         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0435 \u043d\u0435\u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u043e\u0434\u043d\u0443 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c <code>self.weights<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u0438\u043d\u0443 <code>inputs<\/code>, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u043a\u0440\u0430\u0439\u043d\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041a\u043e\u0433\u0434\u0430 <code>inputs.len() &lt; self.weights.len()<\/code>.<\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 <code>inputs.len() == self.weights.len()<\/code>.<\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 <code>inputs.len() > self.weights.len()<\/code>.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 \u043a\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0447\u0442\u043e \u043f\u0443\u043d\u043a\u0442 2 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u0435\u0440\u0435\u043d, \u043d\u043e \u044d\u0442\u043e <strong>\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/strong>: \u043c\u044b \u043d\u0438\u0433\u0434\u0435 \u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c! \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043b\u0438\u0431\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043b\u0438\u0431\u043e \u0441\u0431\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c <code>Neuron::propagate()<\/code> \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> Result&lt;f32, String> {         if inputs.len() != self.weights.len() {             return Err(format!(                 \"\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e {} \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c {}\",                 inputs.len(),                 self.weights.len(),             ));         }          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043c\u043e\u0438\u0445 \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u043a\u0440\u0435\u0439\u0442\u043e\u0432 \u2014 <a href=\"https:\/\/github.com\/dtolnay\/thiserror\">thiserror<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub type Result&lt;T> = std::result::Result&lt;T, Error>;  #[derive(Debug, Error)] pub enum Error {     #[error(\"\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e {got} \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c {expected}\")]     MismatchedInputSize {         got: usize,         expected: usize,     }, }  \/* ... *\/  impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> Result&lt;f32> {         if inputs.len() != self.weights.len() {             return Err(Error::MismatchedInputSize {                 got: inputs.len(),                 expected: self.weights.len(),             });         }          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<ol>\n<li>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>assert_eq!()<\/code> \/ <code>panic!()<\/code>:<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         assert_eq!(inputs.len(), self.weights.len());          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043b\u0443\u0447\u0448\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 <strong>\u043f\u043e\u0439\u043c\u0430\u0442\u044c<\/strong> \u043e\u0448\u0438\u0431\u043a\u0443 \u0438 \u043b\u0435\u0433\u043a\u043e \u0435\u0435 <strong>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c<\/strong>. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0433\u0440\u0430 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u0432\u0435\u0447, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0415\u0441\u043b\u0438 <code>assert_eq()<\/code> \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043d\u0435\u0432\u0435\u0440\u043d\u0430, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/li>\n<li>\u042d\u0442\u043e \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u2014 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0440\u044f \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         assert_eq!(inputs.len(), self.weights.len());          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0438\u0434\u0438\u043e\u043c, \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/          if output > 0.0 {             output         } else {             0.0         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043a\u0440\u044b\u0442\u044b\u043c <code>f32::max()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/          output.max(0.0)     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/          let mut output = 0.0;          for i in 0..inputs.len() {             output += inputs[i] * self.weights[i];         }          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>.zip()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/          let mut output = 0.0;          for (&amp;input, &amp;weight) in inputs.iter().zip(&amp;self.weights) {             output += input * weight;         }          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>inputs[i]<\/code>, \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e <strong>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0433\u0440\u0430\u043d\u0438\u0446 (bounds check)<\/strong> \u2014 \u044d\u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0438 \u043f\u0430\u043d\u0438\u043a\u0443\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     let numbers = vec![1];     println!(\"{}\", numbers[123]); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 123'<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041a\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>.zip()<\/code> \u0438\u043b\u0438 <code>.map()<\/code>, \u043c\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u0448 \u043a\u043e\u0434 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c (\u043d\u0430 \u0432\u043a\u0443\u0441 \u0438 \u0446\u0432\u0435\u0442&#8230;), \u043d\u043e \u0438 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u043c.<\/p><\/blockquote>\n<p>\u2026 \u0437\u0430\u0442\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>.map()<\/code> \u0438 <code>.sum()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         \/* ... *\/          let mut output = inputs             .iter()             .zip(&amp;self.weights)             .map(|(input, weight)| input * weight)             .sum::&lt;f32>();          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 <code>::&lt;><\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/techblog.tonsser.com\/posts\/what-is-rusts-turbofish\">\u0442\u0443\u0440\u0431\u043e\u0440\u044b\u0431\u043e\u0439 (turbofish)<\/a>. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u044f\u0432\u043d\u044b\u0435 \u043e\u0431\u0449\u0438\u0435 (generic) \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u043e\u043c.<\/p><\/blockquote>\n<p>\u0412\u0443\u0430\u043b\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn propagate(&amp;self, inputs: &amp;[f32]) -> f32 {         assert_eq!(inputs.len(), self.weights.len());          let output = inputs             .iter()             .zip(&amp;self.weights)             .map(|(input, weight)| input * weight)             .sum::&lt;f32>();          (self.bias + output).max(0.0)     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e, \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u043e, \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043d\u043e <strong>\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e<\/strong>? \u041c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0442\u044c \u043a\u043e\u0448\u043a\u0443 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438? \u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0446\u0435\u043d Dogecoin?<\/p>\n<p>  <\/p>\n<h2 id=\"razrabotka-new\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 <code>new()<\/code><\/h2>\n<p>  <\/p>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043c\u044b \u0431\u044b\u043b\u0438 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u043d\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435, \u0447\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0434\u0443\u043c\u0430\u043b\u0438 \u043e <strong>\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445<\/strong>, \u043d\u043e \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct Network {     layers: Vec&lt;Layer>, }  impl Network {     pub fn new(layers: Vec&lt;Layer>) -> Self {         Self { layers }     }      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0445\u043e\u0442\u0438\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c <code>Layer<\/code> \u0438 <code>Neuron<\/code> \u0432\u043d\u0435 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random() -> Self {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0442\u044c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0435 \u0441\u043b\u043e\u0435\u0432 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0439\u0440\u043e\u043d\u043e\u0432 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u043e\u0435 \u2014 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(neurons_per_layer: Vec&lt;usize>) -> Self {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct LayerTopology {     pub neurons: usize, }  impl Network {     pub fn random(layers: Vec&lt;LayerTopology>) -> Self {         todo!()     }      \/* ... *\/ }  \/\/ \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 `layers`. \/\/ \/\/ \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f `neurons_per_layer`, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 `Vec&lt;usize>` \/\/ \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u044d\u0442\u043e\u0442 `usize`. \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c.<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u043b\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/v4\/zp\/b2\/v4zpb2hepswfi37dstvdjozl5xk.png\" data-src=\"https:\/\/habrastorage.org\/webt\/v4\/zp\/b2\/v4zpb2hepswfi37dstvdjozl5xk.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u2026 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0447\u0438\u0441\u043b\u0430\u043c\u0438: \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043b\u0438 \u044d\u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>LayerTopology<\/code> \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u043b\u0435\u043c \u043d\u0435\u0432\u0435\u0440\u043d\u0430? \u041d\u0430\u043e\u0431\u043e\u0440\u043e\u0442!<\/p>\n<p>  <\/p>\n<p>\u041c\u044b <strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u0432 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0412 FFNN \u0432\u0441\u0435 \u0441\u043b\u043e\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/nr\/_h\/wn\/nr_hwnbb4jaay6g8rhfmuyksnuo.png\" data-src=\"https:\/\/habrastorage.org\/webt\/nr\/_h\/wn\/nr_hwnbb4jaay6g8rhfmuyksnuo.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u044f A \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u044f B, \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] pub struct LayerTopology {     pub input_neurons: usize,     pub output_neurons: usize, }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0430\u0448 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u043c, \u043d\u043e, \u0447\u0442\u043e \u0435\u0449\u0435 \u0445\u0443\u0436\u0435, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0430\u044f, \u0447\u0442\u043e \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044e\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f <code>layer[0].output_neurons == layer[1].input_neurons<\/code> \u0438 \u0442.\u0434. \u2014 \u043f\u043e\u043b\u043d\u0430\u044f \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0438\u0446\u0430!<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u0432\u0445\u043e\u0434\u044b \u0438 \u0432\u044b\u0445\u043e\u0434\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0435\u0449\u0435 \u0434\u043e \u0435\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(layers: Vec&lt;LayerTopology>) -> Self {         let mut built_layers = Vec::new();          for i in 0..(layers.len() - 1) {             let input_size = layers[i].neurons;             let output_size = layers[i + 1].neurons;              built_layers.push(Layer::random(                 input_size,                 output_size,             ));         }          Self { layers: built_layers }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0435 &#171;\u0440\u0430\u0441\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c&#187; \u2014 \u0443\u0433\u0430\u0434\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u044b\u0437\u043e\u0432\u0435\u043c <code>Network::random(vec![])<\/code>?<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(layers: Vec&lt;LayerTopology>) -> Self {         \/\/ \u0421\u0435\u0442\u044c \u0441 \u043e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0435\u043c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430, \u043d\u043e \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0430:         assert!(layers.len() > 1);          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b\u0430 <code>for<\/code>, \u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u2014 \u044d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0448\u0430\u0431\u043b\u043e\u043d, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>windows()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(layers: Vec&lt;LayerTopology>) -> Self {         \/* ... *\/          for adjacent_layers in layers.windows(2) {             let input_size = adjacent_layers[0].neurons;             let output_size = adjacent_layers[1].neurons;              \/* ... *\/         }          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043e <a href=\"https:\/\/doc.rust-lang.org\/book\/ch18-03-pattern-syntax.html#destructuring-to-break-apart-values\">\u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a>, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">for [fst, snd] in layers.windows(2) {     built_layers.push(Layer::random(fst.neurons, snd.neurons)); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 &#171;\u041d\u0435\u0442&#187;:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">error[E0005]: refutable pattern in `for` loop binding: `&amp;[]`,               `&amp;[_]` and `&amp;[_, _, _, ..]` not covered  --> src\/lib.rs   |   |     for [fst, snd] in layers.windows(2) {   |         ^^^^^^^^^^ patterns `&amp;[]`, `&amp;[_]` and `&amp;[_, _, _, ..]`   |                    not covered   |   = note: the matched value is of type `&amp;[LayerTopology]`<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e <code>windows(2)<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0440\u043e\u0432\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0435\u043c\u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043b\u0438\u0448\u044c, \u0447\u0442\u043e <code>windows()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 (\u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043e\u043f\u0440\u043e\u0432\u0435\u0440\u0436\u0438\u043c\u044b\u043c (refutable)<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u043b\u0443\u0447\u0430\u044f\u043c\u0438; \u0442\u0440\u044e\u043a \u0441 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>\u043d\u0435\u043e\u043f\u0440\u043e\u0432\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e (irrefutable)<\/strong> \u0448\u0430\u0431\u043b\u043e\u043d\u0430).<\/p>\n<p>  \u041d\u043e\u0447\u043d\u043e\u0439 Rust, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 <strong>\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 (const generics)<\/strong> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 <code>.array_windows()<\/code>:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">#![feature(array_windows)]  for [fst, snd] in layers.array_windows() {     built_layers.push(Layer::random(fst.neurons, snd.neurons)); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p><\/blockquote>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(layers: Vec&lt;LayerTopology>) -> Self {         let layers = layers             .windows(2)             .map(|layers| Layer::random(layers[0].neurons, layers[1].neurons))             .collect();          Self { layers }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445: \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u043c, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c <strong>\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u0435<\/strong> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Network {     pub fn random(layers: &amp;[LayerTopology]) -> Self {         \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u0435 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u2014 \u0441 \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">let network = Network::random(&amp;[     LayerTopology { neurons: 8 },     LayerTopology { neurons: 15 },     LayerTopology { neurons: 2 }, ]);<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">let layers = vec![     LayerTopology { neurons: 8 },     LayerTopology { neurons: 15 },     LayerTopology { neurons: 2 }, ];  let network_a = Network::random(&amp;layers); let network_b = Network::random(&amp;layers); \/\/                              ^ \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 `.clone()`<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435, \u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435\u2026 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0437\u0430\u043c\u0435\u0442\u043a\u0438\u2026 \u0430, <code>Layer::random()<\/code>!<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn random(input_size: usize, output_size: usize) -> Self {         let mut neurons = Vec::new();          for _ in 0..output_size {             neurons.push(Neuron::random(input_size));         }          Self { neurons }     }      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Layer {     fn random(input_size: usize, output_size: usize) -> Self {         let neurons = (0..output_size)             .map(|_| Neuron::random(input_size))             .collect();          Self { neurons }     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p><code>|_|<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>toilet closure (\u0433\u0430\u0440\u0434\u0435\u0440\u043e\u0431\u043d\u044b\u043c \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435\u043c?)<\/strong> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0439 \u043d\u0435 \u0432\u0430\u0436\u0435\u043d\/\u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">.map(|output_neuron_id| Neuron::random(input))<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 <code>output_neuron_id<\/code>, \u0431\u043e\u043b\u0435\u0435 \u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>_<\/code> (\u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b <code>_output_neuron_id<\/code>) \u0434\u043b\u044f \u0438\u043d\u0434\u0438\u043a\u0430\u0446\u0438\u0438 \u0444\u0430\u043a\u0442\u0430 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0421\u0430\u043c <code>_<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u0435\u043c (placeholder) \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ \u041a\u0430\u043a \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430: fn ignore_some_arguments(_: usize, b: usize, _: usize) {     \/\/                   ^                   ^ }  \/\/ ...\u043d\u043e \u043d\u0435 \u043a\u0430\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435: fn _() { \/\/ ^ error: expected identifier, found reserved identifier `_` }  \/\/ \u041a\u0430\u043a \u0442\u0438\u043f: fn load_files(paths: &amp;[&amp;Path]) -> Vec&lt;String> {     paths         .iter()         .map(std::fs::read_to_string)         .collect::&lt;Result&lt;_, _>>()     \/\/                    ^  ^         .unwrap() }  \/\/ ...\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439: fn what_am_i(foo: _) {     \/\/            ^ error: the type placeholder `_` is not allowed     \/\/              within types on item signatures }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043d\u0430\u0448\u0435\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u2014 <code>Neuron::random()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn random(input_size: usize) -> Self {         let bias = todo!();          let weights = (0..input_size)             .map(|_| todo!())             .collect();          Self { bias, weights }     }      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 C++ \u0438\u043b\u0438 Python, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Rust \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (\u0434\u0430\u043b\u0435\u0435 \u0442\u0430\u043a\u0436\u0435 \u2014 \u0413\u041f\u0421\u0427). \u0427\u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442? \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f <a href=\"https:\/\/crates.io\/\">crates.io<\/a>!<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u043e \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0413\u041f\u0421\u0427, <a href=\"https:\/\/crates.io\/crates\/rand\">rand<\/a> \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c. \u042d\u0442\u043e <a href=\"https:\/\/rust-lang-nursery.github.io\/rust-cookbook\/algorithms\/randomness.html\">\u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439<\/a> \u043a\u0440\u0435\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0438\u043f\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 <code>Cargo.toml<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># ...  [dependencies] rand = \"0.8\"<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438 \u0437\u0430\u0442\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use rand::Rng;  \/* ... *\/  impl Neuron {     fn random(input_size: usize) -> Self {         let mut rng = rand::thread_rng();         let bias = rng.gen_range(-1.0..=1.0);          let weights = (0..input_size)             .map(|_| rng.gen_range(-1.0..=1.0))             .collect();          Self { bias, weights }     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p><code>0..3<\/code> \u2014 \u044d\u0442\u043e <strong>\u043f\u043e\u043b\u0443\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 <code>0<\/code>, <code>1<\/code> \u0438 <code>2<\/code>.<br \/>  <code>0..=3<\/code> \u2014 \u044d\u0442\u043e <strong>\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 <code>3<\/code>.<\/p><\/blockquote>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, <code>rng.gen_range(-1.0..=1.0)<\/code> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0446\u0435\u043d\u044b Dogecoin, \u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0441\u0435\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f?<\/p>\n<p>  <\/p>\n<h2 id=\"testirovanie\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Pure_function\">\u0427\u0438\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/a> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438 \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u0447\u0438\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub fn add(x: usize, y: usize) -> usize {     x + y }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0430 \u044d\u0442\u043e \u043d\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub fn read(path: impl AsRef&lt;Path>) -> String {     std::fs::read_to_string(path).unwrap() }<\/code><\/pre>\n<p>  <\/p>\n<p><em><code>add(1, 2)<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>3<\/code>, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <code>read(\"file.txt\")<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0444\u0430\u0439\u043b <code>file.txt<\/code> \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.<\/em><\/p>\n<p>  <\/p>\n<p>\u0427\u0438\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ \u042d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \/\/ (\u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f *\u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c*) #[test] fn test_add() {     assert_eq!(add(1, 2), 3); }  \/\/ \u042d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438, \u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u044c\u0441\u044f, \u043f\u0440\u0435\u0434\u0443\u0433\u0430\u0434\u0430\u0442\u044c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \/\/ (\u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f *\u043d\u0435\u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c*) #[test] fn test_read() {     assert_eq!(         std::fs::read_to_string(\"serials-to-watch.txt\"),         \"killing eve\",     ); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0432 <code>Neuron::random()<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0435\u0447\u0438\u0441\u0442\u043e\u0439, \u0447\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn random_is_pure() {     let neuron_a = Neuron::random(4);     let neuron_b = Neuron::random(4);      \/\/ \u0415\u0441\u043b\u0438 \u0431\u044b `Neuron::random()` \u0431\u044b\u043b\u0430 \u0447\u0438\u0441\u0442\u043e\u0439, \u043e\u0431\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u0438 \u0431\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438:     assert_eq!(neuron_a, neuron_b); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0447\u0438\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c <strong>\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u043e<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/* ... *\/  #[cfg(test)] mod tests {     use super::*;      #[test]     fn random() {         let neuron = Neuron::random(4);          assert!(\/* \u0447\u0442\u043e? *\/);     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test() {     let neuron = Neuron::random(4);      assert_eq!(neuron.weights.len(), 4); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043d\u043e \u044d\u0442\u043e \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>Neuron::random()<\/code> \u0432 \u0447\u0438\u0441\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u0436\u0435\u0442\u0441\u044f\u2026 \u043d\u0435\u043b\u0435\u043f\u044b\u043c? \u041a\u0430\u043a\u043e\u0439 \u0441\u043c\u044b\u0441\u043b \u0432 \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c?<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u044f \u043f\u0440\u0438\u043c\u0438\u0440\u044f\u044e \u043e\u0431\u0430 \u043c\u0438\u0440\u0430, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0435\u0447\u0438\u0441\u0442\u043e\u0442\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Neuron {     fn random(input_size: usize) -> Self {         let mut rng = rand::thread_rng(); \/\/ \u0443\u043f\u0441          \/* ... *\/     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>thread_rng()<\/code>, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0441 \u0440\u0430\u043d\u0434\u043e\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c?<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use rand::{Rng, RngCore};  \/* ... *\/  impl Network {     pub fn random(rng: &amp;mut dyn RngCore, layers: &amp;[LayerTopology]) -> Self {         let layers = layers             .windows(2)             .map(|layers| Layer::random(rng, layers[0].neurons, layers[1].neurons))             .collect();          \/* ... *\/     }      \/* ... *\/ }  \/* ... *\/  impl Layer {     fn random(rng: &amp;mut dyn RngCore, input_size: usize, output_size: usize) -> Self {         let neurons = (0..output_size)             .map(|_| Neuron::random(rng, input_size))             .collect();          \/* ... *\/     }      \/* ... *\/ }  \/* ... *\/  impl Neuron {     fn random(rng: &amp;mut dyn RngCore, input_size: usize) -> Self {         \/* ... *\/     }      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0438\u0445 \u0442\u0435\u0441\u0442\u0430\u0445 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u044b\u0439, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439 \u0413\u041f\u0421\u0427, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0413\u041f\u0421\u0427 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443.<\/p>\n<p>  <\/p>\n<blockquote><p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn do_something() {     println!(\"\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c...\");     println!(\"...\u0441\u0434\u0435\u043b\u0430\u043d\u043e!\"); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn do_something(stdout: &amp;mut dyn Write) {     writeln!(stdout, \"\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c...\").unwrap();     writeln!(stdout, \"...\u0441\u0434\u0435\u043b\u0430\u043d\u043e!\").unwrap(); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn ensure_something_happens() {     let mut stdout = String::new();     do_something(&amp;mut stdout);      assert_eq!(stdout, \"\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c...\\n...\u0441\u0434\u0435\u043b\u0430\u043d\u043e!\\n\"); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u042f \u0434\u0435\u043b\u0430\u043b \u044d\u0442\u043e <a href=\"https:\/\/github.com\/Patryk27\/lxd-snapper\/blob\/9b096962122988abb3677a69ced244ea7cec2fa2\/src\/cmds\/backup.rs#L159\">\u0440\u0430\u043d\u044c\u0448\u0435<\/a>, \u0438 \u044d\u0442\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c.<\/p>\n<p>  \u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438 <code>do_something()<\/code>, \u043d\u0438 <code>random()<\/code> \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u0442\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e <a href=\"https:\/\/en.wikipedia.org\/wiki\/Referential_transparency\">\u0441\u0441\u044b\u043b\u043e\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c\u044e (referential transparency)<\/a> \u2014 \u0445\u043e\u0442\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn do_something&lt;W: Write>(stdout: W) -> W {     \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u0440\u0435\u0439\u0442 <code>rand<\/code> \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0433\u043e (\u0444\u0438\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e) \u0413\u041f\u0421\u0427, \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0440\u0435\u0439\u0442 \u2014 \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f <a href=\"https:\/\/crates.io\/crates\/rand_chacha\">rand_chacha<\/a> (\u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u0438):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># ...  [dependencies] rand = \"0.8\"  [dev-dependencies] rand_chacha = \"0.3\"<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[cfg(test)] mod tests {     use super::*;     use rand::SeedableRng;     use rand_chacha::ChaCha8Rng;      #[test]     fn random() {         \/\/ \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c (seed), \u043d\u0430\u0448 `rng`         \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439         let mut rng = ChaCha8Rng::from_seed(Default::default());         let neuron = Neuron::random(&amp;mut rng, 4);          assert_eq!(neuron.bias, \/* ... *\/);         assert_eq!(neuron.weights, &amp;[\/* ... *\/]);     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b, \u043d\u043e \u044d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u2014 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0443\u043b\u0435\u0439, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn random() {     \/* ... *\/      assert_eq!(neuron.bias, 0.0);     assert_eq!(neuron.weights, &amp;[0.0, 0.0, 0.0, 0.0]); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 <code>cargo test<\/code> \u0434\u0430\u0435\u0442 \u043d\u0430\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">thread '...' panicked at 'assertion failed: `(left == right)`   left: `-0.6255188`,  right: `0.0`<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn random() {     \/* ... *\/      assert_eq!(neuron.bias, -0.6255188);      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 <code>cargo test<\/code> \u0434\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">thread '...' panicked at 'assertion failed: `(left == right)`   left: `[0.67383957, 0.8181262, 0.26284897, 0.5238807]`,  right: `[0.0, 0.0, 0.0, 0.0]`', src\/lib.rs:29:5<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn random() {     \/* ... *\/      assert_eq!(         neuron.weights,         &amp;[0.67383957, 0.8181262, 0.26284897, 0.5238807]     ); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0440\u0430\u0437\u043d\u044b\u0435, \u0438 \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u2014 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438, \u043f\u043e\u043a\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 <code>cargo test<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0447\u0438\u0441\u0435\u043b (\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0413\u041f\u0421\u0427 \u0441 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u043c).<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0442\u0435\u043c\u0443: <strong>\u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 (\u0437\u0430\u043f\u044f\u0442\u043e\u0439)<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, <code>f32<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 32-\u0431\u0438\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442 <code>~1,2*10^-38<\/code> \u0434\u043e <code>~3,4*10^38<\/code>. \u0423\u0432\u044b, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0447\u0438\u0441\u043b\u0430, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>f32<\/code> \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u0432\u043d\u043e <code>0.15<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     println!(\"{:.10}\", 0.15f32);     \/\/ 0.1500000060 }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438\u043b\u0438 <code>0.45<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {    println!(\"{:.10}\", 0.45f32);    \/\/ 0.4499999881 }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0435 \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043a\u0438\u0440\u043f\u0438\u0447, \u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441 \u043d\u0435\u0431\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test() {     assert_eq!(0.45f32, 0.15 + 0.15 + 0.15); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">thread 'test' panicked at 'assertion failed: `(left == right)`   left: `0.45`,  right: `0.45000002`'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0447\u0438\u0442\u0430\u043b\u0438 \u043e \u0447\u0438\u0441\u043b\u0430\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 <a href=\"https:\/\/floating-point-gui.de\/\">\u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0442\u043e\u0447\u043d\u043e, \u0442\u043e \u043a\u0430\u043a \u0438\u0445 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c? <strong>\u041f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e!<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test() {     let actual: f32 = 0.1 + 0.2;     let expected = 0.3;      assert!((actual - expected).abs() &lt; f32::EPSILON); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u043e \u0432\u0441\u0435\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0445 <a href=\"https:\/\/en.wikipedia.org\/wiki\/IEEE_754\">IEEE 754<\/a> (\u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u043e \u0432\u0441\u0435\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f) \u2014 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441 <strong>\u043e\u0442\u0441\u0442\u0443\u043f\u043e\u043c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 (margin of error)<\/strong> (\u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c <strong>\u0434\u043e\u043f\u0443\u0441\u043a\u043e\u043c (tolerance)<\/strong>).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u043a\u0440\u043e\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">macro_rules! assert_almost_eq {     ($left:expr, $right:expr) => {         let left: f32 = $left;         let right: f32 = $right;          assert!((left - right).abs() &lt; f32::EPSILON);     } }  #[test] fn test() {     assert_almost_eq!(0.45f32, 0.15 + 0.15 + 0.15); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0440\u0435\u0439\u0442\u0430, \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u0430\u043a <a href=\"https:\/\/docs.rs\/approx\/0.4.0\/approx\/\">approx<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test() {     approx::assert_relative_eq!(0.45f32, 0.15 + 0.15 + 0.15); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f <code>approx<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 <code>Cargo.toml<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># ...  [dev-dependencies] approx = \"0.4\" rand_chacha = \"0.3\"<\/code><\/pre>\n<p>  <\/p>\n<p>\u2026 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use super::*; use approx::assert_relative_eq; use rand::SeedableRng; use rand_chacha::ChaCha8Rng;  #[test] fn random() {     let mut rng = ChaCha8Rng::from_seed(Default::default());     let neuron = Neuron::random(&amp;mut rng, 4);      assert_relative_eq!(neuron.bias, -0.6255188);      assert_relative_eq!(         neuron.weights.as_slice(),         [0.67383957, 0.8181262, 0.26284897, 0.5238807].as_ref()     ); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0434\u043b\u044f <code>Neuron::propagate()<\/code> \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0440\u0443\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[cfg(test)] mod tests {     \/* ... *\/      #[test]     fn random() {         \/* ... *\/     }      #[test]     fn propagate() {         todo!()     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0438\u0445 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0439.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0442\u0430\u043a \u2014 \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438 \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">#[cfg(test)] mod tests {     use super::*;      mod cart {         use super::*;          mod when_user_adds_a_flower_to_their_cart {             use super::*;              #[test]             fn user_can_see_this_flower_in_their_cart() {                 \/* ... *\/             }              #[test]             fn user_can_remove_this_flower_from_their_cart() {                 \/* ... *\/             }              mod and_submits_order {                 \/* ... *\/             }              mod and_abandons_cart {                 \/* ... *\/             }         }     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 <code>Neuron<\/code> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c &#171;\u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043e\u0434\u043e\u043c&#187;, \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 &#171;\u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043a\u043e\u0434\u0430&#187; \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043a\u043e\u0434\u043e\u043c. \u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 <strong>\u043a\u0440\u0430\u0439\u043d\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438<\/strong>, \u0441\u043a\u0430\u0436\u0435\u043c:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">fn propagate(\/* ... *\/) {     if \/* ... *\/ {         do_foo()     } else {         do_bar()     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u0442\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430:<\/p><\/blockquote>\n<p>  <\/p>\n<pre><code class=\"rust\">#[cfg(test)] mod tests {     use super::*;      mod propagate {         use super::*;          mod given_neuron_with_foo {             use super::*;              #[test]             fn fooifies_it() {                 \/* ... *\/             }         }          mod given_neuron_thats_bar {             use super::*;              #[test]             fn bars_it() {                 \/* ... *\/             }         }     } }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u2026 \u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 <code>fn random()<\/code> \u0438 <code>fn propagate()<\/code>.<\/p><\/blockquote>\n<p>\u041a\u0430\u043a \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>propagate()<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e? \u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0440\u0443\u0447\u043d\u0443\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn propagate() {     let neuron = Neuron {         bias: 0.5,         weights: vec![-0.3, 0.8],     };      \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 `.max()` (\u043d\u0430\u0448\u0435\u0433\u043e ReLU):     assert_relative_eq!(         neuron.propagate(&amp;[-10.0, -10.0]),         0.0,     );      \/\/ `0.5` \u0438 `1.0` \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e:     assert_relative_eq!(         neuron.propagate(&amp;[0.5, 1.0]),         (-0.3 * 0.5) + (0.8 * 1.0) + 0.5,     );      \/\/ \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c `1.15`, \u043d\u043e \u043f\u043e\u043b\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430     \/\/ \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u0448\u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u044f\u0441\u043d\u044b\u043c\u0438 }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f <code>Layer<\/code> \u0438 <code>Network<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchitelnye-mysli\">\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u044b\u0441\u043b\u0438<\/h2>\n<p>  <\/p>\n<p><strong>\u0427\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438?<\/strong><\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u0441 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0438\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0427\u0442\u043e \u043d\u0430\u0441\u0447\u0435\u0442 \u0433\u043b\u0430\u0437?<\/li>\n<li>\u0413\u0434\u0435 \u043a\u043e\u0434, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435?<\/li>\n<li>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0435\u043b\u0435\u043d\u043e\u0432\u0430\u0442\u044b\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432 \u0441\u0442\u0438\u043b\u0435 Fallout?<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u2026 \u043d\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0430\u043c\u0430 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c, \u0445\u043e\u0442\u044f \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b, \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u2014 \u043d\u0435 \u0432\u043e\u043b\u043d\u0443\u0439\u0442\u0435\u0441\u044c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0432\u0441\u0435 \u0432\u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0430 \u0441\u0432\u043e\u0438 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0410 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 <a href=\"https:\/\/github.com\/Patryk27\/shorelark\/tree\/main\/libs\/neural-network\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c<\/a>.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0442\u0430\u043a\u043e\u0439 \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u0439?<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 &#171;\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043d\u0430 Python \u0441 \u043d\u0443\u043b\u044f&#187;, \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 FFNN \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 Python \u2014 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043d\u0438\u043c\u0438 \u043d\u0430\u0448 \u043a\u043e\u0434 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0434\u0443\u0442\u044b\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a?<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043c\u0443 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f! \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0435\u0442\u044c \u0432 1\/10 \u043e\u0442 \u0435\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/nalgebra.org\/\">nalgebra<\/a>, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u0436\u0435 <a href=\"https:\/\/www.arewelearningyet.com\/neural-networks\/\">\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u0440\u0435\u0439\u0442\u043e\u0432<\/a>, \u043d\u043e \u043d\u0430\u043c \u0432\u0430\u0436\u0435\u043d \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043d\u043a\u0442 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u0438 \u0441\u0430\u043c\u043e \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435.<\/p>\n<p>  <\/p>\n<p><strong>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/strong><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f FFNN \u2014 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0435\u0433\u043e \u043a \u043d\u0430\u0448\u0435\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438.<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<blockquote><p><a href=\"https:\/\/t.me\/timewebru\"><b>\u041d\u043e\u0432\u043e\u0441\u0442\u0438, \u043e\u0431\u0437\u043e\u0440\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0441\u044b \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Timeweb.Cloud \u2014 \u0432 \u043d\u0430\u0448\u0435\u043c Telegram-\u043a\u0430\u043d\u0430\u043b\u0435<\/b><\/a> <b>\u21a9<\/b><\/p><\/blockquote>\n<p><a href=\"https:\/\/timeweb.cloud\/?i=106909\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/r8\/ms\/jc\/r8msjcfet9mgza3ybpor_sdgrt0.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/r8\/ms\/jc\/r8msjcfet9mgza3ybpor_sdgrt0.jpeg\" data-blurred=\"true\"\/><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/818985\/\"> https:\/\/habr.com\/ru\/articles\/818985\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ok\/13\/y9\/ok13y9vlz-qasq8lvjgusd0lpyk.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ok\/13\/y9\/ok13y9vlz-qasq8lvjgusd0lpyk.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438<\/strong> \u0438 <strong>\u0433\u0435\u043d\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/strong>.<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/817585\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u043b\u043e\u0436\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e FFNN (feedforward neural network \u2014 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u043e\u0437\u0433\u043e\u043c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0434\u0438\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u0434\u0435 Rust, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435\u0441\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b? \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/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-378448","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378448","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=378448"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378448\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}