You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "izveigor (via GitHub)" <gi...@apache.org> on 2023/03/23 14:20:09 UTC

[GitHub] [arrow-rs] izveigor opened a new issue, #3914: feat: add comparison/sort support for Float16

izveigor opened a new issue, #3914:
URL: https://github.com/apache/arrow-rs/issues/3914

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   <!--
   A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 
   (This section helps Arrow developers understand the context and *why* for this feature, in addition to  the *what*)
   -->
   These changes added comparison/sort support for Float16 (the type from  library `use half::f16`)
   
   Code demo of features:
   ```
   use arrow::array::BooleanArray;
   use arrow::array::{Float16Array, ArrayRef};
   use arrow_ord::comparison::lt_dyn_scalar;
   use arrow_ord::sort::sort;
   use std::sync::Arc;
   use half::f16;
   
   fn main() {
       // comparison
       let array : Float16Array = [Some(f16::from_f64(2.0)), Some(f16::from_f64(1.0)), Some(f16::from_f64(3.0))].into_iter().collect();
       let a_eq = lt_dyn_scalar(&array, 2.0).unwrap();
       assert_eq!(
           a_eq,
           BooleanArray::from(
               vec![Some(false), Some(true), Some(false)]
           ),
       );
       
       // sort
       let array : Float16Array = [Some(f16::from_f64(2.0)), Some(f16::from_f64(1.0)), Some(f16::from_f64(3.0))].into_iter().collect();
       let array_ref: ArrayRef = Arc::new(array.clone());
       let sorted_array = sort(&array_ref, None).unwrap();
   
       assert_eq!(
           format!("{:#?}", sorted_array),
           "PrimitiveArray<Float16>\n[\n  1.0,\n  2.0,\n  3.0,\n]",
       );
   }
   ```
   **Describe the solution you'd like**
   The following functions/macros will work with float16:
   arrow-ord/sort.rs:
   - sort_to_indices (include in `pub fn sort` function)
   
   arrow-ord/comparison.rs:
   - dyn_compare_scalar!
   - typed_cmp_dict_non_dict!
   - typed_compares!
   - typed_dict_cmp!
   
   **Describe alternatives you've considered**
   Don't support sort/comparison functions for float16 data type.
   
   **Additional context**
   All changes are tested.
   
   The implementation of f16 is taken from `use half::f16`.
   


-- 
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.apache.org

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


[GitHub] [arrow-rs] tustvold closed issue #3914: feat: add comparison/sort support for Float16

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed issue #3914: feat: add comparison/sort support for Float16
URL: https://github.com/apache/arrow-rs/issues/3914


-- 
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