##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
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;
}
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