This document provides guidelines for maintaining high-quality Rust code. These rules MUST be followed by all AI coding agents and contributors.
All code you write MUST be fully optimized.
"Fully optimized" includes:
| # -*- coding: utf-8 -*- | |
| import torch | |
| import math | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import torchvision.io as io | |
| import torchvision.transforms as T | |
| from torch.utils.data import TensorDataset, DataLoader |
| import tensorflow as tf | |
| import tensorflow_datasets as tfds | |
| (ds_train, ds_test), ds_info = tfds.load( | |
| 'mnist', | |
| split=['train', 'test'], | |
| shuffle_files=True, | |
| as_supervised=True, | |
| with_info=True, | |
| ) |
| set nowrap | |
| set nobackup | |
| set undofile " Undo across sessions | |
| set undolevels=800 " Keep 800 changes to be undone | |
| set undodir=~/.vim/tmp/undo// | |
| nmap <F2> :.w !pbcopy<CR><CR> | |
| vmap <F2> :w !pbcopy<CR><CR> | |
| set noswapfile |
| brew install neovim | |
| rustup component add rust-analyzer | |
| brew install luajit | |
| sudo ln -s `which luajit` /usr/local/bin/lua | |
| nvim -u NORC -c "source https://raw.githubusercontent.com/lumen-oss/rocks.nvim/master/installer.lua" | |
| nvim | |
| :Rocks install rustaceanvim | |
| :RustAnalyzer start |
| // https://gist.github.com/stephenlb/d1a2972222864afea79076b793e4f58d | |
| const http = require("xhr"); | |
| const pubnub = require("pubnub"); | |
| const dataUrl = 'https://gist.githubusercontent.com/stephenlb/d1a2972222864afea79076b793e4f58d/raw/4854f61998c6972a87dc63c257b8c8138ea4a541/Chat-flooding_api_calls.json'; | |
| const publishKey = '...............'; | |
| const subscribeKey = '...............'; | |
| let data = null; | |
| let position = 0; |
| startup_message off | |
| vbell on | |
| msgwait 1 | |
| defscrollback 200000 | |
| hardstatus alwayslastline | |
| hardstatus string '%{= kG}[ Stephen Blum ]%{g}[%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m/%d %{W}%c %{g}]' | |
| caption string "%{W}%n%f %t%?(%u)%?%{r}" | |
| rendition so =rb 04 |
To compile and execute the program from a different source file, such as infer.rs, and name the resulting binary infer, follow these modified instructions:
Update Project Structure: Create a new source file named infer.rs in the src directory.
touch src/infer.rs| # YouTube Video https://youtu.be/SDCzXr-mBcw | |
| import torch | |
| import requests | |
| from PIL import Image | |
| from transformers import Blip2Processor, Blip2ForConditionalGeneration | |
| from optimum.bettertransformer import BetterTransformer | |
| # Load the processor and model | |
| processor = Blip2Processor.from_pretrained("Salesforce/blip2-flan-t5-xl") |
| Images from 120ms to 30ms: Python 🐍 to Rust 🦀🚀 article |