This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Rcpp.h> | |
| #include <algorithm> | |
| using namespace Rcpp; | |
| inline double vec_sum(const Rcpp::NumericVector &x) { | |
| return std::accumulate(x.begin(), x.end(), 0.0); | |
| } | |
| // [[Rcpp::export]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=Jupyter notebook | |
| [Service] | |
| Type=simple | |
| ExecStart=/usr/bin/jupyter-notebook --no-browser | |
| [Install] | |
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sympy import symbols, diff, solve, init_printing, latex | |
| init_printing(use_latex = "mathjax") | |
| from IPython.display import display, Math | |
| # аргументы и формула | |
| x, y, = symbols(("x", "y")) | |
| expr = x ** 3 + 4 * y ** 3 - 3 * x - 3 * y | |
| display(Math(r"f(x,y) = %s" % latex(expr))) | |
| # производные первого порядка | |
| dx = diff(expr, x) | |
| dy = diff(expr, y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib.request as req | |
| import io | |
| import zipfile | |
| import tempfile | |
| import os.path | |
| url = "https://stepic.org/media/attachments/lesson/24465/main.zip" | |
| with req.urlopen(url) as resp: | |
| with zipfile.ZipFile(io.BytesIO(resp.read())) as zfile: | |
| dirlist = {os.path.dirname(i) for i in zfile.namelist() if i.endswith(".py")} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [[Rcpp::plugins(cpp11)]] | |
| // [[Rcpp::depends(RcppArmadillo)]] | |
| #include <RcppArmadillo.h> | |
| // [[Rcpp::depends(RcppEigen)]] | |
| #include <RcppEigen.h> | |
| // [[Rcpp::export]] | |
| Rcpp::NumericMatrix cbind_rcpp_for(const Rcpp::NumericMatrix& x, const Rcpp::NumericMatrix& y) { | |
| std::size_t ncols_x = x.cols(), nrows_x = x.rows(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| double median(const NumericVector& x) { | |
| NumericVector y(x); | |
| std::size_t n = y.size(); | |
| int half = n / 2; | |
| std::nth_element(y.begin(), y.begin() + half, y.end()); | |
| if(n % 2 == 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Rcpp.h> | |
| // [[Rcpp::export]] | |
| double fastsum(const Rcpp::NumericVector& x) { | |
| std::size_t n = x.size(); | |
| double total = 0; | |
| if (n > 0) { | |
| for (std::size_t i = 0, k = n - 1; i < k; ++i, --k) | |
| total += x[i] + x[k]; | |
| if (n % 2 == 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!usr/bin/env python | |
| import sys | |
| import random | |
| def make_pairs(l): | |
| if len(l) % 2 != 0: | |
| raise ValueError("Количество элементов должно быть чётным.") | |
| return zip(l[::2], l[1::2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| // [[Rcpp::plugins(cpp11)]] | |
| template <int RTYPE> | |
| Vector<RTYPE> rep_each_impl(const Vector<RTYPE>& x, std::size_t each) { | |
| std::size_t n = x.size(); | |
| Vector<RTYPE> res = no_init(n * each); | |
| auto begin = res.begin(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // [[Rcpp::plugins(cpp11)]] | |
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| template <int RTYPE> | |
| Vector<RTYPE> shuffle_impl(const Vector<RTYPE>& x) { | |
| Vector<RTYPE> res(x); // make copy | |
| auto first = res.begin(), last = res.end(); |