Created
January 29, 2023 03:00
-
-
Save HurricanKai/a401125f12133297c6b309d9acb042b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PCG32 randomness | |
let all_randomness = vec!["pcg_state", "pcg_inc"]; | |
const PCG32_MULT: u64 = 0x5851f42d4c957f2du64; | |
// note that a >> b and a << b are replaced with a / lit(2.pow(b)) and a * lit(2.pow(b)) respectively | |
/* let xorshifted = ((col("pcg_state") / lit(2u64.pow(18))).xor(col("pcg_state")) | |
/ lit(2u64.pow(27))) | |
.cast(DataType::UInt32); | |
let rot = (col("pcg_state") / lit(2u64.pow(59))).cast(DataType::UInt32); | |
let random_u32 = (((col("pcg_state") / lit(2u64.pow(18))).xor(col("pcg_state")) | |
/ lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
/ lit(2).pow((col("pcg_state") / lit(2u64.pow(59))).cast(DataType::UInt32))) | |
.or( | |
((col("pcg_state") / lit(2u64.pow(18))).xor(col("pcg_state")) / lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
* lit(2) | |
.pow((col("pcg_state") / lit(2u64.pow(59))).cast(DataType::UInt32).not() + lit(1)) | |
.and(31), | |
); | |
*/ | |
let r1 = (((((col("pcg_state") / lit(2u64.pow(18))).xor(col("pcg_state")) | |
/ lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
/ lit(2).pow((col("pcg_state") / lit(2u64.pow(59))).cast(DataType::UInt32))) | |
.or( | |
((col("pcg_state") / lit(2u64.pow(18))).xor(col("pcg_state")) / lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
* lit(2) | |
.pow( | |
(col("pcg_state") / lit(2u64.pow(59))) | |
.cast(DataType::UInt32) | |
.not() | |
+ lit(1), | |
) | |
.and(31), | |
)) * lit(2u64.pow(20))) | |
.or(lit(0x3ff0000000000000u64)); | |
let r2 = ((((((col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) | |
/ lit(2u64.pow(18))) | |
.xor(col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) | |
/ lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
/ lit(2).pow( | |
((col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) / lit(2u64.pow(59))) | |
.cast(DataType::UInt32), | |
)) | |
.or((((col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) | |
/ lit(2u64.pow(18))) | |
.xor(col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) | |
/ lit(2u64.pow(27))) | |
.cast(DataType::UInt32) | |
* lit(2) | |
.pow( | |
((col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) / lit(2u64.pow(59))) | |
.cast(DataType::UInt32) | |
.not() | |
+ lit(1), | |
) | |
.and(31))) | |
* lit(2u64.pow(20))) | |
.or(lit(0x3ff0000000000000u64)); | |
let generate_random = vec![ | |
// advance state by 2 | |
((col("pcg_state") * lit(PCG32_MULT) + col("pcg_inc")) * lit(PCG32_MULT) | |
+ col("pcg_inc")) | |
.alias("pcg_state"), | |
col("pcg_inc"), | |
r1.alias("r1"), | |
r2.alias("r2"), | |
cols(&all_positions), | |
cols(&all_velocities), | |
cols(&all_pbest), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment