Files
cppdraft_translate/cppdraft/linalg/scaled/scaled.md
2025-10-25 03:02:53 +03:00

1.6 KiB

[linalg.scaled.scaled]

29 Numerics library [numerics]

29.9 Basic linear algebra algorithms [linalg]

29.9.8 Scaled in-place transformation [linalg.scaled]

29.9.8.3 Function template scaled [linalg.scaled.scaled]

1

#

The scaled function template takes a scaling factor alpha and an mdspan x, and returns a new read-only mdspan with the same domain as x, that represents the elementwise product of alpha with each element of x.

🔗

template<class ScalingFactor, class ElementType, class Extents, class Layout, class Accessor> constexpr auto scaled(ScalingFactor alpha, mdspan<ElementType, Extents, Layout, Accessor> x);

2

#

Let SA be scaled_accessor<ScalingFactor, Accessor>.

3

#

Returns: mdspan<typename SA::element_type, Extents, Layout, SA>(x.data_handle(), x.mapping(), SA(alpha, x.accessor()))

4

#

[Example 1: void test_scaled(mdspan<double, extents<int, 10>> x){auto x_scaled = scaled(5.0, x); for (int i = 0; i < x.extent(0); ++i) { assert(x_scaled[i] == 5.0 * x[i]); }} — end example]