Skip to content

Instantly share code, notes, and snippets.

View ManishAradwad's full-sized avatar

toji ManishAradwad

View GitHub Profile
@ManishAradwad
ManishAradwad / donut.mojo
Created December 14, 2023 13:57
Donut.mojo
from math import sin, cos
struct Array[T: AnyRegType]:
var value: T
var rows: Int
var cols: Int
var total_items: Int
var data: Pointer[T]
fn __init__(inout self, value: T, rows: Int, cols: Int) -> None:
@ManishAradwad
ManishAradwad / pmodel.py
Created September 1, 2022 14:22
Probabilistic Model for recommendation system
n = 5
alpha = 0.2
p = 0.8
summ = 0
for i in range(n):
summ += p*(alpha**i)
prev_votes = np.floor(n_clusters*np.random.rand(4, n)-0.000001)
boundary = np.zeros(n)
@ManishAradwad
ManishAradwad / vgg.py
Created September 1, 2022 14:10
Model for recommendation system
# VGG16 is used as pretrained CNN model
vgg_model = VGG16(weights='imagenet', include_top=False, input_shape=(512, 512, 3))
model = keras.Sequential()
for layer in vgg_model.layers:
model.add(layer)
model.add(Flatten())
model.add(Dense(512, name='embeddings'))
# Flattening the mesh
vertices = np.array(mesh.vertices)
vertices[:, 2] = vertices[:, 2].mean() # Replacing the depth value with the mean depth
# Function to plot the mesh
def plot(triangles, vertices):
fig = go.Figure(
data=[
go.Mesh3d(
x=vertices[:,0],
y=vertices[:,1],
z=vertices[:,2],
i=triangles[:,0],
j=triangles[:,1],
# Loading the mesh
mesh = o3d.io.read_triangle_mesh("bunny.obj")
# All this is needed for plotting the mesh properly
if not mesh.has_vertex_normals(): mesh.compute_vertex_normals()
if not mesh.has_triangle_normals(): mesh.compute_triangle_normals()
triangles = np.asarray(mesh.triangles)
vertices = np.asarray(mesh.vertices)
colors = None
@ManishAradwad
ManishAradwad / nst.py
Created July 2, 2022 15:01
Assorted NST
generated_image = weights[0]*style1_image + weights[1]*style2_image + weights[2]*style3_image
@ManishAradwad
ManishAradwad / custom_gradient.py
Created June 26, 2022 12:56
Custom Gradient Function
# Final function to return some random crease from 8 different types
def custom_crease():
spacing = random.uniform(1, 1.5)
scale = random.randint(100, 300)
corner = random.randint(1, 4)
# constant determines the type of crease and also is used to scale spacing in parabolic_crease
constant = random.randint(1, 10)
# Returning those creases which are based on parabolic
@ManishAradwad
ManishAradwad / parabolic_gradient.py
Last active June 26, 2022 12:52
Parabolic Gradient
def parabolic_crease(spacing, c, scale=100, corner=1, resolution = 1000):
"""
Parameters:
spacing = controls how close the intermediate values will be to lower value
c = higher the c more spread out the gradient will be
scale = lesser the scale more concentrated is gradient towards the corner
"""
img = np.zeros((resolution, resolution))
@ManishAradwad
ManishAradwad / create_uneven_array.py
Last active June 26, 2022 12:52
Create uneven array
# cross = True if cross crease is wanted
def create_uneven_array(low, up, steps, spacing=1, cross=False):
span = up - low
dx = 1.0 / steps
if cross:
arr = np.array([low + (i*dx)**spacing*span for i in range(steps//2)])
return np.append(arr, arr[::-1])
else :
arr = np.array([low + (i*dx)**spacing*span for i in range(steps)])
return arr