legate::Scalar#
-
class Scalar#
A type-erased container for scalars.
A
Scalar
can be owned or shared, depending on whether it owns the backing allocation: If aScalar
is shared, it does not own the allocation and any of its copies are also shared. If aScalar
is owned, it owns the backing allocation and releases it upon destruction. Any copy of an ownedScalar
is owned as well.Public Functions
-
Scalar(const Type &type, const void *data, bool copy = false)#
Creates a shared
Scalar
with an existing allocation. The caller is responsible for passing in a sufficiently big allocation.- Parameters:
type –
Type
of 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
Scalar
from a scalar value.- Template Parameters:
T – The scalar type to wrap
- Parameters:
value – A scalar value to create a
Scalar
with
-
template<typename T>
Scalar(const T &value, const Type &type)# Creates an owned
Scalar
of a specified type from a scalar value.
-
explicit Scalar(std::string_view string)#
Creates an owned
Scalar
from astd::string_view
. The value from the original string will be copied.- Parameters:
string – The
std::string_view
to create aScalar
with
-
template<typename T>
explicit Scalar(const std::vector<T> &values)# Creates an owned
Scalar
from astd::vector
of scalars. The values in the input vector will be copied.- Parameters:
values – Values to create a
Scalar
with in a vector.
-
template<typename T>
explicit Scalar(const tuple<T> &values)# Creates an owned
Scalar
from atuple
of scalars. The values in the inputtuple
will be copied.- Parameters:
values – Values to create a
Scalar
with in atuple
-
explicit Scalar(const std::vector<bool> &values)#
Creates an owned
Scalar
from 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 butVAL
isn’tstd:string
orstd:string_view
, or 3) the inverse; i.e.,VAL
isstd:string
orstd:string_view
but the scalar’s type isn’t string
-
template<typename VAL>
Span<const VAL> values() const# Returns values stored in the
Scalar
. If theScalar
does 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 ofVAL
isn’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)#