Skip to content

Commit

Permalink
bugfixes - mismatching types
Browse files Browse the repository at this point in the history
  • Loading branch information
yonatankarni committed Jan 2, 2023
1 parent a93530a commit 5f085f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ flate2 = { version = "1.0", features = ["cloudflare_zlib"], default-features = f
shellwords = "1.1.0"
blas = "0.22"
intel-mkl-src = {version= "0.7.0", default-features = false, features=["download", "mkl-static-lp64-seq"]}

libm = "0.2.6"
[build-dependencies]
cbindgen = "0.23.0"

Expand Down
14 changes: 7 additions & 7 deletions src/block_sigmoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ impl BlockTrait for BlockSigmoid

// for now doing the actual slow sigmoid computation. once we establish a baseline,
// we can replace with a fast approximation or a lookup table
if x < 0 {
let epx = f32::pow(e, x);
let s = epx / (1 + epx);
if x < 0. {
let epx = f32::powf(e, x);
let s = epx / (1.0 + epx);
*pb.tape.get_unchecked_mut(self.output_offset + i) = s;
*pb.tape.get_unchecked_mut(self.input_offset + i) = s * (1 - s);
*pb.tape.get_unchecked_mut(self.input_offset + i) = s * (1.0 - s);
} else {
let s = 1 / (1 + f32::pow(e, -x));
let s = 1.0 / (1.0 + f32::powf(e, -x));
*pb.tape.get_unchecked_mut(self.output_offset + i) = s;
*pb.tape.get_unchecked_mut(self.input_offset + i) = s * (1 - s);
*pb.tape.get_unchecked_mut(self.input_offset + i) = s * (1.0 - s);
}
}

Expand All @@ -116,7 +116,7 @@ impl BlockTrait for BlockSigmoid
unsafe {
for i in 0..self.num_inputs as usize {
let x = *pb.tape.get_unchecked_mut(self.input_offset + i);
*pb.tape.get_unchecked_mut(self.output_offset + i) = 1 / (1 + f32::pow(e, -x));
*pb.tape.get_unchecked_mut(self.output_offset + i) = 1.0 / (1.0 + f32::powf(e, -x));
}
block_helpers::forward(further_blocks, fb, pb);
} // unsafe end
Expand Down
2 changes: 1 addition & 1 deletion src/block_tanh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl BlockTrait for BlockTanh
// we can try to replace with a lookup table
let t = tanhf(x);
*pb.tape.get_unchecked_mut(self.output_offset + i) = t;
*pb.tape.get_unchecked_mut(self.input_offset + i) = 1 - t*t; // derivative
*pb.tape.get_unchecked_mut(self.input_offset + i) = 1. - t*t; // derivative
}

block_helpers::forward_backward(further_blocks, fb, pb, update);
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ mod port_buffer;
mod block_neural;
mod block_misc;
mod block_relu;
mod block_leaky_relu;
mod block_tanh;
mod block_sigmoid;
mod block_normalize;
mod graph;

Expand Down
2 changes: 1 addition & 1 deletion src/regressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Regressor {
println!("Tanh layer");
},
NNActivation::Sigmoid => {
output = block_tanh::new_sigmoid_block(&mut bg, &mi, output).unwrap();
output = block_sigmoid::new_sigmoid_block(&mut bg, &mi, output).unwrap();
println!("Sigmoid layer");
}
}
Expand Down

0 comments on commit 5f085f4

Please sign in to comment.