|
giogadi posted:I seem to recall some random trivia that, if you want to represent a 3D Vector as a struct, it can be advantageous to actually store 4 values: Well, depending on the compiler, it might be able to automagically compile a lot of vector code into SSE intrinsics. If you use a library dedicated to 3d-graphics-adjacent vector math, like GLM, you can enforce this through template parameters, even.
|
# ? Mar 10, 2021 02:45 |
|
|
# ? Jun 8, 2024 08:48 |
|
Absurd Alhazred posted:Well, depending on the compiler, it might be able to automagically compile a lot of vector code into SSE intrinsics. If you use a library dedicated to 3d-graphics-adjacent vector math, like GLM, you can enforce this through template parameters, even. Yeah, it's for vector intrinsics, which usually need their arguments to be aligned on 4-word/16-byte boundaries.
|
# ? Mar 10, 2021 03:11 |
|
Absurd Alhazred posted:Well, depending on the compiler, it might be able to automagically compile a lot of vector code into SSE intrinsics. If you use a library dedicated to 3d-graphics-adjacent vector math, like GLM, you can enforce this through template parameters, even. more falafel please posted:Yeah, it's for vector intrinsics, which usually need their arguments to be aligned on 4-word/16-byte boundaries. Thanks! I'm trying to experiment to make sure I understand the concept correctly. It turns out that just putting 4 values in the struct does not guarantee 16-byte alignment of the struct. Here's an example that shows this: code:
|
# ? Mar 10, 2021 04:29 |
|
That would do it, so would code:
|
# ? Mar 10, 2021 05:03 |
|
giogadi posted:I’m not sure - I always thought the fastest way to rotate a 3d vector is just to multiply with a 3x3 rotation matrix. Like, you can directly rotate a vector with a quaternion but it’s about as fast as converting the quat into a rotation matrix and just rotating that way. But I might be wrong!
|
# ? Mar 10, 2021 05:16 |
|
I was just cleaning up old environments at work, and I found a comical thing I wrote to make constexpr maps in C++, keyed on strings or ints. The idea being you can do something like code:
But the reason it's still floating in an old environment is it had an annoying issue where g++ (or maybe it was clang) complained about accessing arrays out of bounds, because it had a bit in it like code:
I could make it work with a #pragma disabling that warning before the template code and re-enabling it after, but unfortunately that kind of #pragma doesn't support push/pop behavior, so that would mean my template code could unintentionally enable a warning that the user did not want for any files included after that one. So my amazing convoluted class of nonsense never saw the light of day.
|
# ? Mar 10, 2021 05:51 |
|
Re: coordinate transforms, there are a couple of different options, with different trade-offs in how hard it is to apply them to a vector, how much memory footprint they require and how hard it is to compose two different transforms to arrive at the "first A, then B" transform. If you're in a situation where the representation matters -- which you generally are not -- then you might use one representation for storage, one when applying or compositing, you might support multiple representation types for different scenarios and batch process each type separately, etc. A list: - 3x3 matrices can represent some combination of rotation, scale and shear. Compose easily. 9 floats storage, 15 flops to apply (ignoring vectorization, fma, real hardware in general), 45 flops to compose. - A 3x3 matrix + offset vector represents any affine transform (i.e. also translates) and composes about as well. 12 floats storage, 18 flops to apply, - 4x4 matrices also do any affine transform through homogeneous coordinates, likewise compose well. 16 floats storage (naively), 28 flops to apply, ... I'unno, 80ish flops to compose naively I think. - Axis of rotation + angle represents rotation only. Cheap to store at 3 or 4 floats, 32 flops and some trig to apply. Basically can't be composed without switching to another representation. - Euler angles are rotation only. Cheap to store at 3 floats, easy to apply if trig is cheap. Has degenerate gimbal lock issues, hard to compose. - Quaternions are effectively rotation only (you have the freedom to do other things, but I'm sure as hell not going to). 4 floats worth of storage, I think something like 20 flops both to apply and to compose. The flops numbers are highly dubious in terms of real cycles since hardware instructions for basic float vector operations have been around on mainstream CPUs for over 20 years and vectorizing linear algebra is just about all a GPU does. Any sane library will use the hardware vector implementation for matrix and quaternion operations. A nice compiler might figure it out too if your float math is really straightforward, but generally don't expect it. No one does Euler angles, they suck. Sorry Leonhard. Axis-angle happens for storage if you really need the space/cache efficiency, but is usually converted to some other representation for actual use. 4x4 matrix is the go-to when you actually have a homogeneous coordinate and want a full affine transform. 3x3 matrix is generally better than 4x4 for the transforms it supports: typically as fast in hardware, faster to compose and you fit more transforms in cache. 3x3 matrix + offset vector is mainly a thing in cases where you need the translation component in higher precision (not uncommon in CAD). Quaternions are the go-to option for pure rotations because they have a small cache footprint, compose very easily and are reasonably fast to apply. Only drawback is that they can't realistically do anything but rotations. tl;dr: just use 4x4 matrices and homogeneous coordinates everywhere unless you really care about the storage footprint of your millions of transforms or are doing a bunch of rotational composition that absolutely must be blazing fast. If you do have to care, use a good vectorized library (e.g. Eigen) and profile because it's hard to guess at the real-world performance. It depends on the balance of composition-vs-application, if you're applying one transform to many vectors or applying several different transforms, how cache-friendly your data layout is, etc. Whatever library you use will probably handle 3x3 and 4x4 matrix multiplies with the same __m128 types and intrinsics, but you want avoid caring about that particular detail unless your interest is specifically teaching yourself vectorization. Xerophyte fucked around with this message at 14:51 on Mar 10, 2021 |
# ? Mar 10, 2021 06:39 |
|
UE3 used Euler angles all over the place, it was a mess.
|
# ? Mar 10, 2021 06:44 |
|
more falafel please posted:UE3 used Euler angles all over the place, it was a mess. I mean, they make sense as a user-facing input. Just don't do vector math with them.
|
# ? Mar 10, 2021 06:46 |
|
Xerophyte posted:I mean, they make sense as a user-facing input. Just don't do vector math with them. Yeah, but they did. It's a miracle any game ever shipped on UE3, let alone that a lot of them were good.
|
# ? Mar 10, 2021 06:59 |
|
chglcu posted:FTFY I know what you mean. Rust is a bit too opinionated. Nim and especially D are for me the more appealing ones, especially the latter one. D is literally a "sick of C++'s bullshit" the language, created by gamedev and C++ compiler writer Walter bright. It has seen some use in gamedev at Remedy for rapid prototyping through dynamic linking iDTech style, but doesn't seem to get much more traction.
|
# ? Mar 10, 2021 23:12 |
|
I miss the in-house math libraries we used at avalanche that used geometric algebra. So, rotors instead of quats. And frankly I don’t even understand the math enough to have a valid preference.
|
# ? Mar 11, 2021 01:04 |
|
Xerophyte posted:Re: coordinate transforms, there are a couple of different options, with different trade-offs in how hard it is to apply them to a vector, how much memory footprint they require and how hard it is to compose two different transforms to arrive at the "first A, then B" transform. If you're in a situation where the representation matters -- which you generally are not -- then you might use one representation for storage, one when applying or compositing, you might support multiple representation types for different scenarios and batch process each type separately, etc. Just wanted to say that this is a great post.
|
# ? Mar 11, 2021 03:43 |
|
Yeah, that was super helpful. Much appreciated!
|
# ? Mar 11, 2021 05:02 |
|
baby puzzle posted:I miss the in-house math libraries we used at avalanche that used geometric algebra. So, rotors instead of quats. And frankly I don’t even understand the math enough to have a valid preference. Cool! About my sum total knowledge about geometric algebra is that quaternions are equivalent to some of it (googling says they're equivalent to the subalgebra G(3,0), whatever that means) and that you can use them to "extend" quaternions to all conformal (rotation, translation, mirroring) transforms in some nice way that I don't understand. Not that I really understand quaternions either, I can just encode a rotation in them. I've never come across anyone using GA, or any code that does; I didn't know Avalanche did. What did you like about it? Did it handle non-conformal transforms?
|
# ? Mar 11, 2021 11:57 |
|
Geometric algebra is nice because it's a bit more intuitive to derive and generalizes better to other dimensionalities. It doesn't actually make much difference in your code, or any difference in your performance, at the end of the day, but it would still be cool to see it used more.
|
# ? Mar 11, 2021 18:03 |
|
No one "understands" quaternions, but don't let that stop you from using them.
|
# ? Mar 11, 2021 18:17 |
|
code:
Nalin fucked around with this message at 02:58 on Mar 12, 2021 |
# ? Mar 12, 2021 01:59 |
|
Nalin posted:How can I make an isA2 concept that wouldn't make the doStuff function ambiguous for A3? Because no matter how much I search on stuff like SFINAE and whatnot, nobody ever seems to have ever had the question, "How do I check for something NOT existing?" Took me forever but I was finally able to solve it. code:
|
# ? Mar 12, 2021 03:29 |
|
Just out of curiosity, why do you need to know than an A2 is not an A3?
|
# ? Mar 12, 2021 03:31 |
|
Because otherwise calling doStuff on an A3 is ambiguous - the value matches both the A2 and A3 concepts, so it's not clear which one should be used. The idea is to make the A2 declaration uninstantiable for things that are actually an A3, the same way the A3 declaration is inherently uninstantiable for things that are "just" an A2 without any z value. What I don't totally understand (perhaps because something is lost in converting the real situation to a toy example) is why the situation even uses templates and concepts to begin with.
|
# ? Mar 12, 2021 03:43 |
|
Jabor posted:What I don't totally understand (perhaps because something is lost in converting the real situation to a toy example) is why the situation even uses templates and concepts to begin with. Basically, I am using Google mathfu, which does terrible things like this: code:
Google was very nice in providing a vector::FromType/ToType function which helpfully just memcpy's the whole data[] array, because that's a great way to frustrate people trying to debug why everything has exploded. Turns out you can't memcpy a float into an int and make it work.
|
# ? Mar 12, 2021 04:27 |
|
Nalin posted:I wanted to make a generic conversion function that could convert a vector<int, 2> to a vector<float, 2>, and any other data type. I also wanted it to work on vector<T, 3> with the same name, but overloaded. Surely you should just be using the array representation, no? code:
|
# ? Mar 12, 2021 05:20 |
|
ShoulderDaemon posted:I mean, I'm assuming that these things are packed appropriately for this to work correctly, but working with the integer-indexed data seems a lot simpler than trying to deal with overloads and named members. It's at this point where "typedef mathfu::Vector<float, 2> Vector2df;" enters the whole codebase and screws up everything.
|
# ? Mar 12, 2021 06:54 |
|
Nalin posted:It's at this point where "typedef mathfu::Vector<float, 2> Vector2df;" enters the whole codebase and screws up everything. I think I must not be understanding the problem you're encountering, because it works okay for me.
|
# ? Mar 12, 2021 07:22 |
|
ShoulderDaemon posted:I think I must not be understanding the problem you're encountering, because it works okay for me. You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff.
|
# ? Mar 12, 2021 09:10 |
|
That pretty much summarizes programming
|
# ? Mar 12, 2021 13:00 |
|
Nalin posted:How can I make an isA2 concept that wouldn't make the doStuff function ambiguous for A3? Because no matter how much I search on stuff like SFINAE and whatnot, nobody ever seems to have ever had the question, "How do I check for something NOT existing?" So your real question has already been answered but if for some reason in the future you really do need to check for a field not existing, you could do it like: (godbolt link) code:
|
# ? Mar 12, 2021 13:48 |
|
Nalin posted:You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff. It's the next day and I'm refreshed now. I know why I didn't see that method of doing it. I was completely focused on doing: auto vec = convert<Vector2di>(floatvec); It is definitely a lot more simple to do: auto vec = convert<int32_t>(floatvec); Lime posted:So your real question has already been answered but if for some reason in the future you really do need to check for a field not existing, you could do it like: (godbolt link) Awesome, thanks! I eventually figured out a similar thing for a different problem I was having. Well, if anything, flailing around like this is definitely giving me a better understanding of things like SFINAE and concepts.
|
# ? Mar 12, 2021 19:54 |
I’ve been hugely enjoying ploughing through CS50, but having finally gone back with the benefit of a couple of extra weeks’ knowledge and compiled a version of Tideman that worked for all tests I have to say: gently caress that guy and his horrible election ranking system. E: it’s not really a question I just wanted to vent because good God that was an exercise in patience.
|
|
# ? Mar 14, 2021 16:16 |
|
The downside to adding items to the end of a vector is that the internal array may be resized when its capacity is reached. This can be a somewhat expensive operation if your vector already has a lot of items in it. If you know in advance the number of items you'll be push_backing into your vector, you can make sure there's enough space in the internal array for them by calling the vector's "reserve" member function beforehand. e: This is an answer to a question that I now cannot find in the thread. FastEddie fucked around with this message at 10:59 on Mar 15, 2021 |
# ? Mar 15, 2021 10:55 |
|
Just keep in mind that keeping reserve more than twice on one instance of vector is likely serious performance bug.
|
# ? Mar 15, 2021 14:37 |
|
This is a bit of a longshot, but does anybody here have any experience with any of the C++ libraries designed to read lidar data? (i.e., laz files). None of the ones with documented APIs seem to support laz format 1.4, which I need. Laszip (which backs all the libraries) supports 1.4 but has extremely poor documentation and sometimes it just seems to return 0 instead of the actual values present in the file (which I can verify using the well-documented libraries in other languages). It's probably my own drat fault with not understanding the poorly-document API though. e: lmao it was extremely dumb and had nothing to do with misunderstanding the api the documentation was so poor that I was having trouble to get my code to even compile, and ended up linking to both the current and old-version .lib file. When I cleaned out my links to only link to the current version it worked fine. cheetah7071 fucked around with this message at 00:03 on Mar 16, 2021 |
# ? Mar 15, 2021 23:40 |
|
Hello C++ thread, we are hiring people to work on trading/execution platforms in NYC. Most of our code is C++, we have a bunch of transport layer stuff in C, and you should be familiar enough with C to read our tactic code. We are also looking to use Rust for future systems, so if you know and/or want to know Rust that is a plus. A large number of our tests (especially integration tests, we test multiple trading systems at once) are coordinated in typed python3, so familiarity with python and type annotations is a big plus. You will be expected to get your Series 57 (https://www.finra.org/registration-exams-ce/qualification-exams/series57), requires recertification every few years in the form a CYOA. Position is not fully remote, after the pandemic cools you can do a couple days a week from home. Shoot me a PM if you are interested and I can give you some more details.
|
# ? Mar 22, 2021 21:55 |
|
Sweeper posted:You will be expected to get your Series 57 (https://www.finra.org/registration-exams-ce/qualification-exams/series57), requires recertification every few years in the form a CYOA lol at the idea that financial “regulations” in this country are administered by Choose Your Own Adventure quote:You are about to change code governing single transactions if more money than most human beings will ever earn in a lifetime. Suddenly, you notice a flaw in the logic...
|
# ? Mar 22, 2021 23:58 |
|
csammis posted:lol at the idea that financial “regulations” in this country are administered by Choose Your Own Adventure Well the initial test is a lovely test you go to a testing center to take. If I recall it’s a couple hours of multiple choice questions about the financial industry, regulations, basics of the the different securities and how they work, why they exist, etc. the test just makes sure you have any idea how finance works, you need to know the regulations exist to be able to look them up and follow them (compliance department is obviously the backstop on did you follow it)
|
# ? Mar 23, 2021 00:42 |
|
I'de rather do a CYOA than the mandatory silverlight-powered stock footage masterpieces of : "You meet up with your friend Nancy working for a competitor. In a private meeting she asks you to fix prices. Do you a) agree b) tell her you agree but secretly do not do it or c) notify your manager, legal, and the fraud and compliance officer" Yes, now I'm totally up to speed with ethics and compliance laws! To post some actual C++ content: With Concepts finally being in a released standard, are we seeing an uptick in the use of C++ template mixins? I remember them being pretty neat, but seen rarely. Likely it's because it just introduced yet another giant footgun. Concepts seem to solve some of its problems, on paper at least.
|
# ? Mar 23, 2021 13:13 |
|
You mean what some people call policy-based design, e.g. std::lock<mutex-type>, where mutex type changes what actually happens?
|
# ? Mar 23, 2021 14:41 |
|
Beef posted:With Concepts finally being in a released standard, are we seeing an uptick in the use of C++ template mixins? I've never used mixins before, but at least in my hobby projects I've started to make use of concepts in general. I usually try to filter my template with a requires to reduce arcane compiler errors. Like, just a few days ago I took a template function that converts an enum to a number and threw a "requires std::integral<T>" on it. I've also taken to creating new concepts for templates that operate on class member variables and functions in order to make simpler error messages.
|
# ? Mar 23, 2021 19:19 |
|
|
# ? Jun 8, 2024 08:48 |
|
Sweeper posted:Well the initial test is a lovely test you go to a testing center to take. If I recall it’s a couple hours of multiple choice questions about the financial industry, regulations, basics of the the different securities and how they work, why they exist, etc. the test just makes sure you have any idea how finance works, you need to know the regulations exist to be able to look them up and follow them (compliance department is obviously the backstop on did you follow it) The point of these "tests" is not to actually verify your knowledge; it is to let your employer document that yes, we totally trained Mr. Sweeper on safety/environmental/security regulations, here is confirmation that he passed the test, so this injury/oil spill/disclosure of customer information is totally his fault and not the company’s.
|
# ? Mar 23, 2021 20:30 |