rust-polars-core-Update-rand.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From ad111d3113ce0a8893942a30756f10fbe8d9f80c Mon Sep 17 00:00:00 2001
  2. From: Gert Hulselmans <hulselmansgert@gmail.com>
  3. Date: Thu, 11 Nov 2021 22:43:04 +0100
  4. Subject: [PATCH] Update "rand" to 0.8 and "rand_distr" to 0.4. (#1713)
  5. This cherry-picks a commit ad111d3113ce0a8893942a30756f10fbe8d9f80c
  6. from upstream, adjusted to apply to the polars-core tarball from crates.io,
  7. and with the changes to Cargo.lock and Cargo.toml useless for Guix dropped.
  8. This way, we don't have to keep the old rust-rand around.
  9. ---
  10. .../src/chunked_array/random.rs | 25 ++++++++-----------
  11. 3 files changed, 24 insertions(+), 28 deletions(-)
  12. diff --git a/src/chunked_array/random.rs b/src/chunked_array/random.rs
  13. index b78f0d83c..486040097 100644
  14. --- a/src/chunked_array/random.rs
  15. +++ b/src/chunked_array/random.rs
  16. @@ -6,25 +6,22 @@ use rand::prelude::*;
  17. use rand::seq::IteratorRandom;
  18. use rand_distr::{Distribution, Normal, StandardNormal, Uniform};
  19. -fn create_rand_index_with_replacement(n: usize, len: usize) -> (ThreadRng, UInt32Chunked) {
  20. +fn create_rand_index_with_replacement(n: usize, len: usize) -> UInt32Chunked {
  21. let mut rng = rand::thread_rng();
  22. - (
  23. - rng,
  24. - (0u32..n as u32)
  25. - .map(move |_| Uniform::new(0u32, len as u32).sample(&mut rng))
  26. - .collect_trusted::<NoNull<UInt32Chunked>>()
  27. - .into_inner(),
  28. - )
  29. + (0u32..n as u32)
  30. + .map(move |_| Uniform::new(0u32, len as u32).sample(&mut rng))
  31. + .collect_trusted::<NoNull<UInt32Chunked>>()
  32. + .into_inner()
  33. }
  34. -fn create_rand_index_no_replacement(n: usize, len: usize) -> (ThreadRng, UInt32Chunked) {
  35. +fn create_rand_index_no_replacement(n: usize, len: usize) -> UInt32Chunked {
  36. // TODO! prevent allocation.
  37. let mut rng = rand::thread_rng();
  38. let mut buf = AlignedVec::with_capacity(n);
  39. // Safety: will be filled
  40. unsafe { buf.set_len(n) };
  41. (0u32..len as u32).choose_multiple_fill(&mut rng, buf.as_mut_slice());
  42. - (rng, UInt32Chunked::new_from_aligned_vec("", buf))
  43. + UInt32Chunked::new_from_aligned_vec("", buf)
  44. }
  45. impl<T> ChunkedArray<T>
  46. @@ -42,13 +39,13 @@ where
  47. match with_replacement {
  48. true => {
  49. - let (_, idx) = create_rand_index_with_replacement(n, len);
  50. + let idx = create_rand_index_with_replacement(n, len);
  51. // Safety we know that we never go out of bounds
  52. debug_assert_eq!(len, self.len());
  53. unsafe { Ok(self.take_unchecked((&idx).into())) }
  54. }
  55. false => {
  56. - let (_, idx) = create_rand_index_no_replacement(n, len);
  57. + let idx = create_rand_index_no_replacement(n, len);
  58. // Safety we know that we never go out of bounds
  59. debug_assert_eq!(len, self.len());
  60. unsafe { Ok(self.take_unchecked((&idx).into())) }
  61. @@ -73,8 +70,8 @@ impl DataFrame {
  62. }
  63. // all columns should used the same indices. So we first create the indices.
  64. let idx: UInt32Chunked = match with_replacement {
  65. - true => create_rand_index_with_replacement(n, self.height()).1,
  66. - false => create_rand_index_no_replacement(n, self.height()).1,
  67. + true => create_rand_index_with_replacement(n, self.height()),
  68. + false => create_rand_index_no_replacement(n, self.height()),
  69. };
  70. // Safety:
  71. // indices are within bounds
  72. base-commit: dab34d3832935bb084c1ec583a729a261a6160b2
  73. --
  74. 2.36.1