Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement struct-of-arrays (SoA) utilities #320

Merged
merged 1 commit into from
May 1, 2023
Merged

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Apr 23, 2023

This adds a set of iterators and utilities for converting between arrays of structs and structs of arrays. There's definitely more that can be done, but it's a start. This pull request includes:

  • Creating and extendingColorType<Collection<T>> from any IntoIterator<Item=ColorType<T>>.
  • Iterating over ColorType<Collection<T>>.
  • Some Vec functions are available for ColorType<Vec<T>>, with more that can be added.
  • Slicing and indexing with get and get_mut.
  • Working with ColorType<&T> and ColorType<&mut T>, using copied, cloned and set.

See the discussion in #303 for some background.

Closed Issues

@Ogeon
Copy link
Owner Author

Ogeon commented Apr 23, 2023

There are still a few pieces left, but it's time to stop for today.

@github-actions
Copy link

Benchmark for da49fc0

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.2±0.10µs 3.2±0.07µs 0.00%
Cie family/lab to xyz 760.9±17.06ns 763.5±15.99ns +0.34%
Cie family/lch to lab 2.4±0.03µs 2.4±0.08µs 0.00%
Cie family/linsrgb to xyz 308.0±4.47ns 310.2±9.66ns +0.71%
Cie family/linsrgb to xyz - wide::f32x8 101.7±1.28ns 107.2±1.25ns +5.41%
Cie family/xyz to lab 18.0±0.51µs 18.1±0.48µs +0.56%
Cie family/xyz to yxy 628.7±7.77ns 629.6±8.44ns +0.14%
Cie family/yxy to xyz 653.2±18.92ns 653.3±13.12ns +0.02%
Matrix functions/matrix_inverse 11.1±0.14ns 10.7±0.14ns -3.60%
Matrix functions/multiply_3x3 9.8±0.94ns 9.7±0.14ns -1.02%
Matrix functions/multiply_rgb_to_xyz 6.0±0.08ns 6.0±0.09ns 0.00%
Matrix functions/multiply_xyz 6.0±0.12ns 6.0±0.13ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.0±0.09ns 6.0±0.09ns 0.00%
Matrix functions/rgb_to_xyz_matrix 24.9±0.37ns 24.9±0.31ns 0.00%
Rgb family/hsl to hsv 649.9±7.29ns 650.9±7.54ns +0.15%
Rgb family/hsl to linear hsl 13.0±0.24µs 13.0±0.23µs 0.00%
Rgb family/hsl to rgb 2.2±0.03µs 2.2±0.03µs 0.00%
Rgb family/hsv to hsl 821.8±19.35ns 822.3±10.23ns +0.06%
Rgb family/hsv to hwb 233.4±3.88ns 233.9±2.99ns +0.21%
Rgb family/hsv to linear hsv 11.7±0.14µs 11.8±0.30µs +0.85%
Rgb family/hsv to rgb 1921.7±41.53ns 1972.9±28.58ns +2.66%
Rgb family/hwb to hsv 482.0±11.03ns 482.3±6.80ns +0.06%
Rgb family/hwb to linear hwb 12.4±0.17µs 12.3±0.18µs -0.81%
Rgb family/linear hsl to hsl 11.3±0.22µs 11.3±0.18µs 0.00%
Rgb family/linear hsv to hsv 10.4±0.31µs 10.2±0.14µs -1.92%
Rgb family/linear hwb to hwb 11.3±0.19µs 11.3±0.19µs 0.00%
Rgb family/linsrgb to rgb 5.9±0.17µs 5.9±0.08µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.1±0.09µs 5.1±0.06µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 959.4±13.80ns 961.9±14.36ns +0.26%
Rgb family/linsrgb_f64 to rgb_u8 1217.8±13.21ns 1219.0±18.57ns +0.10%
Rgb family/rgb to hsl 848.4±13.67ns 855.3±13.01ns +0.81%
Rgb family/rgb to hsl - wide::f32x8 472.1±8.08ns 469.8±6.49ns -0.49%
Rgb family/rgb to hsv 515.3±9.63ns 523.1±6.03ns +1.51%
Rgb family/rgb to hsv - wide::f32x8 426.9±4.69ns 428.3±7.82ns +0.33%
Rgb family/rgb to linsrgb 8.3±0.11µs 8.3±0.20µs 0.00%
Rgb family/rgb to linsrgb - wide::f32x8 3.3±0.07µs 3.3±0.08µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 307.9±6.14ns 306.8±4.89ns -0.36%
Rgb family/rgb_u8 to linsrgb_f64 311.2±3.25ns 312.7±4.92ns +0.48%
Rgb family/xyz to linsrgb 355.4±6.12ns 354.0±5.61ns -0.39%
Rgb family/xyz to linsrgb - wide::f32x8 105.5±1.47ns 106.2±2.50ns +0.66%

