|
Boost : |
Subject: Re: [boost] different matrix library?
From: Edward Grace (ej.grace_at_[hidden])
Date: 2009-08-18 05:04:11
On 17 Aug 2009, at 20:48, DE wrote:
> Edward Grace wrote:
>>
>> It's conceptually not very difficult but describing the regions you
>> want can be tricky. The secret is the
>>
>> B(tgt{:}) = A(src{:})
>>
>> at the end which makes life very easy. How would one code this in C++
>> for example? Give it a bash - it's trickier than it looks (I'm happy
>> for tips to do this better by the way).
>>
>
> I see B is filled first, and values taken from A later on. In C++,
> would it
> make sense to do this assignment inline at the point where you
> define source
> and target ranges? Or, by adding (constructing) dimensions to B one
> at a
> time once you know what they should contain?
Hi Rutger,
I'm not sure I understand. Perhaps because, I'm guessing, you don't
understand what the
B(tgt{:}) = A(src{:})
is doing -- it took me a while to figure out when I first saw it.
Can you confirm that you are happy with the following - src on the
left tgt on the right?
ASCII ART ALERT
1D) (Yes, trivial)
+--+--+--+--+ +--+--+--+--+--+--+
|1 |2 |3 |4 | => |1 |2 | | |3 |4 | Two subregions to assign to
+--+--+--+--+ +--+--+--+--+--+--+
2D) (Easy enough...)
+--+--+--+--+ +--+--+--+--+--+--+--+
|1 |2 |3 |4 | |1 |2 | | | |3 |4 |
+--+--+--+--+ +--+--+--+--+--+--+--+
|5 |6 |7 |8 | => |5 |6 | | | |7 |8 | Four subregions to assign to
+--+--+--+--+ +--+--+--+--+--+--+--+
|9 |10|11|12| | | | | | | | |
+--+--+--+--+ +--+--+--+--+--+--+--+
|9 |10| | | |11|12|
+--+--+--+--+--+--+--+
I won't try and draw the 3D or 4D cases - it's too much work.
Suffice to say if you use your imagination, in the 3D case you end up
with repeats of the pattern above along the other dimension (out of
the screen). In the end the space in the 'middle' of the target cube
looks like the cross in [surrealism warning] Salvador Dali's "The
Crucifixion". Obviously in the 4D+ case this object is the N-
dimensional hyper-crucifix shape.
In ND one gets 2^N hypercubes to assign to, the number of subdomains
increases exponentially with the number of dimensions.
Ultimately of course the actual assignment can be described as a long
list of source and target indices assuming the mutidimensional arrays
can be flattened in to a single long vector - the equivalent question
is, what is the most straightforward way of building this list? I
think this is a tricky problem -- while it's possible I'd be
interested to see if the code that does the job can be made obvious
to understand.
The solution I gave in MATLAB, while not as tidy as it could be, is
straightforward to code and solves the N-dimensional copy/assignment
problem - the secret being the form of the last line.
How would *you* do this, elegantly, in C++? That's a genuine
question -- I'm curious because, quite frankly, it's foxed me for
ages and I would like to do this in C++! ;-)
(Hence my suggestion for some sort of assignment / indexing
gymnastics resource for people interested in this kind of weirdness)
Thanks,
-ed
------------------------------------------------
"No more boom and bust." -- Dr. J. G. Brown, 1997
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk