Created
July 18, 2014 23:26
-
-
Save mjburgess/4d91ab576e681db2061e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mjburgess@mjb:guess$ cargo build | |
Compiling guess v0.1.0 (file:/home/mjburgess/src/rust/guess) | |
src/guess.rs:24:64: 24:73 error: cannot move out of dereference of `&`-pointer | |
src/guess.rs:24 Vec::from_fn(weights.len(), |i| update(rate, *weights.get(i), xy.get(i).val0(), xy.get(i).val1() as int, *p.get(i))) | |
^~~~~~~~~ | |
src/guess.rs:24:82: 24:91 error: cannot move out of dereference of `&`-pointer | |
src/guess.rs:24 Vec::from_fn(weights.len(), |i| update(rate, *weights.get(i), xy.get(i).val0(), xy.get(i).val1() as int, *p.get(i))) | |
^~~~~~~~~ | |
error: aborting due to 2 previous errors | |
Could not execute process `rustc src/guess.rs --crate-name guess --crate-type bin --out-dir /home/mjburgess/src/rust/guess/target -L /home/mjburgess/src/rust/guess/target -L /home/mjburgess/src/rust/guess/target/deps` (status=101) |
This file contains hidden or 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
fn ages() -> Vec<(uint, uint)> { | |
vec![ | |
(10, 0), | |
(11, 0), | |
(12, 0), | |
(7, 0), | |
(18, 1), | |
(45, 1), | |
(22, 1), | |
(23, 1) | |
] | |
} | |
fn percept1D<T: Mul<T,T>>(w: T, x: T) -> T { | |
w * x | |
} | |
fn weights(inputLength: uint) -> Vec<uint> { | |
Vec::from_elem(inputLength, 0) | |
} | |
fn recalibrate<T: Mul<T, T>>(rate: int, weights: Vec<int>, p: Vec<int>, xy: Vec<(T, uint)>) -> Vec<int> { | |
Vec::from_fn(weights.len(), |i| update(rate, *weights.get(i), xy.get(i).val0(), xy.get(i).val1() as int, *p.get(i))) | |
} | |
fn update<T: Mul<T, T>>(rate: int, w: int, x: T, y: int, p: int) -> int { | |
rate * (y - p) | |
} | |
fn inputs<'a, T> (xy: &'a mut Vec<(T, uint)>, x :T) -> &'a mut Vec<(T, uint)> { | |
xy.unshift((x, 1)); | |
xy | |
} | |
fn main() { | |
let mut ages = ages(); | |
let xy = inputs(&mut ages, 0); | |
let w = weights(xy.len()); | |
println!("xy = {}", xy); | |
println!("w = {}", w); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment