Skip to the relevant sections if needed.
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 <cstddef> | |
#include <cstdlib> | |
template <typename R, auto getter, auto setter, size_t (*offset)()> | |
struct property { | |
inline R *self() { | |
return reinterpret_cast<R *>(reinterpret_cast<size_t>(this) - offset()); | |
} | |
inline operator auto() { return (self()->*getter)(); } | |
inline void operator=(auto t) { (self()->*setter)(t); } |
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
void imageScaleAndRotate(const cv::Mat &src, cv::Mat &out, double scale, double roll) { | |
// scaling | |
cv::Mat imSmall; | |
cv::resize(src, imSmall, cv::Size(), scale, scale); | |
// prepare for rotating | |
int width = imSmall.cols, height = imSmall.rows; | |
int diagonal = int(sqrt(height * height + width * width)); | |
int offsetX = (diagonal - width) / 2, offsetY = (diagonal - height) / 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
# A minimal example of how to implement byte-pair encoding (BPE) tokenizer from scratch in Python. | |
# Reference: https://github.com/karpathy/minbpe | |
# Contact: [email protected] | |
def get_stats(byte_arr): | |
# get the frequency of each byte pair in the text | |
count = {} | |
for pair in zip(byte_arr[:-1], byte_arr[1:]): # e.g. pair: (b'a', b' ') | |
count[pair] = count.get(pair, 0) + 1 |
OlderNewer