-
Notifications
You must be signed in to change notification settings - Fork 621
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
Linear Transformation kernel for CPU #1300
Conversation
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
include/dali/core/geom/mat.h
Outdated
template <int rows, int cols, typename T = float> | ||
DALI_HOST_DEV constexpr dali::mat<rows, cols, T> eye() { | ||
mat<rows, cols, T> ret(0); | ||
for (int i = 0; i < rows && i < cols; i++) { | ||
ret(i, i) = 1; | ||
} | ||
return ret; | ||
} | ||
|
||
|
||
template <int N, typename T = float> | ||
DALI_HOST_DEV constexpr dali::mat<N, N, T> eye() { | ||
return eye<N, N, T>(); | ||
} | ||
|
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.
These functions are redundant. Construction from scalar puts that scalar on the diagonal.
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 in my opinion baaaad. Is there any FW or library, that does the diagonal-initialization by the constructor? I'd rather expect the construtor to initialize all the matrix elements with given value (cf. OpenCV). I'd vote for chaning the behavoiur of the constructor, but not in this PR, since this change can create problems...
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.
That's what you have in OpenGL / shader programming.
Since matrices are usually used for multiplaction and vectors for addition, this gives consistent results:
mat3 A;
A * 5 == A * mat3(5);
vec4 v;
v + 5 = v + vec4(5);
|
||
template <int rows, int cols, typename T> | ||
std::ostream &operator<<(std::ostream &os, const dali::mat<rows, cols, T> &m) { | ||
for (int i = 0; i < rows; i++) { |
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.
Side-note: we'd certainly want a prettier printer for matrices, but it'll do for the sake of this PR.
dali/core/geom_mat_test.cu
Outdated
|
||
TEST(MatTest, identity_matrix) { | ||
mat3 three_by_three = {{ | ||
{1, 0, 0}, | ||
{0, 1, 0}, | ||
{0, 0, 1} | ||
}}; | ||
mat3x1 three_by_one = {{ | ||
{1},{0},{0} // NOLINT | ||
}}; | ||
mat3x2 three_by_two = {{ | ||
{1, 0}, | ||
{0, 1}, | ||
{0, 0}, | ||
}}; | ||
auto m1 = eye<3, int>(); | ||
auto m2 = eye<3, 1, int>(); | ||
auto m3 = eye<3, 2, int>(); | ||
EXPECT_EQ(m1, three_by_three); | ||
EXPECT_EQ(m2, three_by_one); | ||
EXPECT_EQ(m3, three_by_two); | ||
} | ||
|
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.
Redundant!
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.
Remove "eye" functions.
Use roi.hi instead lo+extent.
I don't really agree, that
Note: I have no idea, if you can do Clearly, more common approach is the OpenCV-like, i.e. constructor generates matrix with all elements set to given value. It gives consistency between matrix-type and vector-type (GLSL doesn't contain such ctor for vector). Therefore in my opinion, our mat constructor should follow OpenCV approach. Getting back to the Lastly, how does it hurt? |
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
!build |
CI MESSAGE: [930370]: BUILD STARTED |
CI MESSAGE: [930370]: BUILD FAILED |
!build |
CI MESSAGE: [930398]: BUILD STARTED |
CI MESSAGE: [930398]: BUILD FAILED |
!build |
CI MESSAGE: [930529]: BUILD STARTED |
CI MESSAGE: [930529]: BUILD PASSED |
Why we need this PR?
Because we have LinearTransformationGpu kernel. That's for consistency