473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

boost::multi_array and variable assignment

Hello!

I am trying to use boost::multi_array and want to create a view where I am
lowering the number of dimensions, but I wish the dimension to be reduced
to be decided at runtime.

I have a vector of integers and this vector size is the same as the number
of dimensions. If the vector [1] value is -1, then the first dimension
will have all values (i.e. range ()), otherwise it will be a number
indicating what slice to use.

You can see in case 2 what I have tried and maybe what I am trying to do.
Case 3 and 4 I am hard coding the dimensions where I want all values, which
does work, but I'd like to get rid of the hard-codedness and make this more
generic.

Furthermore, I have a one dimensional array of values which I am
"converting" to a boost::multi_array so I can slice into it with the views.
I won't know the dimensions until I read the data. Is there a better more
generic way of doing this? Something like a pointer to a N-dimensional
structure where I can just use the view?

Thanks in advance for any ideas!

Joey

Here is my code:

{
double ret_val;
typedef boost::multi_array_types::index_range range;

const VariableInfo &vinfo = GetVariable (si._sensor);
SubSensorType local_subsensors (si._subsensors);
assert (local_subsensors.size () == vinfo._sizes.size ());
switch (vinfo._sizes.size ()) {
case 0 : ret_val = vals [0];
break;
case 1 : { // one-d array
ret_val = (vals [whichPosition]);
}
break;

// Now we get into slices, find the subsensor element that has -1, and
// create a slice along that dimension

case 2 : { // two-dimensional array
typedef boost::const_multi_array_ref <double, 2array_type;
array_type::index_gen indices;

array_type multi_array (&(vals [0]), vinfo._sizes);
/*

This doesn't work!

array_type::const_array_view <1>::type OneDView;
if (local_subsensors [0] == -1)
OneDView = multi_array [indices [range ()]
[local_subsensors [1]]];
else
if (local_subsensors [1] == -1)
OneDView = multi_array [indices [local_subsensors [0]
[range ()]]];

ret_val = (OneDView [whichPosition]);
*/
}
break;
case 3 : { // three-dimensional array

typedef boost::const_multi_array_ref <double, 3array_type;
array_type::index_gen indices;

array_type multi_array (&(vals [0]), vinfo._sizes);
array_type::const_array_view <1>::type OneDView =
multi_array [indices [local_subsensors [0]]
[local_subsensors [1]]
[range ()]];
ret_val = (OneDView [whichPosition]);
}
break;
case 4 : { // four-dimensional array
typedef boost::const_multi_array_ref <double, 4array_type;
array_type::index_gen indices;

array_type multi_array (&(vals [0]), vinfo._sizes);
array_type::const_array_view <1>::type OneDView =
multi_array [indices [local_subsensors [0]]
[local_subsensors [1]]
[local_subsensors [2]]
[range ()]];

ret_val = (OneDView [whichPosition]);
}
break;
default : assert (vinfo._sizes.size () < 4);

}
return (ret_val);
}
Jun 27 '08 #1
0 1314

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lars Schouw | last post by:
Guys I want to use the boost matrix and found out that I have to know the size of the matrix when I construct it. (except from resizing and loosing my data). Is there any way I can add more...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
16
by: Jeff Flinn | last post by:
At the risk of raising the OT ire of some here, I'd like to know what might be done to raise the awareness of the boost libraries. I've found boost and it's libraries invaluable in my work for ~5...
2
by: toton | last post by:
Hi, I am trying to use boost::range with one of my own container class, and having some problem. I am missing some usage of range. Can anyone suggest a proper way for it ? To show the problem...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
1
by: marcomoeller | last post by:
Hi, I whant to write an function (ore overloading the class) which is able to trace out an row of the Array. So the function becomes an array of Dim n and returns one of Dim n-1. something...
0
by: suram.sunil | last post by:
Is there a way to create a generic N-dimensional array using the multi_array containers assuming no knowledge of the dimensionality or the shape during while creating it? Any help is...
3
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using...
19
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.