Skip to content

Instantly share code, notes, and snippets.

View ghamarian's full-sized avatar

Amir Ghamarian ghamarian

View GitHub Profile
#include <hip/hip_runtime.h>
#include <iostream>
#define BLOCK_SIZE 256
__global__ void vecAdd(const float* __restrict__ A,
const float* __restrict__ B,
float* __restrict__ C,
int n)
{
# Make sure you have these installed:
# pip install torch pandas faiss-gpu (or faiss-cpu if no GPU)
import pandas as pd
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
def next_row(a):
return [0] + [a + b for a, b in zip(a, a[1:])] + [0]
def g(n):
lst = [[0, 1, 0]]
for _ in range(n):
lst.append(next_row(lst[-1]))
return lst
from pynput import keyboard
import pyperclip
import time
# Initialize
with open("your_file.txt", "r") as f:
lines = f.readlines()
# Remove newline characters
lines = [line.strip() for line in lines]

Torch objects used in learnpytorch.io website

name type
torch.Tensor <class 'torch._C._TensorMeta'>
torch.e <class 'float'>
torch.t <class 'builtin_function_or_method'>
torch.torch <class 'module'>
torch.eig <class 'function'>
torch.ne <class 'builtin_function_or_method'>
torch.nn
# Torch objects used in learnpytorch.io website
|name|type|
|----|----|
|torch.Tensor|<class 'torch._C._TensorMeta'>|
|torch.e|<class 'float'>|
|torch.t|<class 'builtin_function_or_method'>|
|torch.torch|<class 'module'>|
|torch.eig|<class 'function'>|
|torch.ne|<class 'builtin_function_or_method'>|
|torch.nn|<class 'module'>|
#include <algorithm>
#include <concepts>
#include <functional>
#include <iostream>
#include <memory>
#include <vector>
template <typename T>
concept Drawable = requires(T t) {
{ t.draw() } -> std::same_as<void>;
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
xs = []
ys = []
import operator
from itertools import cycle
from numbers import Number
import numpy as np
def broadcast(a, b, op):
if isinstance(a, Number) and isinstance(b, Number):
#include <Eigen/Dense>
#include <Eigen/IterativeLinearSolvers>
#include <algorithm>
#include <iostream>
#include <random>
#include <vector>
std::pair<Eigen::MatrixXf, Eigen::MatrixXf> GenerateData(size_t n) {
std::vector<float> x_data(n);