@Ogeon Ogeon force-pushed the struct_of_arrays branch from 2f96885 to 01239e2 Compare April 29, 2023 15:27
@Ogeon Ogeon marked this pull request as ready for review April 29, 2023 15:28
@Ogeon
Copy link
Owner Author

Ogeon commented Apr 29, 2023

I believe this fulfills the initial requirements and some more. 🙂 I struggled a bit with coming up with a good example, so that may be improved later.

@Ogeon Ogeon force-pushed the struct_of_arrays branch from 01239e2 to aee9c93 Compare April 29, 2023 15:32
@github-actions
Copy link

Benchmark for b1e0c79

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.2±0.04µs 3.2±0.08µs 0.00%
Cie family/lab to xyz 764.9±9.22ns 764.8±14.05ns -0.01%
Cie family/lch to lab 2.4±0.05µs 2.4±0.05µs 0.00%
Cie family/linsrgb to xyz 308.8±7.12ns 310.6±7.19ns +0.58%
Cie family/linsrgb to xyz - wide::f32x8 101.1±1.90ns 101.7±2.33ns +0.59%
Cie family/xyz to lab 17.9±0.26µs 18.3±1.10µs +2.23%
Cie family/xyz to yxy 632.8±10.08ns 629.8±14.93ns -0.47%
Cie family/yxy to xyz 547.4±7.70ns 548.2±7.47ns +0.15%
Matrix functions/matrix_inverse 10.7±0.15ns 10.8±0.22ns +0.93%
Matrix functions/multiply_3x3 9.7±0.28ns 9.6±0.11ns -1.03%
Matrix functions/multiply_rgb_to_xyz 6.0±0.08ns 6.0±0.12ns 0.00%
Matrix functions/multiply_xyz 6.0±0.15ns 6.0±0.18ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.0±0.06ns 6.0±0.11ns 0.00%
Matrix functions/rgb_to_xyz_matrix 24.9±0.37ns 24.9±0.34ns 0.00%
Rgb family/hsl to hsv 649.7±9.86ns 648.3±8.63ns -0.22%
Rgb family/hsl to linear hsl 13.2±0.21µs 13.1±0.30µs -0.76%
Rgb family/hsl to rgb 2.1±0.02µs 2.1±0.04µs 0.00%
Rgb family/hsv to hsl 831.4±37.51ns 821.2±11.13ns -1.23%
Rgb family/hsv to hwb 233.4±4.67ns 233.0±4.51ns -0.17%
Rgb family/hsv to linear hsv 11.7±0.13µs 11.8±0.21µs +0.85%
Rgb family/hsv to rgb 1968.5±49.27ns 1915.3±26.59ns -2.70%
Rgb family/hwb to hsv 479.7±4.65ns 482.8±15.01ns +0.65%
Rgb family/hwb to linear hwb 12.4±0.27µs 12.4±0.19µs 0.00%
Rgb family/linear hsl to hsl 11.2±0.18µs 11.2±0.17µs 0.00%
Rgb family/linear hsv to hsv 10.2±0.14µs 10.3±0.15µs +0.98%
Rgb family/linear hwb to hwb 11.3±0.16µs 11.3±0.16µs 0.00%
Rgb family/linsrgb to rgb 5.9±0.11µs 5.9±0.22µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.2±0.10µs 5.2±0.12µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 959.3±15.55ns 954.8±17.43ns -0.47%
Rgb family/linsrgb_f64 to rgb_u8 1225.0±31.96ns 1221.8±27.84ns -0.26%
Rgb family/rgb to hsl 853.4±13.86ns 847.9±11.22ns -0.64%
Rgb family/rgb to hsl - wide::f32x8 469.7±6.94ns 470.2±7.51ns +0.11%
Rgb family/rgb to hsv 516.7±20.28ns 515.1±13.27ns -0.31%
Rgb family/rgb to hsv - wide::f32x8 430.0±7.44ns 431.6±12.26ns +0.37%
Rgb family/rgb to linsrgb 8.3±0.14µs 8.3±0.17µs 0.00%
Rgb family/rgb to linsrgb - wide::f32x8 3.3±0.05µs 3.3±0.05µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 306.2±3.71ns 306.8±4.33ns +0.20%
Rgb family/rgb_u8 to linsrgb_f64 311.3±3.66ns 312.1±3.25ns +0.26%
Rgb family/xyz to linsrgb 352.8±4.07ns 354.3±7.63ns +0.43%
Rgb family/xyz to linsrgb - wide::f32x8 106.1±1.54ns 105.6±1.55ns -0.47%

@Ogeon
Copy link
Owner Author

Ogeon commented May 1, 2023

bors r+

@bors
Copy link
Contributor

bors bot commented May 1, 2023

Build succeeded:

@bors bors bot merged commit efd30f9 into master May 1, 2023
@bors bors bot deleted the struct_of_arrays branch May 1, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pixel to Struct of Arrays (and back again!)
1 participant