Conversation
Reported-by: Zach Atkins <zach.atkins@colorado.edu> Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org>
|
This looks pretty good. The test is a rather different style than what we usually use, so I'll have some comments for you there soon. Let me know if you have questions as you keep working! |
jeremylt
left a comment
There was a problem hiding this comment.
The bulk of this outside of t129-vector.c looks really good. Lemmie cook up a separate comment about what exactly I would do for the test though
|
Ok, here is what I would do for the tests. You should think of the tests as an extension of the documentation. To that end, they should all have a similar look/feel so that it is easier for people to review the tests and see how specific functions work. So, I would start with an existing test instead of making a brand new one. Let's start with /// @file
/// Test scaling a vector
/// \test Test scaling of a vector
//TESTARGS(name="length 10") {ceed_resource} 10
//TESTARGS(name="length 0") {ceed_resource} 0
#include <ceed.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
Ceed ceed;
CeedVector x;
CeedInt len = 10;
CeedInit(argv[1], &ceed);
len = argc > 2 ? atoi(argv[2]) : len;
CeedVectorCreate(ceed, len, &x);
{
CeedScalar array[len];
for (CeedInt i = 0; i < len; i++) array[i] = 10 + i;
CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, array);
}
{
// Sync memtype to device for GPU backends
CeedMemType type = CEED_MEM_HOST;
CeedGetPreferredMemType(ceed, &type);
CeedVectorSyncArray(x, type);
}
CeedVectorScale(x, -0.5);
{
const CeedScalar *read_array;
CeedVectorGetArrayRead(x, CEED_MEM_HOST, &read_array);
for (CeedInt i = 0; i < len; i++) {
if (fabs(read_array[i] + (10.0 + i) / 2) > 1e-14) {
// LCOV_EXCL_START
printf("Error in alpha x at index %" CeedInt_FMT ", computed: %f actual: %f\n", i, read_array[i], -(10.0 + i) / 2);
// LCOV_EXCL_STOP
}
}
CeedVectorRestoreArrayRead(x, &read_array);
}
CeedVectorDestroy(&x);
CeedDestroy(&ceed);
return 0;
}I like to consider the edge cases here. Two come to mind immediately
The test file
So that should guide our modification of this code to make a test for If we change for (CeedInt i = 0; i < len; i++) array[i] = 10 + i;into a different pattern, then we can build array contents that hit our edge case concerns. I would then replace the I would then replace the logic following It may be worth doing this twice, the second time with a bigger value of Does that all make sense? |
Small documentation formatting change. Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org>
Use CeedCall for call to backend implementation. Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org>
Add empty line to end of file. Co-authored-by: Jeremy L Thompson <jeremy@jeremylt.org>
|
Thanks, Jeremey! I think that's all making sense. Ah, it makes sense how you are explaining the tests in general. I should have asked about the test for the Scale function. Are you thinking of just making one vector and changing the threshold for the different test cases? |
|
Yeah, that is how I would do it. I don't see a reason why the vector itself would make a big difference, unless its of a special length (length 0 specifically). CI has given the following style fix: index 4abc4d6..d829c7a 100644
--- a/interface/ceed-vector.c
+++ b/interface/ceed-vector.c
@@ -789,8 +789,7 @@ int CeedVectorFilter(CeedVector x, CeedScalar threshold) {
// Default implementation
CeedCall(CeedVectorGetArray(x, CEED_MEM_HOST, &x_array));
assert(x_array);
- CeedPragmaSIMD
- for (CeedSize i = 0; i < length; i++) {
+ CeedPragmaSIMD for (CeedSize i = 0; i < length; i++) {
if (fabs(x_array[i]) <= threshold) x_array[i] = 0.0;
}
CeedCall(CeedVectorRestoreArray(x, &x_array)); |
Purpose:
Add CeedVectorFilter function to filter or clip a CeedVector using a threshold value. Vector entries with absolute value less than
thresholdare clipped to0.0.This may be considered a WIP pull request.
Default implementation of the function and a test, t129-vector.c, are implemented.
GPU backends have NOT been implemented yet.
Addresses Issue #1830
LLM/GenAI Disclosure: Google AI mode was used to check syntax for the function, and its suggestion to use the
CeedPragmaSIMDmacro was adopted. Google AI mode was used to write piece of the test for this function,t129-vector.cBy submitting this PR, the author certifies to its contents as described by the Developer's Certificate of Origin.
Please follow the Contributing Guidelines for all PRs.