Skip to main content
Code Review

Return to Revisions

2 of 3
added 790 characters in body
JDługosz
  • 11.7k
  • 19
  • 40
for (int j = 0; j < width; j++) {
 elements[i].emplace_back(0.0f);

Instead of writing a loop, use the constructor form to create a vector of the desired length; all elements will be initialized to zero automatically.

for (int i = 0; i < dest.width; i++)
 for (int j = 0; j < dest.height; j++)
 dest.set_element(i, j, t_elements[i][j]);
}

Calling set_element on every element to copy the results — Copy the elements in the order in which they appear in the row, and use an iterator to place them efficiently.

for (int k = 0; k < left.width; k++)
 elementVal += (left.get_element(k, i) * right.get_element(j, k));

Likewise for the get_element function, called repeatedly for every output value. For the inner dimension, just use iterator increment to advance to the next value.

Here is the way we did raster graphics in the old days: Don’t make a vector of vectors. Make a single vector, and an access function that multiplies the row by the row size and adds the column to produce a single index.

Now, given a pointer to any cell, you can efficiently move to the next in any direction. Going right, increment by one. Going down, increment by the row size. So trace through the source matrices this way, one going right, one going down.

JDługosz
  • 11.7k
  • 19
  • 40
default

AltStyle によって変換されたページ (->オリジナル) /