|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82051 - sandbox/variadic_templates/sandbox/array_dyn
From: cppljevans_at_[hidden]
Date: 2012-12-17 12:18:19
Author: cppljevans
Date: 2012-12-17 12:18:18 EST (Mon, 17 Dec 2012)
New Revision: 82051
URL: http://svn.boost.org/trac/boost/changeset/82051
Log:
Demo or reshape starting from 0 axis0 size.
This demo in response to:
From: gast128 <gast128_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.user
Subject: [Boost.MultiArray]: size question
Date: Mon, 17 Dec 2012 15:50:49 +0000 (UTC)
Lines: 15
Text files modified:
sandbox/variadic_templates/sandbox/array_dyn/array_dyn.cpp | 117 ++++++++++++++++++++++++++++-----------
1 files changed, 84 insertions(+), 33 deletions(-)
Modified: sandbox/variadic_templates/sandbox/array_dyn/array_dyn.cpp
==============================================================================
--- sandbox/variadic_templates/sandbox/array_dyn/array_dyn.cpp (original)
+++ sandbox/variadic_templates/sandbox/array_dyn/array_dyn.cpp 2012-12-17 12:18:18 EST (Mon, 17 Dec 2012)
@@ -3,13 +3,84 @@
//
#include "array_dyn.hpp"
+ template
+ < typename T
+ >
+ std::ostream&
+operator<<
+ ( std::ostream&sout
+ , std::vector<T>const&vec
+ )
+ {
+ sout<<"{ ";
+ for(unsigned i=0; i<vec.size(); ++i)
+ {
+ if(0<i) sout<<", ";
+ sout<<vec[i];
+ }
+ sout<<"}";
+ return sout;
+ }
+
int main(void)
{
- for(unsigned dir_op=dir_fwd; dir_op<unsigned(dir_rev+1); ++dir_op)
{
- std::cout<<"*************************\n";
+ #if 0
+ std::cout<<"*********general demo****************\n";
+ for(unsigned dir_op=dir_fwd; dir_op<unsigned(dir_rev+1); ++dir_op)
+ {
+ std::cout<<"*************************\n";
+ std::cout<<"dir_op="<<dir_op<<"\n";
+ array_dyn<int> ai(dirs(dir_op),{2,3,4});
+ unsigned const size=ai.my_data.size();
+ std::cout<<"my_data.size()="<<size<<"\n";
+ unsigned const value0=1000;
+ for( unsigned i=0; i<size; ++i)
+ {
+ ai.my_data[i]=value0+i;
+ }
+ unsigned const rank=ai.rank();
+ std::cout<<"rank="<<rank<<"\n";
+ std::cout<<"size()="<<ai.size()<<"\n";
+ for(unsigned i=0;i<rank;++i)
+ {
+ std::cout<<"stride("<<i<<")="<<ai.stride(i)<<"\n";
+ std::cout<<" size("<<i<<")="<<ai.size(i)<<"\n";
+ }
+ std::cout<<"ai.offset_at_indices(1,0,0)="<<ai.offset_at_indices({1,0,0})<<"\n";
+ std::cout<<"ai(1,0,0)="<<ai({1,0,0})<<"\n";
+ std::cout<<"ai.offset_at_indices(0,1,0)="<<ai.offset_at_indices({0,1,0})<<"\n";
+ std::cout<<"ai(0,1,0)="<<ai({0,1,0})<<"\n";
+ std::cout<<"ai.offset_at_indices(0,0,1)="<<ai.offset_at_indices({0,0,1})<<"\n";
+ std::cout<<"ai(0,0,1)="<<ai({0,0,1})<<"\n";
+ std::cout<<"ai.ok_indices(1,2,3)="<<ai.ok_indices({1,2,3})<<"\n";
+ typedef std::vector<unsigned> indices_t;
+ std::cout<<"ai.ok_indices(indices_t({0,0,0}))="<<ai.ok_indices(indices_t({0,0,0}))<<"\n";
+ std::cout<<"ai.ok_indices(1,2,4)="<<ai.ok_indices({1,2,4})<<"\n";
+ std::cout<<"ai.ok_indices(1,2,3,0)="<<ai.ok_indices({1,2,3,0})<<"\n";
+ unsigned offset=ai.offset_at_indices({1,2,3});
+ std::cout<<"ai.offset_at_indices(1,2,3)="<<offset<<"\n";
+ std::vector<unsigned> indices(ai.indices_at_offset(offset));
+ std::cout<<"indices_at_offset("<<offset<<")=\n";
+ for(unsigned i=0; i< indices.size(); ++i)
+ {
+ std::cout<<indices[i]<<" ";
+ }
+ std::cout<<"\n";
+ #if 1
+ std::cout<<"ai=\n";
+ std::cout<<ai<<".\n";
+ #endif
+ }
+ #endif
+ }
+ {
+ unsigned dir_op=dir_fwd;
+ std::cout<<"********reshape demo***********\n";
std::cout<<"dir_op="<<dir_op<<"\n";
- array_dyn<int> ai(dirs(dir_op),{2,3,4});
+ std::vector<unsigned> shape({0,3});
+ std::cout<<"shape="<<shape<<"\n";
+ array_dyn<int> ai(dirs(dir_op),shape);
unsigned const size=ai.my_data.size();
std::cout<<"my_data.size()="<<size<<"\n";
unsigned const value0=1000;
@@ -17,38 +88,18 @@
{
ai.my_data[i]=value0+i;
}
- unsigned const rank=ai.rank();
- std::cout<<"rank="<<rank<<"\n";
- std::cout<<"size()="<<ai.size()<<"\n";
- for(unsigned i=0;i<rank;++i)
- {
- std::cout<<"stride("<<i<<")="<<ai.stride(i)<<"\n";
- std::cout<<" size("<<i<<")="<<ai.size(i)<<"\n";
- }
- std::cout<<"ai.offset_at_indices(1,0,0)="<<ai.offset_at_indices({1,0,0})<<"\n";
- std::cout<<"ai(1,0,0)="<<ai({1,0,0})<<"\n";
- std::cout<<"ai.offset_at_indices(0,1,0)="<<ai.offset_at_indices({0,1,0})<<"\n";
- std::cout<<"ai(0,1,0)="<<ai({0,1,0})<<"\n";
- std::cout<<"ai.offset_at_indices(0,0,1)="<<ai.offset_at_indices({0,0,1})<<"\n";
- std::cout<<"ai(0,0,1)="<<ai({0,0,1})<<"\n";
- std::cout<<"ai.ok_indices(1,2,3)="<<ai.ok_indices({1,2,3})<<"\n";
- typedef std::vector<unsigned> indices_t;
- std::cout<<"ai.ok_indices(indices_t({0,0,0}))="<<ai.ok_indices(indices_t({0,0,0}))<<"\n";
- std::cout<<"ai.ok_indices(1,2,4)="<<ai.ok_indices({1,2,4})<<"\n";
- std::cout<<"ai.ok_indices(1,2,3,0)="<<ai.ok_indices({1,2,3,0})<<"\n";
- unsigned offset=ai.offset_at_indices({1,2,3});
- std::cout<<"ai.offset_at_indices(1,2,3)="<<offset<<"\n";
- std::vector<unsigned> indices(ai.indices_at_offset(offset));
- std::cout<<"indices_at_offset("<<offset<<")=\n";
- for(unsigned i=0; i< indices.size(); ++i)
- {
- std::cout<<indices[i]<<" ";
- }
- std::cout<<"\n";
- #if 1
std::cout<<"ai=\n";
std::cout<<ai<<".\n";
- #endif
+ shape[0]=1;
+ std::cout<<"shape="<<shape<<"\n";
+ ai.reshape(shape);
+ std::cout<<"ai=\n";
+ std::cout<<ai<<".\n";
+ shape[0]=5;
+ std::cout<<"shape="<<shape<<"\n";
+ ai.reshape(shape);
+ std::cout<<"ai=\n";
+ std::cout<<ai<<".\n";
}
return 0;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk