7Vector<T> Vector<T>::conj()
const {
8 static_assert(is_complex_v<T>,
"conj() only available for complex Vector");
9 std::vector<T> conj_data;
10 conj_data.reserve(this->size());
11 for (std::size_t i = 0; i < this->size(); ++i) {
12 conj_data.push_back(std::conj(this->data()[i]));
14 return Vector<T>{std::move(conj_data)};
18auto Vector<T>::real()
const {
19 static_assert(is_complex_v<T>,
"real() only available for complex Vector");
20 std::vector<typename T::value_type> real_data;
21 real_data.reserve(this->size());
22 for (std::size_t i = 0; i < this->size(); ++i) {
23 real_data.push_back(std::real(this->data()[i]));
25 return Vector<typename T::value_type>{std::move(real_data)};
28auto Vector<T>::imag()
const {
29 static_assert(is_complex_v<T>,
"imag() only available for complex Vector");
30 std::vector<typename T::value_type> imag_data;
31 imag_data.reserve(this->size());
32 for (std::size_t i = 0; i < this->size(); ++i) {
33 imag_data.push_back(std::imag(this->data()[i]));
35 return Vector<typename T::value_type>{std::move(imag_data)};
38auto Vector<T>::complex()
const {
39 static_assert(!is_complex_v<T>,
"complex() only available for real Vector");
41 std::vector<std::complex<T>> new_data;
42 new_data.reserve(this->m_data.size());
43 for (std::size_t i = 0; i < this->m_data.size(); ++i) {
44 new_data.push_back(this->m_data[i]);
46 return Vector<std::complex<T>>{std::move(new_data)};
51Vector<T> &Vector<T>::operator+=(
const Vector<T> &rhs) {
52 assert(this->rows() == rhs.rows() && this->cols() == rhs.cols());
54 this->m_data += rhs.m_data;
58Vector<T> &Vector<T>::operator-=(
const Vector<T> rhs) {
59 assert(this->rows() == rhs.rows() && this->cols() == rhs.cols());
61 this->m_data -= rhs.m_data;
65Vector<T> &Vector<T>::operator*=(
const T x) {
71Vector<T> &Vector<T>::operator/=(
const T x) {
80 const auto size = std::max(this->rows(), this->cols());
81 if constexpr (std::is_same_v<T, double>) {
82 return gsl_vector_view_array(this->data(), size);
83 }
else if constexpr (std::is_same_v<T, float>) {
84 return gsl_vector_float_view_array(this->data(), size);
85 }
else if constexpr (std::is_same_v<T, std::complex<double>>) {
86 return gsl_vector_complex_view_array(
87 reinterpret_cast<double *
>(this->data()), size);
88 }
else if constexpr (std::is_same_v<T, std::complex<float>>) {
89 return gsl_vector_complex_float_view_array(
90 reinterpret_cast<float *
>(this->data()), size);
93 "as_gsl_view only for double/float (or complex double/float)");
99 const auto size = std::max(this->rows(), this->cols());
100 if constexpr (std::is_same_v<T, double>) {
101 return gsl_vector_const_view_array(this->data(), size);
102 }
else if constexpr (std::is_same_v<T, float>) {
103 return gsl_vector_float_const_view_array(this->data(), size);
104 }
else if constexpr (std::is_same_v<T, std::complex<double>>) {
105 return gsl_vector_complex_const_view_array(
106 reinterpret_cast<const double *
>(this->data()), size);
107 }
else if constexpr (std::is_same_v<T, std::complex<float>>) {
108 return gsl_vector_complex_float_const_view_array(
109 reinterpret_cast<const float *
>(this->data()), size);
112 "as_gsl_view only for double/float (or complex double/float)");
auto as_gsl_view()
Returns gsl_vector_view (or _float_view, _complex_view, _complex_float_view). Call ....
Definition Vector.ipp:79
Defines Matrix, Vector classes, and linear some algebra functions.
Definition Matrix.hpp:26
namespace qip::overloads provides operator overloads for std::vector
Definition Vector.hpp:450