Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl<T: Add<Output=T> + Mul<Output=T> + Clone + Zero> SparseVec<T> {
- pub fn zeros(length: usize) -> SparseVec<T> {
- SparseVec {
- length: length,
- data: BTreeMap::new()
- }
- }
- pub fn set(&mut self, index: usize, value: T) {
- self.data.insert(index, value);
- }
- pub fn dot(self, rhs: &SparseVec<T>) -> T {
- self.data.into_iter().map(|(k, v)| {
- match rhs.data.get(&k) {
- Some(r) => r.clone() * v,
- None => Zero::zero()
- }
- }).sum()
- }
- pub fn norm(self) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement