-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I added tests to core/impl/tensor_impl.hpp #3
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first PR!!
Tensor<T> t1(s1); | ||
|
||
REQUIRE(t1.shape == s1); | ||
REQUIRE(t1.data == AlignedPtr<T>(s1.total())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the content of the pointer is guaranteed to match between allocations. It would be better to test that the length of data == s1.total()
TEST_CASE_TEMPLATE("Tensor(Shape&, PtrType&)", T, test_data_types) | ||
{ | ||
Shape s1; | ||
AlignedPtr<T> ptr1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an empty pointer and empty shape. The test would be better if you set the shape and filled the pointer with some values. For example-
Shape s1 = Shape{2, 2};
AlignedPtr<T> ptr1 = {1, 2, 3, 4};
Then you can explicitly test if tensor shape == {2, 2} and aligned ptr data = {1, 2, 3, 4}
…al projection function that returns vector projected onto line L spanned by vector s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new methods are really cool!
inline Tensor<DataType> gaussian_elim(Tensor<DataType>& T1) | ||
{ | ||
static_assert(std::is_floating_point<DataType>::value, | ||
"eigenvalues() requires signed data"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to change eigenvalues() :)
} | ||
|
||
template <typename DataType> | ||
inline Tensor<DataType> gaussian_elim(Tensor<DataType>& T1, Tensor<DataType>& V1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add documentation for the 2 tensor case
TNT_ASSERT(T1.shape.num_axes() == 2, InvalidParameterException("tnt::gaussian_elim()", | ||
__FILE__, __LINE__, "Gaussian elimination requires 2D tensors")) | ||
|
||
return detail::OptimizedGaussianElimination<DataType>::eval(T1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
} | ||
|
||
if (ptr[lead] == 1) { | ||
clearColumn(ptr, i, (lead - (num_cols * i)), num_rows, num_cols, vct); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nitpicky but I like functions to be lowercase_underscore instead of camel case
|
||
static void divideVector(DataType* vct, int row, DataType value) | ||
{ | ||
vct[row] = vct[row] - value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that vct is updated in place? Meaning if I pass in 2 tensors should I expect both to change?
DataType* s = V2.data.data; | ||
int num_rows = V1.shape.axes[ROW_INDEX]; | ||
|
||
scalar_multiply(s, (dotProduct(v, s, num_rows) / dotProduct(s, s, num_rows)), num_rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just do V2 * dotProduct(...). Scalar multiplication is a method for tensors and should be faster then your version (it uses SIMD)
template <typename DataType, typename Enable = void> | ||
struct OptimizedOrthogonalProjection | ||
{ | ||
static Tensor<DataType> eval(const Tensor<DataType>&, const Tensor<DataType>&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inputs are const
here but not in your *_impl.hpp file. I think they should be const in both places
/// \requires V1 and V2 shall be one dimensional | ||
|
||
template <typename DataType> | ||
inline Tensor<DataType> project(Tensor<DataType>& V1, Tensor<DataType> V2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the inputs should be const here as well
No description provided.