Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

##Some Points

Some Points

##Some Thoughts

Some Thoughts

##Code Review

Code Review

###Matrix definitions

Matrix definitions

##Some Points

##Some Thoughts

##Code Review

###Matrix definitions

Some Points

Some Thoughts

Code Review

Matrix definitions

deleted 6 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
 template<typename ...Targs>
 Vector(TargsTargs&&..&&. args): mField({std::forward<Targs>(args)...}){}
 Vector& operator+=(Vector const& vec) const
 {
 for (auto i = 1; i <= Dimension; ++i)
 (*this)[i] += vec[i];
 return *this;
 }
 Vector operator+(Vector const& vec) const
 {
 Vector temp(*this);
 return temp += vec;
 }
 template<typename ...Targs>
 Vector(Targs..&&. args): mField({std::forward<Targs>(args)...}){}
 Vector& operator+=(Vector const& vec) const
 {
 for (auto i = 1; i <= Dimension; ++i)
 (*this)[i] += vec[i];
 return *this;
 }
 Vector operator+(Vector const& vec) const
 {
 Vector temp(*this);
 return temp += vec;
 }
 template<typename ...Targs>
 Vector(Targs&&... args): mField({std::forward<Targs>(args)...}){}
 Vector& operator+=(Vector const& vec)
 {
 for (auto i = 1; i <= Dimension; ++i)
 (*this)[i] += vec[i];
 return *this;
 }
 Vector operator+(Vector const& vec) const
 {
 Vector temp(*this);
 return temp += vec;
 }
added 1442 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

Example:

 {
 Matrix<4,5> x(init);
 Matrix<4,5> y(init);
 Matrix<4,5> z = x + y; // Here the + operator
 // Can loop over all the elements
 // and do the operation for each element.
 std::cout << z[1][1] << "\n"; // Here we use only one value
 } // Then z goes out of scope and is destroyed.
 // So we just did a bunch of operations
 // that are not needed.
// If at the point where we did the operation + we returned an
// object that knows about x and y but did not immediately do the operation
// Then we accesses element [1][1] we see the work has not been done
// and just do the operation for that location. We don't work out all
// the elements just the one we want and only when we need it.
// That is a deferred operation.

Example 2:

 Matrix<4,5> a(init);
 Matrix<5,3> b(init);
 Matrix<4,3> c = a * b;
 Matrix<4,3> d = c;
 Matrix<4,3> e = c - d;

In this example we can see that all elements of e will be zero. So calculating the value of c first is a waste of time. By deferring calculations of the elements we can sometimes determine the result without having to do all the expensive operations.

So at run-time you can perform operations that cancel out other operations and thus you do not need to perform expensive operations if there results do not generate a value that effects the result.

##Code Review

##Code Review

Example:

 {
 Matrix<4,5> x(init);
 Matrix<4,5> y(init);
 Matrix<4,5> z = x + y; // Here the + operator
 // Can loop over all the elements
 // and do the operation for each element.
 std::cout << z[1][1] << "\n"; // Here we use only one value
 } // Then z goes out of scope and is destroyed.
 // So we just did a bunch of operations
 // that are not needed.
// If at the point where we did the operation + we returned an
// object that knows about x and y but did not immediately do the operation
// Then we accesses element [1][1] we see the work has not been done
// and just do the operation for that location. We don't work out all
// the elements just the one we want and only when we need it.
// That is a deferred operation.

Example 2:

 Matrix<4,5> a(init);
 Matrix<5,3> b(init);
 Matrix<4,3> c = a * b;
 Matrix<4,3> d = c;
 Matrix<4,3> e = c - d;

In this example we can see that all elements of e will be zero. So calculating the value of c first is a waste of time. By deferring calculations of the elements we can sometimes determine the result without having to do all the expensive operations.

So at run-time you can perform operations that cancel out other operations and thus you do not need to perform expensive operations if there results do not generate a value that effects the result.

##Code Review

Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
lang-cpp

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