You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/27 20:57:26 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #2957: Add BooleanArray::true_count and BooleanArray::false_count

tustvold opened a new pull request, #2957:
URL: https://github.com/apache/arrow-rs/pull/2957

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   https://github.com/apache/arrow-datafusion/pull/3989#discussion_r1007328633
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-rs] alamb commented on pull request #2957: Add BooleanArray::true_count and BooleanArray::false_count

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2957:
URL: https://github.com/apache/arrow-rs/pull/2957#issuecomment-1295031171

   I filed https://github.com/apache/arrow-rs/issues/2963 to track this


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-rs] ursabot commented on pull request #2957: Add BooleanArray::true_count and BooleanArray::false_count

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2957:
URL: https://github.com/apache/arrow-rs/pull/2957#issuecomment-1295309740

   Benchmark runs are scheduled for baseline = 87ac05bcafd343d3d8ad3b519631d83090afeb1c and contender = 843a2e5699a36537ff962d921d1c9aa0712a8d7c. 843a2e5699a36537ff962d921d1c9aa0712a8d7c is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/19b300e68d7c452c830c95a3fbe8d976...826b43bda96343c4b52afbdd6fb869b8/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/10eeb583f2ea4b7bbde0afdca7e315fb...549566a35b6d488d8c25d2ef6545218c/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/dc65190ab83248229a0db244f0a0d729...00a375432ddd45deb95a73735c6b0b75/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/9c9c82ded968482487c181b6053754af...a9b6e359cdb1402a80dc5734001b9059/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2957: Add BooleanArray::true_count and BooleanArray::false_count

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2957:
URL: https://github.com/apache/arrow-rs/pull/2957#discussion_r1007372959


##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -103,6 +103,53 @@ impl BooleanArray {
         &self.data.buffers()[0]
     }
 
+    /// Returns the number of true values within this buffer
+    pub fn true_count(&self) -> usize {
+        match self.data.null_buffer() {
+            Some(nulls) => {
+                let null_chunks = nulls.bit_chunks(self.offset(), self.len());

Review Comment:
   The duplication is a bit annoying, but any attempt I made to eliminate it just resulted in more code



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-rs] tustvold merged pull request #2957: Add BooleanArray::true_count and BooleanArray::false_count

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #2957:
URL: https://github.com/apache/arrow-rs/pull/2957


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-rs] alamb commented on a diff in pull request #2957: Add BooleanArray::true_count and BooleanArray::false_count

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2957:
URL: https://github.com/apache/arrow-rs/pull/2957#discussion_r1008026886


##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -103,6 +103,53 @@ impl BooleanArray {
         &self.data.buffers()[0]
     }
 
+    /// Returns the number of true values within this buffer

Review Comment:
   ```suggestion
       /// Returns the number of non null, true values within this array
   ```



##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -103,6 +103,53 @@ impl BooleanArray {
         &self.data.buffers()[0]
     }
 
+    /// Returns the number of true values within this buffer
+    pub fn true_count(&self) -> usize {
+        match self.data.null_buffer() {
+            Some(nulls) => {
+                let null_chunks = nulls.bit_chunks(self.offset(), self.len());
+                let value_chunks = self.values().bit_chunks(self.offset(), self.len());
+                null_chunks
+                    .iter()
+                    .zip(value_chunks.iter())
+                    .chain(std::iter::once((
+                        null_chunks.remainder_bits(),
+                        value_chunks.remainder_bits(),
+                    )))
+                    .map(|(a, b)| (a & b).count_ones() as usize)
+                    .sum()
+            }
+            None => self
+                .values()
+                .count_set_bits_offset(self.offset(), self.len()),
+        }
+    }
+
+    /// Returns the number of false values within this buffer
+    pub fn false_count(&self) -> usize {
+        match self.data.null_buffer() {

Review Comment:
   maybe this could be simplified into `self.size() - self.null_count() - self.true_count()` ? I think that would be basically as fast?



##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -431,4 +479,29 @@ mod tests {
     fn test_from_array_data_validation() {
         let _ = BooleanArray::from(ArrayData::new_empty(&DataType::Int32));
     }
+
+    #[test]
+    fn test_true_false_count() {
+        let mut rng = thread_rng();
+
+        for _ in 0..10 {
+            let d: Vec<_> = (0..2000).map(|_| rng.gen_bool(0.5)).collect();

Review Comment:
   ```suggestion
               // no nulls
               let d: Vec<_> = (0..2000).map(|_| rng.gen_bool(0.5)).collect();
   ```



##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -431,4 +479,29 @@ mod tests {
     fn test_from_array_data_validation() {
         let _ = BooleanArray::from(ArrayData::new_empty(&DataType::Int32));
     }
+
+    #[test]
+    fn test_true_false_count() {
+        let mut rng = thread_rng();
+
+        for _ in 0..10 {
+            let d: Vec<_> = (0..2000).map(|_| rng.gen_bool(0.5)).collect();
+            let b = BooleanArray::from(d.clone());
+
+            let expected_true = d.iter().filter(|x| **x).count();
+            assert_eq!(b.true_count(), expected_true);
+            assert_eq!(b.false_count(), d.len() - expected_true);
+
+            let d: Vec<_> = (0..2000)

Review Comment:
   ```suggestion
               // with nulls
               let d: Vec<_> = (0..2000)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

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