Skip to content

Conversation

@GrigoryEvko
Copy link

Quality of life improvement for dot product operations. Entirely optional - feel free to reject if this adds
unnecessary API surface.

Methods:

  • dot(rhs) - Full dot product (alias for (self * rhs).reduce_sum())
  • dot3(rhs) - 3D dot product (first 3 elements, w component ignored)
  • dot4(rhs) - 4D dot product (first 4 elements only)

Rationale:

  • dot3()/dot4() reduce boilerplate in graphics/physics code
  • dot() provides discoverability and matches industry libraries (NumPy, GLM, Eigen)
  • All methods are inline, zero-cost abstractions
  • 26 comprehensive tests included

Implementation:

  • dot() delegates to (self * rhs).reduce_sum()
  • dot3()/dot4() use compile-time assertions for size safety
  • Zero allocations, pure SIMD register operations

Testing:

  • Mathematical properties (commutativity, distributivity, scaling)
  • Special values (infinity, NaN propagation)
  • Size variations (f32x2, f32x4, f32x8, f64x2, f64x4, f64x8)
  • Edge cases (orthogonal vectors, zero vectors, negative values)

Happy to close if you feel it's not worth the API complexity.

GrigoryEvko and others added 3 commits November 16, 2025 23:03
Quality of life improvement for dot product operations. Entirely optional - feel free to reject if this adds unnecessary API surface.

Methods:
- dot(rhs) - Full dot product (sugar for (self * rhs).reduce_sum())
- dot3(rhs) - 3D dot product (first 3 elements, w component ignored)
- dot4(rhs) - 4D dot product (first 4 elements only)

Rationale:
- dot3()/dot4() reduce boilerplate in graphics/physics code
- dot() provides discoverability and matches industry libraries (NumPy, GLM, Eigen)
- All methods are inline, zero-cost abstractions

Implementation:
- dot() delegates to (self * rhs).reduce_sum()
- dot3()/dot4() use compile-time assertions for size safety
- Zero allocations, pure SIMD register operations

Testing (26 tests):
- Mathematical properties (commutativity, distributivity, scaling)
- Special values (infinity, NaN, MAX, MIN, subnormals)
- Size variations (f32x2, f32x4, f32x8, f64x2, f64x4, f64x8)
- Edge cases (orthogonal vectors, zero vectors, negative values)
- w component correctly ignored in dot3()
- Elements beyond index correctly ignored in dot3()/dot4()

The decision to include this is completely up to maintainers. Happy to close if you feel it's not worth the API complexity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
ARM NEON uses flush-to-zero (FTZ) for subnormal values in SIMD operations.
Updated tests to accept either the correct subnormal result or zero.
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.

1 participant