1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Reductions
==========
Sum
---
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::sum(a, {1});
std::cout << r0 << std::endl;
// Outputs {6, 15}
xt::xarray<int> r1 = xt::sum(a);
std::cout << r1 << std::endl;
// Outputs {21}, i.e. r1 is a 0D-tensor
int r2 = xt::sum(a)();
std::cout << r2 << std::endl;
// Outputs 21
auto r3 = xt::sum(a, {1});
std::cout << r3 << std::endl;
// Outputs {6, 15}, but r3 is an unevaluated expression
// the values are computed upon each access
auto r4 = xt::sum<long int>(a, {1});
// r4 holds long int values
auto r5 = xt::sum<short>(a, {1});
// r5 holds int values
auto r6 = xt::sum<xt::big_promote_value_type_t<decltype(a)>>(a, {1});
// r6 holds long long int values
Prod
----
.. code::
xt::xarray<int> a = {{1, 2}, {3, 4}};
xt::xarray<int> r0 = xt::prod(a, {1});
xt::xarray<int> r1 = xt::prod(a);
int r2 = xt::prod(a)();
auto r3 = xt::prod(a, {0});
auro r4 = xt::prod<long int>(a, {0});
auto r5 = xt::prod<xt::big_promote_value_type_t<decltype(a)>>(a, {1});
Mean
----
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::mean(a, {1});
xt::xarray<int> r1 = xt::mean(a);
int r2 = xt::mean(a)();
auto r3 = xt::mean(a, {0});
Variance
--------
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::variance(a, {1});
xt::xarray<int> r1 = xt::variance(a);
int r2 = xt::variance(a)();
auto r3 = xt::variance(a, {0});
Standard deviation
------------------
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::stddev(a, {1});
xt::xarray<int> r1 = xt::stddev(a);
int r2 = xt::stddev(a)();
auto r3 = xt::stddev(a, {0});
Diff
----
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::diff(a, 1, {0});
std::cout << r0 << std::endl;
// Outputs {{1, 1}, {1, 1}}
Amax
----
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::amax(a, {1});
std::cout << r0 << std::endl;
// Outputs {3, 6}
Amin
----
.. code::
xt::xarray<int> a = {{1, 2, 3}, {4, 5, 6}};
xt::xarray<int> r0 = xt::amin(a, {0});
std::cout << r0 << std::endl;
// Outputs {1, 2, 3}
Norms
-----
.. code::
xt::xarray<double> a = {{1., 2., 3.}, {4., 5., 6.}};
xt::xarray<double> b0 = xt::norm_l0(a, {1});
xt::xarray<double> b1 = xt::norm_l1(a, {1});
xt::xarray<double> b2 = xt::norm_sq(a, {1});
xt::xarray<double> b3 = xt::norm_l2(a, {1});
xt::xarray<double> b4 = xt::norm_linf(a, {1});
xt::xarray<double> b5 = xt::norm_lp_to_p(a, {1});
xt::xarray<double> b6 = xt::norm_lp(a, {1});
xt::xarray<double> b7 = xt::norm_induced_l1(a, {1});
xt::xarray<double> b8 = xt::norm_induced_linf(a, {1});
Accumulating functions
----------------------
.. code::
xt::xarray<double> a = {{1., 2., 3.}, {4., 5., 6.}};
xt::xarray<double> b0 = xt::cumsum(a, {1});
std::cout << b0 << std::endl;
// Outputs {{1., 3., 6.}, {4., 9., 15.}}
xt::xarray<double> b1 = xt::cumprod(a, {1});
std::cout << b1 << std::endl;
// Outputs {{1., 2., 6.}, {4., 20., 120.}}
|