I have a (9x9) valarray
std::valarray<i nt> va(81);
va = 0; // fil all elements with zeros
I am taking row slices like that:
std::slice_arra y<int> slr = va[std::slice(r-1,9,9)]; // r = row; a
value between 1 and 9
std::valarray<i nt> row = slr;
and column slices like that:
std::slice_arra y<int> slc = va[std::slice((c-1)*9, 9, 1)]; // c =
col; a value between 1 and 9
std::valarray<i nt> col = slc;
which does work without any problem.
But when I try to extract a subarray:
size_t len[] = {3,3};
size_t dist[] = {9, 1};
std::valarray<s ize_t> lens(len, 2);
std::valarray<s ize_t> dists(dist, 2);
int st_r = ((r-1)/3)*3+1; // r (s.o.)
int st_c = ((c-1)/3)*3+1; // c (s.o.)
int st_i = rc2i( st_r, st_c ); // int rc2i(int row, int col) {
return (col-1) * 9 + (row-1); }
std::gslice_arr ay<int> gslsa = va[std::gslice(st_ i, lens, dists)];
std::valarray<i nt> subarray = gslsa;
the first element is always the value of element 0 of the valarray,
even if my function rc2i calculates the correct values for st_i!
Is it likely, that there is a bug in the sources of the library or did
I just not fully understand the concept of gslice_array/gslice?
I mean I'am sure I didn't understant it completely but I don't see the
mistake I possibly make! :-)
Hoping for some hints.
bye,
Oliver 1 2068
Oliver Block wrote: I have a (9x9) valarray
std::valarray<i nt> va(81); va = 0; // fil all elements with zeros
I am taking row slices like that:
std::slice_arra y<int> slr = va[std::slice(r-1,9,9)]; // r = row; a value between 1 and 9 std::valarray<i nt> row = slr;
and column slices like that:
std::slice_arra y<int> slc = va[std::slice((c-1)*9, 9, 1)]; // c = col; a value between 1 and 9 std::valarray<i nt> col = slc;
which does work without any problem.
But when I try to extract a subarray:
size_t len[] = {3,3}; size_t dist[] = {9, 1}; std::valarray<s ize_t> lens(len, 2); std::valarray<s ize_t> dists(dist, 2);
int st_r = ((r-1)/3)*3+1; // r (s.o.) int st_c = ((c-1)/3)*3+1; // c (s.o.) int st_i = rc2i( st_r, st_c ); // int rc2i(int row, int col) { return (col-1) * 9 + (row-1); }
std::gslice_arr ay<int> gslsa = va[std::gslice(st_ i, lens, dists)]; std::valarray<i nt> subarray = gslsa;
the first element is always the value of element 0 of the valarray, even if my function rc2i calculates the correct values for st_i!
Is it likely, that there is a bug in the sources of the library or did I just not fully understand the concept of gslice_array/gslice?
I mean I'am sure I didn't understant it completely but I don't see the mistake I possibly make! :-)
Hoping for some hints.
Well your code worked for me. However it does have one error in it. You
are not meant to create gslice_array or slice_array objects directly.
std::valarray<i nt> row = va[std::slice(r-1,9,9)];
std::valarray<i nt> subarray = va[std::gslice(st_ i, lens, dists)];
is how you should do it. Try that and see if it works.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian Brechbühler |
last post by:
The template std::valarray behaves pretty much like a mathematical
vector. Arithmetic operators apply elementwise. Now I'd like to extend
this to a user-defined type, e.g., complex.
Multiplying a double by a complex number gives a complex number. Now I
would like to multiply a valarray of doubles by a complex number and get
a valarray of...
|
by: Steven T. Hatton |
last post by:
I bought Josuttis's book on the repeated recommendations of people in this
newsgroup.
http://www.josuttis.com/libbook/
One of the first things I looked up was the std::valarray<>. And what I
read is that he questions the worth of the valarray.
http://www.cs.bsu.edu/homepages/peb/cplusplus/headers/valarray.htm
|
by: Peter |
last post by:
Hi everybody,
I am unfortunately stuck with a probably very simple problem. I made a
class called Particle with a valarray (STL) as a class member.
The code for the class goes like this:
class Particle {
private:
valarray<double>* position;
|
by: ES Kim |
last post by:
comp.std.c++ would be a better place for this question.
Forgive me, but I can't post anything on moderated newsgroups
for some reason.
valarray doesn't have iterators of its own, which makes functions
in <algorithm> less useful. &v works like an iterator, but even this
trick doesn't work for const valarray's.
void f(const...
|
by: ES Kim |
last post by:
Here's a code fragment from TC++PL, p679:
void f(valarray<double>& v)
{
size_t i = { 3, 2, 1, 0 };
valarray<size_t> index(i, 4);
valarray<double> vv = log(v);
}
Every compiler I tried including Comeau produced an error message
| |
by: Michael Hopkins |
last post by:
Hi all
I have a subclass of valarray<T> thus
template <typename T>
class uo_val : public std::valarray<T>
{
public:
uo_val ( ) : std::valarray<T>() {}
uo_val (const int sz ) : std::valarray<T>( sz ) {}
|
by: Dack |
last post by:
Hi,
I want to track memory leaks in my application (that is using <valarray>).
I used the following code:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
But then, when I include <valarray> the compiler raises the following errors :
|
by: Jim |
last post by:
Hi,
I want to declare that that a valarray of a certain name exist at the
beginning of some code, but I can't instatiate it until I've read in
some parameters later on in a for loop i.e.
int main(int argc, char * argv)
{
valarray<floatdata;
float init=0;
for(int i=0; i<argc; i++)
|
by: john |
last post by:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is
mentioned:
"valarray operator-() const; // result= -v for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains the need of
this "operator+".
|
by: john |
last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned:
"Maybe your first idea for a two-dimensional vector was something like this:
class Matrix {
valarray< valarray<doublev;
public:
// ...
};
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |