This file contains 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
#coding:utf-8 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import math | |
def f(x): | |
return x[0] * x[0] + 50 * x[1] * x[1] | |
def g(x): | |
return np.array([2 * x[0], 100 * x[1]]) |
This file contains 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
#pragma once | |
#include <vector> | |
#include <string> | |
#include <algorithm> | |
#include <sstream> | |
#include "dirent.h" | |
std::string replace_all(const std::string& str, const std::string& from, const std::string& to) { | |
std::string result_str = str; | |
size_t start_pos = 0; |
This file contains 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
static const std::string base64_chars = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"abcdefghijklmnopqrstuvwxyz" | |
"0123456789+/"; | |
static inline bool is_base64(unsigned char c) { | |
return (isalnum(c) || (c == '+') || (c == '/')); | |
} |
This file contains 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
#coding: utf-8 | |
#demo of beam search for seq2seq model | |
import numpy as np | |
import random | |
vocab = { | |
0: 'a', | |
1: 'b', | |
2: 'c', | |
3: 'd', |
This file contains 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
//std headers | |
#include <fstream> | |
#include <iostream> | |
//lib headers | |
#include <gif_lib.h> | |
#define USING_NEW_GIF_LIB defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 | |
cv::Mat imread_gif(const std::string& filename, const int flags) | |
{ | |
std::ifstream stream(filename, std::ios::in | std::ios::binary); |
This file contains 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
def custom_min(data): | |
assert len(data) >= 1 | |
if len(data) <= 0: | |
return data,0 | |
min_idx = 0 | |
min_data = data[min_idx] | |
for i,item in enumerate(data): | |
if item < min_data: | |
min_data = item | |
min_idx = i |
This file contains 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
std::string local_to_utf8(const std::string& src) | |
{ | |
#if _WIN32 | |
int len = MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, NULL, 0); | |
wchar_t* wszUTF16 = new wchar_t[len+1]; | |
memset(wszUTF16, 0, len+1); | |
MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, wszUTF16, len); | |
len = WideCharToMultiByte(CP_UTF8, 0, wszUTF16, -1, NULL, 0, NULL, NULL); | |
char* szUTF8 = new char[len + 1]; | |
memset(szUTF8, 0, len + 1); |
This file contains 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
static std::ostream& operator<<(std::ostream& os, const std::vector<int>& data) | |
{ | |
for (size_t i = 0; i < data.size();i++) | |
{ | |
os << data[i]; | |
if (i < (int)data.size() - 1) | |
{ | |
os << ", "; | |
} | |
} |
This file contains 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
static int split(std::vector<int>& data, const int beg, const int end) | |
{ | |
if (beg >= end || end <= 0) | |
{ | |
return -1; | |
} | |
int idx = beg; | |
const int base = data[end - 1]; | |
for (int i = beg; i < end; i++) | |
{ |
This file contains 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 <chrono> | |
#include <string> | |
#include <iostream> | |
struct profiler | |
{ | |
std::string name; | |
std::chrono::high_resolution_clock::time_point p; | |
profiler(std::string const &n) : | |
name(n), p(std::chrono::high_resolution_clock::now()) { } |