Coder Social home page Coder Social logo

Comments (5)

bvisness avatar bvisness commented on May 19, 2024 1

@Nairou That's an interesting case I hadn't thought of. And to @RandyGaul's point, if you want to use the mul style of math, the function names are probably so verbose that you would have to #define mul HMM_Multiply anyway, just to make them tolerable.

My biggest issue with the overloaded versions is that they don't really give you anything beyond the operator overloads (besides a more visible order of operations, I guess). If someone wants to take the @RandyGaul approach, I would rather just let them create mul in their own project with all the overloads they want. That way they can extend it to other things outside of Handmade Math.

from handmademath.

StrangeZak avatar StrangeZak commented on May 19, 2024

I could imagine some C++ like this feature of just being able to call HMM_Multiply with whatever data types and not have to call the explicit functions for that data type. Either way Iā€™m not torn on keeping them or not

from handmademath.

RandyGaul avatar RandyGaul commented on May 19, 2024

Personally I prefer mul kind of function in C++.

The reason is if we concatenate a few matrices like so:

D = A * B * C
D = C * B * A

It isn't extremely clear what the order of intended operations is just by looking at the * operator. This is a problem when someone opens up the math header and wants to create a transform hierarchy, but isn't sure what semantic ordering to apply until they see someone else using the header as an example. But, if there is a mul function people can use either ordering however they like, explicitly, and don't need to see sample code to figure out how to use the header.

D = mul(mul(A, B), C);
D = mul(mul(B, C), A);

I overload this mul function for matrix to matrix, matrix to vector, quaternion to vector, axis-angle to vector, and so-on, transform to transform, transform to vector, and so on.

One more advantage is a transposed multiply can be implemented, and can be potentially easier to on the compiler's optimizer. Compare the two options below for multiplying a tranposed matrix with another matrix.

C = transpose(A) * B;
C = mul_transposed(A, B);

The mul_transposed function can directly implement the operations in-line for transposed multiplication, without making a transposed copy of A.

The final reason, is adding more mul functions is really easy. I have similar mul functions (in my own code) for transforming shapes like planes and rays, or even arrays of vectors.

from handmademath.

Nairou avatar Nairou commented on May 19, 2024

I no longer use the overloaded functions either. I have also been tripped up in the past by reading two versions of each operation in the documentation (usually via search), trying one, and learning it was just an overload of something else.

from handmademath.

bvisness avatar bvisness commented on May 19, 2024

HMM 2.0 preserves the C++ overloads.

from handmademath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.