Skip to content

Instantly share code, notes, and snippets.

@mohitd
mohitd / artificial_neural_network.py
Created December 12, 2023 04:45
Artificial Neural Network Implementation
import numpy as np
from torchvision import datasets
from matplotlib import pyplot as plt
np.random.seed(42)
class Sigmoid:
@staticmethod
def forward(z):
return 1. / (1. + np.exp(-z))
@mohitd
mohitd / artificial_neuron.py
Created December 6, 2023 05:28
Artificial Neuron Implementation
import matplotlib.pyplot as plt
from sklearn import datasets
import numpy as np
# fix the seed for determinism
np.random.seed(42)
def cost(pred, true):
return 0.5 * (true - pred) ** 2
@mohitd
mohitd / different_inputs.cpp
Created January 17, 2022 20:27
Homogeneous API for different Inputs
#include <iostream>
#include <memory>
struct Data {
virtual ~Data() = default;
};
struct TcpData : public Data {
int x;
};
@mohitd
mohitd / coordgetter.cpp
Created January 17, 2022 19:30
Implementing a `get` function for vectors
#include <iostream>
struct Point2 {
float x, y;
};
template<std::size_t I, typename T>
struct CoordGetter;
template<>
@mohitd
mohitd / no-rvo.s
Created March 13, 2019 02:36
Return Value Optimization
0000083d <func()>:
Widget func() {
83d: 55 push ebp
83e: 89 e5 mov ebp,esp
840: 56 push esi
841: 53 push ebx
842: 83 ec 20 sub esp,0x20
845: e8 e2 02 00 00 call b2c <__x86.get_pc_thunk.si>
84a: 81 c6 6a 27 00 00 add esi,0x276a
; CDECL setup stuff
@mohitd
mohitd / kernel.c
Created April 22, 2018 00:20
CSE 5525: Linux Kernel code (shortened)
// SPDX-License-Identifier: GPL-2.0
/*
* Many of the syscalls used in this file expect some of the arguments
* to be __user pointers not __kernel pointers. To limit the sparse
* noise, turn off sparse checking for this file.
*/
#ifdef __CHECKER__
#undef __CHECKER__
#warning "Sparse checking disabled for this file"
#endif
@mohitd
mohitd / sonnets.txt
Created April 18, 2018 16:23
CSE 5525: Shakespeare sonnets for text generation tutorial
THE SONNETS
by William Shakespeare
I
From fairest creatures we desire increase,