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
move scale to linalg #2744
move scale to linalg #2744
Conversation
@@ -1023,7 +1024,7 @@ SGVector<float64_t> CQuadraticTimeMMD::sample_null_spectrum_DEPRECATED( | |||
|
|||
/* when m=n, return m*MMD^2 instead */ | |||
if (m==n) | |||
null_samples.scale(0.5); | |||
linalg::scale(null_samples, null_samples, 0.5); |
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.
hey
just curious, can't there be a convenience method for the case where both arugments are the same?
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.
hi,
We'll have to add a simple method. I'll add it.
@karlnapf please take a look. |
{ | ||
for (int32_t i=0; i<A.vlen; i++) | ||
B[i]=A[i]*alpha; | ||
} |
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.
Some indentation issue is there.
Hi @SunilMahendrakar. Sorry for such a late reply. Have been caught up with something. The PR looks good. I have some comments and it would be great if you could please address those - shouldn't take more than 5 mins. I know GSoC is not happening for us this summer which is depressing, but it would be great if we can finish at least those things that we started. Looking forward to it. |
@lambday Sure!. GSoC would have been great but I'll be contributing anyways. |
That's really nice to hear :) Looking forward. |
@lambday done :) please take a look. |
B[i]=A[i]*alpha; | ||
} | ||
}; | ||
|
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.
@SunilMahendrakar well what I meant here was to have an additional method that just takes raw pointer types and the length of the consecutive memory array.
static void compute(T* A, T* B, index_t len, T alpha)
{
// REQUIRE on null check for both A and B
// the loop goes here
}
So you write the loop there just once and make the SGMatrix and SGVector ones to call that method instead. That way, we'll be able to handle handle raw arrays as well (we can later simply add another wrapper which calls that with NATIVE backend). See what I mean?
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.
@lambday yeah. so that we just have a REQUIRE there which calls this method to perform the actual computation.
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.
Yeah. Keep the other requires there - they are useful. The null check REQUIRE is useful when people (hopefully mistakenly) pass scale(NULL, 1000, 0.5) in the raw ptr method.
Hi @SunilMahendrakar . This looks good. Just see my other comment. A couple of other things I forgot to mention
|
@lambday thanks for the explanation. :) |
@lambday it would be better if we first work towards removing HAVE_CXX11 first then move the calls to linalg, since if we want to prevent compilation failures we would have to add the guard all over the place starting from where we use it, i.e for things dependent on the method where we use it and we have 30-40 scale calls alone. Its easy for outermost methods like unit tests. Since we are going to lose it anyway lets start working towards losing it. |
@SunilMahendrakar that totally makes sense. We want the build to fail in cmake itself in absence of c++11. However, until that happens, I'd suggest that replacing everything with linalg calls can be done later, in separate patches. As of now, we'd be fine just adding it to linalg and having unit-tests. So don't replace everything yet - let's first get native scale merged. |
Please rebase. |
@lambday done please take a look. |
static void compute(SGMatrix<T> A, SGMatrix<T> B, T alpha) | ||
{ | ||
REQUIRE((A.num_rows==B.num_rows)&&(A.num_cols==B.num_cols), | ||
"Dimensions of A(%dx%d) and B(%dx%d) don't match.\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.
I think we can skip the \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.
@iglesias I personally like the \n
in the end - as per our wiki on Assertions -
- Use proper English (Start with capital letters, write sentences)
- Don't forget
\n
at the end. - Make sure that you don't cause segfaults in your assertions, check bounds, pointer valid, etc
Although it is just a matter of choice.
It looks good to me, just very minor comments above. @lambday, ready to merge? |
for (int32_t i=0; i<9; i++) | ||
EXPECT_NEAR(alpha*A[i], B[i], 1e-15); | ||
} | ||
|
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.
@SunilMahendrakar could you please add a couple of these tests (one on SGMatrix and another on SGVector) that does the scale operation in place? This way, linalg::scale(A, alpha)
is also tested.
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.
Actually, it makes sense to have unit tests for in place scale operation for all the backends - since we are exposing it for all of 'em.
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.
sure!
@SunilMahendrakar great job! Thanks for the patch :) Merging. If you could please add two more unit-tests that I mentioned, we can consider the matter close :) |
@lambday buildbots are going crazy. test failing unrelated? |
@SunilMahendrakar yeah |
towards #2717. Everything is not yet replaced.