Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
gslice_array.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <valarray.h> // Includes valarray and provides stream inserter.
31#include <examples.h> // Generic header for all examples.
32
33typedef std::valarray<int> valarray_t;
34
35int main(void) {
36
37 valarray_t::value_type
38 ibuf[22] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
39 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
40
41 // Create a valarray of ints
42 valarray_t vi (ibuf,(sizeof ibuf / sizeof *ibuf));
43
44 // Print out the valarray
45 std::cout << "original valarray vi:\n\n" << vi << "\n\n";
46
47 // Get a two dimensional diagonal slice out of the middle
48 std::size_t length_ary[] = {4, 2};
49 std::size_t stride_ary[] = {4, 6};
50
51 std::valarray<std::size_t> length_val(length_ary, 2);
52 std::valarray<std::size_t> stride_val(stride_ary, 2);
53
54
55 // Print out the slices starting at positions 0 and 2 and respectively.
56 std::cout << "vi[gslice(0,[4,2],[4,6])]\n\n"
57 << vi[std::gslice(0,length_val,stride_val)] << "\n\n";
58
59 std::cout << "vi[gslice(2,[4,2],[4,6])]\n\n"
60 << vi[std::gslice(2,length_val,stride_val)] << "\n\n";
61
62 // Multiply the first slice by the second.
63 vi[std::gslice(0,length_val,stride_val)]
64 *= static_cast<valarray_t > (vi[std::gslice(2,length_val,stride_val)]);
65
66 std::cout << "vi[gslice(0,[4,2],[4,8])] *= vi[gslice(2,[4,2],[4,6])]\n\n"
67 << vi << std::endl;
68
69 return 0;
70
71}
72
std::valarray< int > valarray_t
Definition gslice.cpp:33
int main(void)
std::valarray< int > valarray_t