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

46 lines
1.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[linalg.scaled.scaled]
# 29 Numerics library [[numerics]](./#numerics)
## 29.9 Basic linear algebra algorithms [[linalg]](linalg#scaled.scaled)
### 29.9.8 Scaled in-place transformation [[linalg.scaled]](linalg.scaled#scaled)
#### 29.9.8.3 Function template scaled [linalg.scaled.scaled]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12712)
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[.](#1.sentence-1)
[🔗](#lib:scaled)
` template<class ScalingFactor,
class ElementType, class Extents, class Layout, class Accessor>
constexpr auto scaled(ScalingFactor alpha, mdspan<ElementType, Extents, Layout, Accessor> x);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12728)
Let SA be scaled_accessor<ScalingFactor, Accessor>[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12731)
*Returns*: mdspan<typename SA::element_type, Extents, Layout, SA>(x.data_handle(), x.mapping(),
SA(alpha, x.accessor()))
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L12739)
[*Example [1](#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*]