Lesson 8 (2019) discussion & wiki

If we are doing matmul then shouldn’t we be using Strassen’s algorithm?

1 Like

Is there a way to just get the items out of the map object without assigning them? Say I just want to print the value of items

1 Like

O(N^2.8)

1 Like

The goal is to explain it in a very simple way for now.
Also, to complete my answer, I’m not entirely sure Strassen’s algorithm can be fully parallelized (which is what we do in GPU).

4 Likes

You can write a foreach on the generator and print each elements.

1 Like

I believe that map object behaves like an iterator, and doesn’t provide a random-access interface. Therefore, you can only consume one item after another, as you do with streams.

1 Like

But you can wrap it in list, like:

list(map(tensor, (x_train,y_train,x_valid,y_valid)))

if you really want a true list

2 Likes

Are we going to learn how it is implemented on a GPU efficiently?

Or more pythonic:

[tensor(data) for data in (x_train,y_train,x_valid,y_valid)]
5 Likes

Yeah, essentially list is doing it for you: it consumes everything up to the end of the iterator. Note that it could take some time and occupy memory if you have a really long sequence. Like, if you only need to go through the items one time, it is probably better to keep it an iterator.

2 Likes

Wouldn’t a non-vectorized implementation of matrix multiplication be slow in any language, even C? Is Python really the reason this matmul is slow, or just that it is non-vectorized?

2 Likes

To be clear, this * in the code for the Frobenius norm is the element-wise multiplication right, not the matrix multiplication ?

What does the operations on your vectors once it’s vectorized? Python is faster when you vectorize things because you fall in C code written for numpy.

2 Likes

Always liked maps instead of for loops for doing something over a data structure like a list.

1 Like

Yes, matrix multiplication is @

3 Likes

Not nearly as slow as it is in Python.

Agree, I like “functional” tricks in Python as well :smile: Though sometimes the code becomes less clear if you have too many of them.

1 Like

Shouldn’t one of the m be m.transpose()?

It’s elementwise matrix multiplication.

1 Like

I think Numpy is fast because it is taking advantage of SIMD (single instruction, multiple data), not just because it is in C. But I know very little about Numpy internals.

2 Likes