<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
nrm2.hpp
Go to the documentation of this file.
1
8//
9// Copyright (c) 2017-2021, University of Tennessee. All rights reserved.
10// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
11//
12// This file is part of <T>LAPACK.
13// <T>LAPACK is free software: you can redistribute it and/or modify it under
14// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
15
16#ifndef TLAPACK_BLAS_NRM2_HH
17#define TLAPACK_BLAS_NRM2_HH
18
21
22namespace tlapack {
23
32template <TLAPACK_VECTOR vector_t, disable_if_allow_optblas_t<vector_t> = 0>
33auto nrm2(const vector_t& x)
34{
36
37 // scaled sum of squares
38 real_t scl(1);
39 real_t sumsq(0);
40 lassq(x, scl, sumsq);
41
42 return real_t(scl * sqrt(sumsq));
43}
44
45#ifdef TLAPACK_USE_LAPACKPP
46
47template <TLAPACK_LEGACY_VECTOR vector_t,
48 enable_if_allow_optblas_t<vector_t> = 0>
49auto nrm2(vector_t const& x)
50{
51 // Legacy objects
52 auto x_ = legacy_vector(x);
53
54 // Constants to forward
55 const auto& n = x_.n;
56
57 return ::blas::nrm2(n, x_.ptr, x_.inc);
58}
59
60#endif
61
62} // namespace tlapack
63
64#endif // #ifndef TLAPACK_BLAS_NRM2_HH
#define TLAPACK_LEGACY_VECTOR
Macro for tlapack::concepts::LegacyVector compatible with C++17.
Definition concepts.hpp:954
void lassq(const vector_t &x, real_type< type_t< vector_t > > &scale, real_type< type_t< vector_t > > &sumsq, abs_f absF)
Updates a sum of squares represented in scaled form.
Definition lassq.hpp:49
auto nrm2(const vector_t &x)
Definition nrm2.hpp:33
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113