I want to do some data-analysis, so I need at compile time unknown sized (large) arrays (of double or complex double). The number of dimensions is know at compile-time. What is the "right" way to do this in modern c++.
Asked
Active
Viewed 145 times
0
-
3`std::array` would be appropriate. – cigien Dec 04 '20 at 16:14
-
@cigien though so too at first, but isnt std::array fixed size? (which needs to be known at compile time) – lalala Dec 04 '20 at 16:15
-
4Oh, sorry, you only know the *number of dimensions* at compile-time. My bad. Use a `std::vector` then. – cigien Dec 04 '20 at 16:16
-
1Yes. C++ has very poor support for multidimensional arrays. Can you use third party libraries? – Paul Floyd Dec 04 '20 at 16:17
-
1There was an Herb Sutter talk where he advocated that the go-to container should usually be, "Just use a vector", unless you have a reason not to fall back to that simple default. It may take some searching to find the talk, as he's a prolific speaker. I think the timeframe was around 2011. – DavidO Dec 04 '20 at 16:17
-
1`std::vector` for run-time length, and reserve the length needed. – Blindy Dec 04 '20 at 16:17
-
For data analysis you may like to use https://pandas.pydata.org/ – Maxim Egorushkin Dec 04 '20 at 16:35
-
@MaximEgorushkin is pandas a c++ lib? – lalala Dec 04 '20 at 17:00
-
@PaulFloyd can. Which one do you recommend? – lalala Dec 04 '20 at 17:01
-
@cigien which I find so surprising. I mean one would expect std::array to solve exactly that or not? – lalala Dec 04 '20 at 17:03
-
2Check out the [Boost.MultiArray](https://www.boost.org/doc/libs/1_63_0/libs/multi_array/doc/user.html) – bloody Dec 04 '20 at 17:09
-
I'm not sure what you mean. `std::array` is designed to have a compile-time known size. Otherwise a `vector` is appropriate. I've closed the question as a duplicate of a post that covers your question quite nicely I think. – cigien Dec 04 '20 at 17:31
-
@lalala start with boost – Paul Floyd Dec 04 '20 at 17:33
-
@cigien whilst I expect that there are duplicates, the one that you linked is not a good answer. The standard library has _no_ easy to use dynamic multi-dimensional arrays. – Paul Floyd Dec 04 '20 at 17:35
-
@PaulFloyd I don't follow. If the number of dimensions is known at compile time, then `std::vector` is the right tool, and it's very easy to use. – cigien Dec 04 '20 at 17:37
-
@cigien Oh really so I can write `mat[x][y][z]` with an `std::vector`? That's good news. – Paul Floyd Dec 04 '20 at 17:38
-
@PaulFloyd Yes, absolutely. It needs to be `vector
>> mat;` of course, but that's not an issue since the dimensions are known. – cigien Dec 04 '20 at 17:44 -
@cigien vector
doesnt have a "plain" continguous data view, isnt it, also isnt it that there can be different length in each dimension, what I mean mat[1][2] can be a vector of length 1000, and mat[1][3] a vectore on length 20, isnt it? So this is not what people usually consider an array, isnt it? Also what answer I was looking for was what bloody commented (if it fulfiles the requirements after looking into it more in detail) – lalala Dec 04 '20 at 17:46 -
@lalala That's all true. Why didn't you say all of that in your question? Please edit the question to list *all* the requirements you want for the container, and then ping me, and I'll reopen the question. – cigien Dec 04 '20 at 18:00
-
1Go to 52 minutes in: https://channel9.msdn.com/Events/Build/2014/2-661 – DavidO Dec 04 '20 at 23:39