You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2022/10/18 06:07:27 UTC

[GitHub] [lucenenet] nikcio opened a new pull request, #693: chore: Added suppression attributes to CA1822

nikcio opened a new pull request, #693:
URL: https://github.com/apache/lucenenet/pull/693

   Following #690 I've now added suppression attributes to the methods we decided not to make static.
   
   Adds to #663 
   
   I also had another look at [This issue](https://sonarcloud.io/project/issues?issues=AYPAuN5xhbfJOGLOoaDV&open=AYPAuN5xhbfJOGLOoaDV&id=nikcio_lucenenet) and found that the reason this caused problems is because I forgot to change the `this.` to `BasicModelBE.` in the `Score` method. But I don't know if this is moving too far away from the original code?
   
   The change would be:
   
   ```csharp
   public override sealed float Score(BasicStats stats, float tfn)
   {
       double F = stats.TotalTermFreq + 1 + tfn;
       // approximation only holds true when F << N, so we use N += F
       double N = F + stats.NumberOfDocuments;
       return (float)(-SimilarityBase.Log2((N - 1) * Math.E) + BasicModelBE.F(N + F - 1, N + F - tfn - 2) - BasicModelBE.F(F, F - tfn));
   }
   /// <summary>
   /// The <em>f</em> helper function defined for <em>B<sub>E</sub></em>. </summary>
   private static double F(double n, double m) // LUCENENET: CA1822: Mark members as static
   {
       return (m + 0.5) * SimilarityBase.Log2(n / m) + (n - m) * SimilarityBase.Log2(n);
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] NightOwl888 commented on pull request #693: chore: Added suppression attributes to CA1822

Posted by GitBox <gi...@apache.org>.
NightOwl888 commented on PR #693:
URL: https://github.com/apache/lucenenet/pull/693#issuecomment-1282104390

   > I also had another look at [This issue](https://sonarcloud.io/project/issues?issues=AYPAuN5xhbfJOGLOoaDV&open=AYPAuN5xhbfJOGLOoaDV&id=nikcio_lucenenet) and found that the reason this caused problems is because I forgot to change the `this.` to `BasicModelBE.` in the `Score` method. But I don't know if this is moving too far away from the original code?
   > 
   > The change would be:
   > 
   > ```cs
   > public override sealed float Score(BasicStats stats, float tfn)
   > {
   >     double F = stats.TotalTermFreq + 1 + tfn;
   >     // approximation only holds true when F << N, so we use N += F
   >     double N = F + stats.NumberOfDocuments;
   >     return (float)(-SimilarityBase.Log2((N - 1) * Math.E) + BasicModelBE.F(N + F - 1, N + F - tfn - 2) - BasicModelBE.F(F, F - tfn));
   > }
   > /// <summary>
   > /// The <em>f</em> helper function defined for <em>B<sub>E</sub></em>. </summary>
   > private static double F(double n, double m) // LUCENENET: CA1822: Mark members as static
   > {
   >     return (m + 0.5) * SimilarityBase.Log2(n / m) + (n - m) * SimilarityBase.Log2(n);
   > }
   > ```
   
   ```java
    
     /** The <em>f</em> helper function defined for <em>B<sub>E</sub></em>. */
     private final double f(double n, double m) {
       return (m + 0.5) * log2(n / m) + (n - m) * log2(n);
     }
   ```
   
   In the original code the function `f` was lowercase. I first thought that forced them to use uppercase `F` as a varible name. But, judging by the documentation and comments, the capital F variable name seems to be a math thing, and therefore intentional.
   
   Let's revert this and add the `SuppressMessage` attribute.
   
   We should also add the `[MethodImpl(MethodImplOptions.AggressiveInlining)]` attribute to prompt the compiler to inline this math in the `Score` function, which will give a similar benefit to making the method static.
   
   I have also opened #694 which is related, but should be done in a separate PR since it goes beyond this one class.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] nikcio commented on pull request #693: chore: Added suppression attributes to CA1822

Posted by GitBox <gi...@apache.org>.
nikcio commented on PR #693:
URL: https://github.com/apache/lucenenet/pull/693#issuecomment-1285194318

   The PR has now been updated after the comment above


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] NightOwl888 merged pull request #693: chore: Added suppression attributes to CA1822

Posted by GitBox <gi...@apache.org>.
NightOwl888 merged PR #693:
URL: https://github.com/apache/lucenenet/pull/693


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org