This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void say_hello(int times) | |
{ | |
for (int i = 0; i < times; ++i) | |
{ | |
printf("%d. Hello, Python. I am C!\n", i+1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
# A. Create library | |
C_library = ctypes.CDLL("clib.so") | |
# B. Specify function signatures | |
hello_fxn = C_library.say_hello | |
hello_fxn.argtypes = [ctypes.c_int] | |
# C. Invoke function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clib.so: clib.o | |
gcc -shared -o clib.so clib.o |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataHandler: | |
def __init__(self, string): | |
self.string = string | |
characters = np.sort(list(set(string))) | |
self.num_characters = len(characters) | |
self.char_to_idx = { ch : i for i, ch in enumerate(characters) } | |
self.idx_to_char = { i : ch for ch, i in self.char_to_idx.items() } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import torch.nn as nn | |
class HelloRNN(nn.Module): | |
def __init__(self, num_chars, num_hidden=10): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Connection Matrices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N_EPOCHS = 5000 | |
LR = 0.005 | |
end_early = False | |
seq_i = "" | |
net.train() # Ensure net in training mode | |
for epoch_i in range(N_EPOCHS): | |
# Zero out gradients | |
optimizer.zero_grad() | |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LSTMCell(nn.Module): | |
def __init__(self, num_chars, num_hidden): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Potential Input | |
self.Wxh = nn.Parameter(torch.randn((num_chars, num_hidden))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GRUCell(nn.Module): | |
def __init__(self, num_chars, num_hidden): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Potential Input | |
self.Wxh = nn.Parameter(torch.randn((num_chars, num_hidden))) |
OlderNewer