This is OK because it will be optimized without loop unrolling optimization in modern compilers
Brody Jackson
stop telling him to use a loop. If there is a fixed number of iterations then what he is doing is better because the compiler may not unroll his loop for optimization purposes, resulting in lots of wasteful comparison operations
Hunter Rogers
that's a terribly bloated way to do it.
Adam Gomez
i guess they must be flat in memory, I didn't' know that but I suppose it makes sense
Christopher Hernandez
this
Caleb White
So what's the problem? If the function is only called once it doesn't matter how well it is optimized. Don't tell me he wants to initialize his array a thousand times per second
Aiden Gomez
>This works, not really sure why: The absolute state of Jow Forums
Evan Mitchell
Depends on what you want to do with it. If you want to perform mathematical operations on the matrix, it is the best way. You include a header file, so it isn't bloat. It is generally very efficient.
Angel Morales
It is true that arrays of arrays have to be effectively laid out flat in memory, but the reason it works is just because the initializer syntax in C / C++ explicitly allows initializing members of nested arrays / structs without braces at every level. en.cppreference.com/w/c/language/struct_initialization#Nested_initialization
Grayson Sanchez
He wants to populate a two-dimensional array. If he wants to treat it like a matrix and transform it mathematically, he should use your method.
Unless it's a header-only lib or dynamically linked, then it results in bloated binaries when linked with the library you use.
The problem is that the compiler may not optimize out your loop. IIRC gcc and llvm+clang only unroll your loops at -O3 because it trades some binary size for speed. If you perform loop unrolling in the source for loops with fixed numbers of iterations, then the binaries will have this optimization even when compiled with no optimizations enabled.
If the function is called once you are right in saying that it doesn't matter too much for optimization, as it does not need to scale. This doesn't change the fact that it produces sub-optimal binaries.
Tyler Perry
Mathlet here, what's the difference?
Austin Sullivan
matrix is usually the 2D version calling it a multidimensional array is totally fine the first user is just being a sperg
Adam King
>i guess they must be flat in memory, I didn't' know that but I suppose it makes sense Yes, all elements in an array are consecutive. An array means you have a block of memory where you know the size of each elements, where it starts and hopefully the size of the array. You can also just pad the end with a zero and prey nobody goes beyond the limits of the matrix. The last option is the most compact, so this makes sense for computers. Solving the problem of accessing the data is trivial for the programmer, but it does not require many limitations to the matrix before you create a class which handles these things for you.
C style arrays are the worst possible data structure you can have, but it is a fundamental data structure you need in order to make other data structures.
James Reyes
If it was statically allocated like >int goal[3][3]; then for(int i=0; i
Thomas Morris
>Unless it's a header-only lib or dynamically linked, then it results in bloated binaries when linked with the library you use. Eigen is a header only library. It offers a ton of "bloat" in preprocessor commands, but since you don't have to write it doesn't really impact you. Eigen is THE matrix library for C++ for mathematical purposes. Obviously it doesn't make as much sense to use it if you want to use matrices for non math purposes like images or whatever you store in a matrix, then there are better libraries.
Jow Forums wants to use loops for everything they are very retard I saw them converting a O(1) problem into an O(n) they will never be hired as firmware developers so doesn't matter. If you need a constant matrix do something like
goal[3][3] = { {0,0}, {1,2}, {5,8} };
Isaac Perry
It's a trap
Jaxon Peterson
Premature optimization is the root of all evil.
Just stop
Hudson Perry
>Premature optimization is the root of all evil. dude, you wont ever be DonaldKnuth for repeating him, second its always good to use heuristics when coding to avoid large refactoring the only justification to not optimize is on investigation algorithms until you pass all the test cases.
Ian Cruz
>he thinks parroting knuth makes him elite guess what? there is absolutely no downside to this because it doesn't change testing/attack surface at all, has a negligible effect on binary size, and increases efficiency.
Owen Price
>It's another Jow Forums thinks they're smarter than the founder of algorithmic analysis episode
>guess what? there is absolutely no downside to this because it doesn't change testing/attack surface at all, has a negligible effect on binary size, and increases efficiency.