Skip to content

Commit d1fbc25

Browse files
refac(structure): implment rust's package structure
1 parent 735285e commit d1fbc25

6 files changed

Lines changed: 279 additions & 33 deletions

File tree

try1 (OOP Approach)/rust/Cargo.lock

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "LowLevelMLP"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
lazy_static = "1.5.0"
8+
rand = "0.9.0"

try1 (OOP Approach)/rust/MLP.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

try1 (OOP Approach)/rust/main.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use rand::Rng;
2+
3+
fn random_float(rand_range: u8) -> f32 {
4+
let mut rng = rand::rng();
5+
let random_val: f32 = rng.random::<f32>();
6+
7+
(random_val * (rand_range as f32) * 2.0) - 1.0
8+
}
9+
struct Neuron {
10+
pub value: f32,
11+
pub bias: f32,
12+
pub weights: Vec<f32>,
13+
pub prev_layer_neurons_count: u8,
14+
}
15+
impl Neuron {
16+
fn new(prev_layer_neurons_count: u8) -> Neuron {
17+
let rand_range: u8 = 1;
18+
let mut weights: Vec<f32> = Vec::new();
19+
for _ in 0..prev_layer_neurons_count {
20+
weights.push(random_float(rand_range));
21+
}
22+
23+
Neuron {
24+
value: 0.0,
25+
bias: random_float(rand_range),
26+
weights,
27+
prev_layer_neurons_count,
28+
}
29+
}
30+
}
31+
struct Layer {
32+
size: u8,
33+
neurons: Vec<Neuron>,
34+
}
35+
impl Layer {
36+
fn new(size: u8, prev_layer_neurons_count: u8) -> Layer {
37+
let mut neurons: Vec<Neuron> = Vec::new();
38+
for _ in 0..size {
39+
neurons.push(Neuron::new(prev_layer_neurons_count));
40+
}
41+
42+
Layer { size, neurons }
43+
}
44+
// TODO: Add Other Function of Layer Struct
45+
}
46+
// TODO: Add remaining Structs like MLP,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod MLP;
2+
fn main() {}

0 commit comments

Comments
 (0)