-
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
Transform points op #2288
Transform points op #2288
Conversation
01cfc50
to
3cf0a9c
Compare
DALI_SCHEMA(CoordTransform) | ||
.DocStr(R"(Applies a linear transformation to points or vectors. | ||
|
||
|
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 this bank is redundant.
) // NOLINT | ||
) // NOLINT | ||
), ( // NOLINT | ||
DALI_FAIL(make_string("Unsupported input point dimensionality: ", input_pt_dim_)); |
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.
DALI_FAIL(make_string("Unsupported input point dimensionality: ", input_pt_dim_)); | |
DALI_FAIL(make_string("Unsupported output point dimensionality: ", input_pt_dim_)); |
FillDiag(make_span(&per_sample_mtx_[i * mat_size], mat_size), M.data[i][0]); | ||
} | ||
translation_.resize(output_pt_dim_, 0); | ||
Repeat(per_sample_translation_, translation_, N); |
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 add a comment why the if (is_fused)
is not relevant here?
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.
It's doesn't change anything, but it should be here to avoid a redundant operation.
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 know, but for consistency I would leave at least a comment that it is skipped on purpose here.
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.
What I meant is: the if
should be here. I added it.
!build |
CI MESSAGE: [1642398]: BUILD STARTED |
CI MESSAGE: [1642398]: BUILD PASSED |
true) | ||
.AddOptionalArg<vector<float>>("T", R"(The translation vector. | ||
|
||
If left unspecified, no translation is applied. |
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 not necessarily true. You can still specify translation with MT
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.
Will adjust.
translation_.resize(output_pt_dim_, 0); | ||
} | ||
} else { | ||
DALI_ENFORCE(mtx_.size() % cols == 0, make_string("Cannot form a matrix ", |
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.
DALI_ENFORCE(mtx_.size() % cols == 0, make_string("Cannot form a matrix ", | |
DALI_ENFORCE(mtx_.size() % cols == 0, make_string("Cannot form a matrix with ", |
} | ||
|
||
|
||
vector<float> mtx_; |
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.
do you need those to be public?
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.
In the following scenarios it might be useful:
- If this class is used by composition instead of inheritance.
- ...or the derived class has pImpl.
!build |
CI MESSAGE: [1645356]: BUILD STARTED |
CI MESSAGE: [1645356]: BUILD FAILED |
bf9725f
to
9eb20fb
Compare
!build |
CI MESSAGE: [1646310]: BUILD STARTED |
CI MESSAGE: [1646310]: BUILD FAILED |
CI MESSAGE: [1646310]: BUILD PASSED |
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.
Main points:
- I think there is no check for degenerate argument of empty list, it will probably go through codepath for non-scalar argument provided.
- repeating the obtaining and copying of regular argument in every iteration
- ProcessMatrixArg is a bit long and hard to follow with the ifs, but isn't that bad.
- some naming/typos.
|
||
namespace dali { | ||
|
||
#define COORD_TRANSFORM_INPUT_TYPES (uint8_t, int16_t, uint16_t, int32_t, float) |
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.
What's the reason for this particular subset of types?
This is only a side comment, but if adding more types usually becomes expensive, maybe we need to look into that.
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.
We need to limit the number of types, because the dimensionality is handled at compile-time and we already have 36 combinations there.
This set of types will allow us to process:
- colors (uint8, uint16)
- audio (int16, int32)
- geometry (float)
If left unspecified, identity matrix is used. | ||
|
||
The matrix ``M`` does not need to be square - if it's not, the output vectors will have a | ||
different number of components. |
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.
Maybe add that it will be different than the input
if we need to be really verbose. It sounds a bit like each of them can have a different number of components.
|
||
If left unspecified, no translation is applied unless MT argument is used. | ||
|
||
The number of components of this vector must match the number of rows in matrix ``M``. |
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.
If we provide the matrix M as a flattened list of values, there isn't exactly a good notion of rows. Should we specify that the matrix should be provided as flattened row-major matrix?
(Ideally we would be able to accept anything array like with additional shape, but that would be a bit over the top in this PR).
translation_.resize(output_pt_dim_, 0); | ||
} | ||
} else { | ||
DALI_ENFORCE(mtx_.size() % cols == 0, make_string("Cannot form a matrix with ", |
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.
What if mtx_.size() == 0?
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.
Then we end up with empty output. It will raise a meaningful error later, when selecting the kernel.
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.
Handled explicitly.
if (mtx_.size() == 1) { | ||
SetOutputPtDim(input_pt_dim_); | ||
mtx_.resize(output_pt_dim_ * input_pt_dim_); | ||
FillDiag(mtx_, mtx_[0]); |
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.
FillDiag sounds like filling only the diagonal, maybe something like MakeDiagonalMat
?
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.
Done.
if (is_fused) | ||
translation_.clear(); | ||
|
||
if (HasMatrixRegularArg()) { |
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 will repeat the Regular arguments every iteration even though they do not change between them.
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 deliberate. I assume that at some point we'll allow the values of scalar arguments to change. Not that it would be very useful for this particular operator, but for random number generators, for example, it would have some merit.
} else if (HasMatrixInputArg()) { | ||
const auto &M_inp = ws.ArgumentInput(name); | ||
auto M = view<const float>(M_inp); | ||
DALI_ENFORCE(is_uniform(M.shape), "Matrices for all samples int the batch must have " |
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.
DALI_ENFORCE(is_uniform(M.shape), "Matrices for all samples int the batch must have " | |
DALI_ENFORCE(is_uniform(M.shape), "Matrices for all samples in the batch must have " |
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.
:)
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.
Happens to me all the time :P
Repeat(per_sample_mtx_, mtx_, N); | ||
if (is_fused) | ||
Repeat(per_sample_translation_, translation_, N); | ||
} else if (HasMatrixInputArg()) { |
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 feel like handling InputArg and regular arg could be two separate functions - this one is a tad long, I have to keep track of the if-nesting.
9a237dd
to
38c9152
Compare
@@ -100,13 +100,13 @@ def _run_test(device, batch_size, out_dim, in_dim, in_dtype, out_dtype, M_kind, | |||
Y = Y.clip(info.min, info.max) | |||
|
|||
ref.append(Y) | |||
scale = max(scale, np.max(np.abs(Y)) - np.min(np.abs(Y))) | |||
scale = max(scale, np.max(np.abs(Y)) - np.min(np.abs(Y))) if Y.size > 0 else 1 |
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 crashed for empty input
da6242f
to
9e6c2af
Compare
!build |
CI MESSAGE: [1648586]: BUILD STARTED |
CI MESSAGE: [1648586]: BUILD FAILED |
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Added tests form MTTransformAttr. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
* Adjust documentation for argument M. * Throw an error if M is empty. * Fix typo. * Check type in SetupImpl. * Improve error message for unsupported type. * Short-circuit if input is empty. * Move layout setting to backend-agnostic part. * Add tests for empty input. * Test layouts. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
9e6c2af
to
c5f761a
Compare
R"code(Transforms coordinates so that they are flipped (point reflected) with respect | ||
to a center point.)code") | ||
R"code(Transforms vectors or points by flipping (reflecting) their coordinates with | ||
respect to a given center.)code") |
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.
We're not reflecting with respect to a point - we're reflecting with respect to multiple subspaces.
!build |
CI MESSAGE: [1650835]: BUILD STARTED |
CI MESSAGE: [1650835]: BUILD FAILED |
CI MESSAGE: [1650835]: BUILD PASSED |
Why we need this PR?
What happened in this PR?
Fill relevant points, put NA otherwise. Replace anything inside []
JIRA TASK: DALI-1482, DALI-1605