mirror of
https://github.com/boostorg/ublas.git
synced 2026-01-23 06:02:16 +00:00
fix macro for MSVC adding noexcept fixing test and making changes adding comparison test and adding resolving issue changing extents API fixing MSVC errors fixing MSVC error adding static prod function and adding std::array to static extents and static strides fixing get_number_list refactoring meta_function into type_traits and adding staic_traits for static_extents fixing extents_result_type_outer_prod and combining static_functions and functions removing unnecessary code and header file removing unnecessary forward declaration private member resize and adding removed constructors for matrix and vector changing size_t to std::size_t and fixing stride_t adding is_resizable type trait for tensor resizing improve documenting of is_resizable refactoring code changing msvc version in .yml changing toolset msvc-14.1 to msvc-14.16 and adding VSCLCOMPILER changing toolset msvc-14.2 and image to VS 2019 refactoring code and adding new matrix to appveyor adding VS 2019 with msvc-14.1 and disabling VS 2019 with msvc-14.2 and c++2a adding VS 2019 with msvc-14.2 and changing flag to latest removing VS 2019 with msvc-14.2 and c++17 and adding timeout to travis.yml travis_wait workaround removing VS 2017 from appveyor and refactoring code adding clang support for c++17 and c++20 and refactoring code changing dist to bionic and adding source link to clang 10 fixing travis, bugs and adding new examples fixing example bugs for msvc updating licence and adding test_expression to jamfile adding new tests, refactoring code and fixing bugs fix for msvc c++20 fixing memory problem due to BOOST_AUTO_TEST_SUITE macro defining after fixture removing const from tests and enabling test_tensor.cpp removing const from test_fixed_rank_expression_evaluation.cpp fixing msvc bug fixing msvc-14.2 bug for c++ latest where it cannot properly capture variables in lambda func disintegrating tests into smaller units reducing test_types for testing reducing tests reducing test_types for testing in operator arithmetic improving msvc warinings and separating test_function.cpp into it's own module
91 lines
3.3 KiB
C++
91 lines
3.3 KiB
C++
//
|
|
// Copyright (c) 2018-2020, Cem Bassoy, cem.bassoy@gmail.com
|
|
// Copyright (c) 2019-2020, Amit Singh, amitsingh19975@gmail.com
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See
|
|
// accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
// The authors gratefully acknowledge the support of
|
|
// Google and Fraunhofer IOSB, Ettlingen, Germany
|
|
//
|
|
|
|
#include <boost/numeric/ublas/tensor.hpp>
|
|
#include <boost/multiprecision/cpp_bin_float.hpp>
|
|
|
|
#include <ostream>
|
|
|
|
int main()
|
|
{
|
|
using namespace boost::numeric::ublas;
|
|
using namespace boost::multiprecision;
|
|
|
|
|
|
// creates a three-dimensional tensor with extents 3,4 and 2
|
|
// tensor A stores single-precision floating-point number according
|
|
// to the first-order storage format
|
|
using ftype = float;
|
|
auto A = tensor<ftype>{3,4,2};
|
|
|
|
// initializes the tensor with increasing values along the first-index
|
|
// using a single index.
|
|
auto vf = ftype(0);
|
|
for(auto i = 0u; i < A.size(); ++i, vf += ftype(1))
|
|
A[i] = vf;
|
|
|
|
// formatted output
|
|
std::cout << "% --------------------------- " << std::endl;
|
|
std::cout << "% --------------------------- " << std::endl << std::endl;
|
|
std::cout << "A=" << A << ";" << std::endl << std::endl;
|
|
|
|
// creates a four-dimensional tensor with extents 5,4,3 and 2
|
|
// tensor A stores complex floating-point extended double precision numbers
|
|
// according to the last-order storage format
|
|
// and initializes it with the default value.
|
|
using ctype = std::complex<cpp_bin_float_double_extended>;
|
|
auto B = tensor<ctype,dynamic_extents<>,last_order>(dynamic_extents<>{5,4,3,2},ctype{});
|
|
|
|
// initializes the tensor with increasing values along the last-index
|
|
// using a single-index
|
|
auto vc = ctype(0,0);
|
|
for(auto i = 0u; i < B.size(); ++i, vc += ctype(1,1))
|
|
B[i] = vc;
|
|
|
|
// formatted output
|
|
std::cout << "% --------------------------- " << std::endl;
|
|
std::cout << "% --------------------------- " << std::endl << std::endl;
|
|
std::cout << "B=" << B << ";" << std::endl << std::endl;
|
|
|
|
|
|
|
|
auto C = tensor<ctype,dynamic_extents<>,last_order>(B.extents());
|
|
// computes the complex conjugate of elements of B
|
|
// using multi-index notation.
|
|
for(auto i = 0u; i < B.size(0); ++i)
|
|
for(auto j = 0u; j < B.size(1); ++j)
|
|
for(auto k = 0u; k < B.size(2); ++k)
|
|
for(auto l = 0u; l < B.size(3); ++l)
|
|
C.at(i,j,k,l) = std::conj(B.at(i,j,k,l));
|
|
|
|
std::cout << "% --------------------------- " << std::endl;
|
|
std::cout << "% --------------------------- " << std::endl << std::endl;
|
|
std::cout << "C=" << C << ";" << std::endl << std::endl;
|
|
|
|
|
|
// computes the complex conjugate of elements of B
|
|
// using iterators.
|
|
auto D = tensor<ctype,dynamic_extents<>,last_order>(B.extents());
|
|
std::transform(B.begin(), B.end(), D.begin(), [](auto const& b){ return std::conj(b); });
|
|
std::cout << "% --------------------------- " << std::endl;
|
|
std::cout << "% --------------------------- " << std::endl << std::endl;
|
|
std::cout << "D=" << D << ";" << std::endl << std::endl;
|
|
|
|
// reshaping tensors.
|
|
auto new_extents = B.extents().base();
|
|
std::next_permutation( new_extents.begin(), new_extents.end() );
|
|
D.reshape( dynamic_extents<>(new_extents) );
|
|
std::cout << "% --------------------------- " << std::endl;
|
|
std::cout << "% --------------------------- " << std::endl << std::endl;
|
|
std::cout << "newD=" << D << ";" << std::endl << std::endl;
|
|
}
|