Giter VIP home page Giter VIP logo

Comments (6)

bvisness avatar bvisness commented on June 2, 2024

I don't know what you mean. They allow you to access elements of vectors by index without writing .Elements, if you're using C++. So like myVec3[2] instead of myVec3.Elements[2].

from handmademath.

xparq avatar xparq commented on June 2, 2024

Ahh, sorry, I though the issue title was self-explanatory, but there's always room for misunderstanding. :)

I meant the operator's signature, of course, and (as I noted), specifically its arg. passing approach.

IOW, why the ref? Just pass Index by-val.

from handmademath.

bvisness avatar bvisness commented on June 2, 2024

I meant the operator's signature, of course

When working with humans, I recommend communicating using words and sentences so humans can understand.

Pass-by-reference vs. pass-by-val literally doesn't matter: https://godbolt.org/z/jT63zqWWh. If you believe it does matter and can demonstrate this in godbolt, perhaps we can consider making a change.

from handmademath.

xparq avatar xparq commented on June 2, 2024

Wow, sorry that my friendly suggestion, and my apology both apparently rubbed you the wrong way.
In the hope of some understanding, still: given the context of a) maths, b) C++ coding, and c) the pretty common & well-known old C++ habit of passing everything* by const&, I thought that my notation-heavy (and admittedly too condensed) message would click. I totally understand that it didn't, absolutely fine, maybe even I wouldn't understand it myself. I should've been less cryptic. Sorry again. And misunderstandings are indeed abundant, everywhere, all the time, with everybody -- most of the time we just don't even notice. That's what I meant by my sarcastic remark, and nothing personal.

* except, in your code, AFAICR, it seems to be not done for much else (I may remember wrong) -- that strange (mostly just cosmetic) inconsistency was what made me assume (wrongly then, I suppose) that it could probably be just a copy-paste remnant from older versions


As to Godbolt and stuff: I didn't mean to suggest it for performance, I meant it for a slight code readability improvement (noise reduction), precisely because the more convoluted formulation has no benefits.

from handmademath.

RandyGaul avatar RandyGaul commented on June 2, 2024

Passing everything by pointers or references is not a good habit for certain code as it can introduce pointer aliasing and cause a performance hit.

from handmademath.

bvisness avatar bvisness commented on June 2, 2024

Sure, so if we want to assess values vs. references then we should do so holistically and not for some specific operators based on "readability".

Currently we have:

  • float &operator[](const int &Index) (get vector element)
  • HMM_VecN &operator[](const int &Index) (get matrix column)
  • HMM_T operator+(HMM_T Left, HMM_T Right) (add, subtract, multiply, and divide vectors, matrices, and quaternions)
  • HMM_VecN &operator+=(HMM_VecN &Left, HMM_VecN Right) (same operators combined with assignment)
  • HMM_VecN operator*(HMM_VecN Left, float Right) (vector or matrix * float, and the reverse)
  • HMM_VecN operator*(HMM_MatN Matrix, HMM_VecN Vector) (matrix * vector)
  • HMM_Bool operator==(HMM_VecN Left, HMM_VecN Right) (vector equality and inequality)
  • HMM_VecN operator-(HMM_VecN In) (vector negation)

Clearly most of them are indeed passing by value. I suppose we have to trade off the costs of copies vs. the cost of pointer aliasing, but surely these will almost always be inlined anyway. If passing by reference makes it less likely to inline due to pointer aliasing, then yeah, we should probably switch.

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.