# Assignment: basic linear algebra operations

Download this crate for the second homework assignment. It contains some tests, benchmarks, and function prototypes. Since we are still covering basic Rust concepts, we still focus on small and simple functions.

## 1 Dot product

### 1.1 Implement `dot`

The dot product is used extensively in machine learning and is defined as:

Implement the dot product in `src/dot.rs`

. The following function signature is given:

```
pub fn dot(u: &[f32], v: &[f32]) -> f32;
```

There are several ways to implement the dot product in Rust. For this assignment, try to stick to the C implementation in the first slide deck as closely as possible.

You can test your implementation with `cargo test dot_test`

. There is also a benchmark that will compute the dot product of two random vectors of 500 components. You can run the benchmark with `rustup run nightly cargo bench dot_bench`

.

# 2 Element-wise product

The element-wise product (also called *Hadamard product* for matrices) computes a new vector consisting of the pairwise multiplications of two vectors. That is, the elementwise product is computed as:

### 2.1 Implement the element-wise product

Implement the element-wise product in `src/mul.rs`

as a function with the signature

```
pub fn mul(u: &[f32], v: &[f32]) -> Vec<f32>
```

which:

- Takes references to the vectors and ;
- constructs a new
`Vec`

with the element-wise product; and - moves the new
`Vec`

to the caller.

There is a simple test for the implementation that you can run with `cargo test mul_test`

.

### 2.2 Implement an in-place version of the element-wise product

Implement the element-wise product in `src/mul.rs`

as a function with the signature

```
pub fn mul_inplace(u: &mut [f32], v: &[f32])
```

This function should **not** return a new vector, but instead update , so that it contains the element-wise product after calling this function.

There is a simple test for the implementation that you can run with `cargo test mul_inplace_test`

.

### 2.3 Compare the running times of the implementation

A benchmark is provided for `mul`

and `mul_inplace`

. Run `cargo bench`

to compare the running times for the implementations. Which implementation is faster? Try to explain the result.

## Submission

- Submit your updated project, archived as a
`tar.gz`

or`zip`

file. - Include the first names of the team members in the archive name.
- Run
`cargo clean`

before archiving the project. - Your answers to 2.3 must be included as a
**plain text file**(not PDF, Word, etc.) in the main project directory.

The `tar.gz`

or `zip`

file should be uploaded through this page. The deadline is May 3 at 13:00.