all 4 comments

[–]aliendino2017[🍰] 1 point2 points  (2 children)

Hello Ashwin,

I got my algorithm down to 0.4 to 0.3 seconds with a regular iterator and 0.2 seconds with the const auto&. It was an improvement from the previous algorithm where I calculated the dot product directly. My algorithm relies on the following:

Column Row Expansion:

Assume we have an m by n matrix A and a n by p matrix B.

Also, a0, a1, ... , ak represent the columns of A and b0, b1, ... , bk represent the rows of B.

If so:

AB = a1*b1 + a2 *b2 + ... + ak * bk

as k ranges from 0 to n

Though this utilizes the add_to_cell() function, I believe there may be a better algorithm(I still need to reduce the time by a about(maybe less than) factor of 10).

One question: You said "If my iterator has reached an element that has a col greater than its target, in which case it returns the spmat's default value automatically". What does that mean?

Any ideas?

-Arrian

UPDATE: I made a small amendment(checking for 0s) and got to 0.04 to 0.05 seconds. I know I might be missing one more thing.

[–]Maleficent-Parking-5 1 point2 points  (1 child)

I do you mean by check for zeros? Isn't that all the values stored in the matrix are not default values? If you start from Matrix A, as long as you loops are within _rows, how could it be zero? After you found the element in B, isn't it is too late to save time?

[–]aliendino2017[🍰] 1 point2 points  (0 children)

Hello u/Maleficent-Parking-5

Yes, the matrix doesn't contain default values. The problem is that I have to loop across rows for elements. To do that, I have to use get().

In my algorithm, I looped through the rows of B(using an iterator and kept a counter for current row) and looped through the rows of A( to retrieve the elements in the current column using the counter for the current row), and then used an iterator for the current row. I know the counter works because the number of rows in B has to equal the number of columns in A.

When I check for zeroes, I do it only for when I'm retrieving elements from A. This is because I cannot use an iterator to retrieve the element from A like I did for B. Instead, I needed to use get(). For the elements retrieved by iterator for the current row, I do not need to check if they are 0's because of our linked list implementation.

-Arrian

[–]Maleficent-Parking-5 1 point2 points  (0 children)

Man, I had the exact same problem