legate::Scalar#
-
class Scalar#
A type-erased container for scalars.
A
Scalarcan be owned or shared, depending on whether it owns the backing allocation: If aScalaris shared, it does not own the allocation and any of its copies are also shared. If aScalaris owned, it owns the backing allocation and releases it upon destruction. Any copy of an ownedScalaris owned as well.Public Functions
-
Scalar(const Type &type, const void *data, bool copy = false)#
Creates a shared
Scalarwith an existing allocation. The caller is responsible for passing in a sufficiently big allocation.- Parameters:
type –
Typeof the scalardata – Allocation containing the data.
copy – If
true, the scalar copies the data stored in the allocation and becomes owned.
-
template<typename T, typename = std::enable_if_t<!std::is_convertible_v<T, std::string> && !std::is_same_v<std::decay_t<T>, InternalSharedPtr<detail::Scalar>>>>
explicit Scalar( - const T &value
Creates an owned
Scalarfrom a scalar value.- Template Parameters:
T – The scalar type to wrap
- Parameters:
value – A scalar value to create a
Scalarwith
-
template<typename T>
Scalar(const T &value, const Type &type)# Creates an owned
Scalarof a specified type from a scalar value.
-
explicit Scalar(std::string_view string)#
Creates an owned
Scalarfrom astd::string_view. The value from the original string will be copied.- Parameters:
string – The
std::string_viewto create aScalarwith
-
template<typename T>
explicit Scalar(Span<const T> values)# Creates an owned
Scalarfrom aSpanof scalars. The values in the input span will be copied.- Parameters:
values – Values to create a
Scalarwith in a vector.
-
template<typename T>
explicit Scalar(const std::vector<T> &values)# Creates an owned
Scalarfrom astd::vectorof scalars. The values in the input vector will be copied.- Parameters:
values – Values to create a
Scalarwith in a vector.
-
template<typename T>
explicit Scalar(const tuple<T> &values)# Creates an owned
Scalarfrom atupleof scalars. The values in the inputtuplewill be copied.- Parameters:
values – Values to create a
Scalarwith in atuple
-
explicit Scalar(const std::vector<bool> &values)#
Creates an owned
Scalarfrom astd::vector<bool>. The values in the input vector will be copied.Like most things with
std::vector<bool>, this construction is not particularly efficient. In order to be copied into theScalar, the vector will first be “expanded” into a temporarystd::vector<std::uint8_t>, resulting in multiple copies being performed.The user is therefore highly encouraged to use
std::vector<std::uint8_t>directly instead ofstd::vector<bool>(if possible), especially if such vectors are commonly passed to tasks.- Parameters:
values – The values with which to create the
Scalar.
-
std::size_t size() const#
Returns the size of allocation for the
Scalar.- Returns:
The size of allocation in bytes
-
template<typename VAL>
VAL value() const# Returns a copy of the value stored in this
Scalar.1) size of the scalar does not match with size of
VAL, 2) the scalar holds a string butVALisn’tstd:stringorstd:string_view, or 3) the inverse; i.e.,VALisstd:stringorstd:string_viewbut the scalar’s type isn’t string
-
template<typename VAL>
Span<const VAL> values() const# Returns values stored in the
Scalar. If theScalardoes not have a fixed array type, a unit span will be returned.1) the scalar has a fixed array type whose element type has a different size from
VAL, 2) the scalar holds a string and size ofVALisn’t 1 byte, 3) the scalar’s type isn’t a fixed array type and the size is different from size ofVAL- Throws:
std::invalid_argument – If one of the following cases is encountered:
- Returns:
Values stored in the
Scalar
-
Scalar(const Type &type, const void *data, bool copy = false)#