算法训练营Day1
704. 二分查找 704. 二分查找 - 力扣(LeetCode) 123456789101112131415161718192021class Solution {public: int search(vector<int>& nums, int target) { size_t left{}; size_t right{nums.size() - 1}; while (left <= right) { size_t mid{left + (right - left) / 2}; if (nums[mid] == target) { return mid; } else if (nums[mid] < target) { left = mid + 1; ...
Go并发模式
A boring function 1234567891011121314151617package mainimport ( "fmt" "time")func boring(msg string) { for i := 0; ; i++ { fmt.Println(msg, i) time.Sleep(time.Second) }}func main() { boring("boring!")} Slightly less boring 123456789101112131415161718package mainimport ( "fmt" "math/rand" "time")func boring(msg string) { for i := 0; ; i++ { fmt.Println(msg,...
uv的使用
1234567891011uv venv --python python3.12# 从 requirements.txt 安装uv pip install -r requirements.txt# 同时安装和同步到 requirements.txtuv pip sync requirements.txt# 导出当前环境的依赖到 requirements.txtuv pip freeze > requirements.txt# 只包含直接安装的包(不包含依赖的依赖)uv pip freeze --exclude-editable > requirements.txt# 以兼容 pip 的格式导出uv pip freeze --format pip > requirements.txt
从类型论的角度看Rust的生命周期
Rust的生命周期尽管细化了一些编程语言中的类型,但没有细化完全,或者说在Rust中有些符号滥用,关系表示的并不是那么明晰。用不严谨的类型论的符号可以表示如下。需要注意的就是生命周期可以视作类型的“类型”,用T : 'a表示,而生命周期之间的关系则是同一层级的类型之间的关系用'a <: 'b表示'a的生命周期长于'b。 12345678910111213'static 是 'a 的子类型, 'a 是 'b 的子类型, 即: 'static <: 'a <: 'bi32 : 'staticString : 'staticT : 'static若T : 'static, 则&T = &'a T : 'a. 这里的&T似乎应该视作&'a T. 万恶的自动推导将细节隐藏起来了. 暴论: Rust的学习难度就是因为这些干扰语言一致性的语法糖造成的。若T : 'a,...
Cpp指针、引用 VS Rust所有权、借用
Rust的所有权与变量遮蔽有关,与C++的移动语义还是有一些区别。比如在C++下述操作中const变量d和j并不会随std::move而清空: 123456789std::string a{"1"};std::string b{"12"};std::string c{"123"};std::string const d{"1234"};std::string i{std::move(a)};i = std::move(b);i = std::move(d);std::string const j{std::move(c)};std::string const k{std::move(j)}; 对于引用: 123456789101112131415161718std::string a{"1"};std::string...
引用折叠、万能引用和完美转发
本文给出引用折叠、万能引用和完美转发的相关代码。需要注意的是万能引用(T &&arg)中匹配的类型T,要么是U,要么是U&&。forward的返回值,要么是不具名左值引用,要么是不具名右值引用。在wrapper中,对forward的调用,要么是forward<U>(U &&arg),要么是forward<U&>(U...
WSL的安装与迁移
管理员身份运行PowerShell,执行: 1234567wsl -l -vwsl --install Ubuntu-22.04wsl --shutdown Ubuntu-22.04wsl --export Ubuntu-22.04 E:\Ubuntu22.tarwsl --unregister Ubuntu-22.04wsl --import Ubuntu-22.04 E:\WSL\Ubuntu22 E:\Ubuntu22.tar --version 2ubuntu2204 config --default-user <username> 注意:需要手动创建E:\WSL\Ubuntu22目录 具体可见: WSL 的基本命令 | Microsoft Learn WSL安装linux系统以及从C盘迁移至其他盘_哔哩哔哩_bilibili
在windows系统上部署whisper-rs
本文介绍如何在Windows系统上部署whisper-rs项目进行语言流式转录。 前置条件 构建该项目需要在VS中安装Clang组件,具体教程见:How to Install Clang on Windows - wikiHow。安装组件后,需先打开Developer Command Prompt for VS 2022,在其中输入 Command Prompt for VS 20221where.exe clang 将显示的路径所对应的形如C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin的路径作为环境变量LIBCLANG_PATH,并将路径添加到PATH中。注意不是Llvm\bin,而是Llvm\x64\bin。 构建并使用 12git clone --recursive https://github.com/tazz4843/whisper-rs.gitcd whisper-rs 下载ggerganov/whisper.cpp at...
在windows系统上部署whisper.cpp
本文介绍如何在Windows系统上部署whisper.cpp项目进行语言流式转录。 克隆仓库并下载base.en模型 123git clone https://github.com/ggerganov/whisper.cpp.gitcd whisper.cpp.\models\download-ggml-model.cmd base.en base.en模型是English-only model,若使用Multilingual model请去掉.en。所有可用模型,请见:whisper.cpp/models/README.md at master · ggerganov/whisper.cpp。 下载 vcpkg 并配置环境变量 请参见: 在 Visual Studio Code 中使用 CMake 安装和管理包 | Microsoft...
在Windows系统上部署openai-whisper模型
本文介绍如何在Windows系统上部署openai/whisper模型。除开ffmpeg的安装外,其余步骤都可参见openai/whisper: Robust Speech Recognition via Large-Scale Weak Supervision。建议使用scoop安装ffmpeg,因为Chocolatey无法更改自定义默认下载目录。 安装Scoop和ffmpeg音频处理库 12345# 安装powershellSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserirm get.scoop.sh -outfile 'install.ps1'.\install.ps1 -ScoopDir 'E:\ProgramHome\Scoop' -ScoopGlobalDir 'E:\ProgramHome\GlobalScoopApps' -NoProxyscoop install ffmpeg 安装whisper 1234#...