class Singleton {
Singleton() = default;
public:
Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete;
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 showOpenCVMat(cv::Mat img, UIImageView* imageView) { | |
cv::Mat converted; | |
img.convertTo(converted, CV_8U); | |
// convert the cv::Mat to UIImage | |
NSData *data = [NSData dataWithBytes:converted.data length:converted.elemSize() * converted.total()]; | |
CGColorSpaceRef colorSpace = | |
CGColorSpaceCreateDeviceGray(); // CGColorSpaceCreateDeviceRGB(); | |
CGDataProviderRef provider = | |
CGDataProviderCreateWithCFData((__bridge CFDataRef)data); | |
CGImageRef imageRef = CGImageCreate( |
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
template <typename T> | |
class vector { | |
size_t size_ = 0; | |
size_t capacity_ = 0; | |
T* data_ = nullptr; | |
public: | |
// Default constructor | |
vector() = default; |
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
def sample(img, x: float, y: float): | |
h, w = img.shape | |
left = math.floor(x) | |
top = math.floor(y) | |
right = left + 1 | |
bottom = top + 1 | |
# top left corner | |
if (0 <= left < w) and (0 <= top < h): |
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 <limits> | |
#include <iostream> | |
int main() { | |
float eps = std::numeric_limits<float>::epsilon(); | |
float a = 1.0f; | |
float b = a + eps; | |
float c = a + eps / 2.0f; | |
std::cout << "a == b: " << std::boolalpha << (a == b) << "\n"; // false | |
std::cout << "a == c: " << std::boolalpha << (a == c) << "\n"; // true |
给 ComputeShader
class 增加以下三个方法:
// 从 OpenCV Mat 创建(只读的) Metal Texture
- (id<MTLTexture>) textureFromCVMat:(const void*)cv_data Width:(int) w Height:(int)h {
// Create a Metal texture descriptor
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR8Unorm
width:w
height:h
mipmapped:NO];
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 Cocoa | |
let input: [Float] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0] | |
var output_real = Array<Float>(repeating: 0, count: 8) | |
var output_imag = Array<Float>(repeating: 0, count: 8) | |
for i in 0..<8 { | |
var real_sum: Float = 0.0 | |
var imag_sum: Float = 0.0 | |
for k in 0..<8 { |
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
// | |
// Timer.h | |
// NLE | |
// | |
// Created by Guo Shuai on 2023/7/27. | |
// | |
#ifndef Timer_h | |
#define Timer_h |
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 <stdio.h> | |
#include <math.h> | |
#define PI 3.14159265358979323846 | |
// O(n^2) | |
void dft(double *input, double *real, double *imag, int n) { | |
for (int k = 0; k < n; k++) { | |
real[k] = 0; | |
imag[k] = 0; |