Arithmetic#
2025-10-17
7 min read time
Addition#
#include <raft/linalg/add.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void add(
)# Elementwise add operation.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] raft::resources
in1 – [in] First Input
in2 – [in] Second Input
out – [out] Output
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void add_scalar( - raft::resources const &handle,
- InType in,
- OutType out,
- raft::device_scalar_view<const typename InType::value_type, ScalarIdxType> scalar
Elementwise addition of device scalar to input.
Elementwise addition of host scalar to input.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
- Parameters:
handle – [in] raft::resources
in – [in] Input
scalar – [in] raft::device_scalar_view
out – [in] Output
handle – [in] raft::resources
in – [in] Input
scalar – [in] raft::host_scalar_view
out – [in] Output
Binary Op#
#include <raft/linalg/binary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void binary_op(
)# perform element-wise binary operation on the input arrays
Note
Lambda must be a functor with the following signature:
OutType func(const InType& val1, const InType& val2);- Template Parameters:
InType – Input Type raft::device_mdspan
Lambda – the device-lambda performing the actual operation
OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] raft::resources
in1 – [in] First input
in2 – [in] Second input
out – [out] Output
op – [in] the device-lambda
Division#
#include <raft/linalg/divide.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void divide_scalar( - raft::resources const &handle,
- InType in,
- OutType out,
- raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar
Elementwise division of input by host scalar.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
- Parameters:
handle – [in] raft::resources
in – [in] Input
scalar – [in] raft::host_scalar_view
out – [out] Output
Multiplication#
#include <raft/linalg/multiply.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void multiply_scalar( - raft::resources const &handle,
- InType in,
- OutType out,
- raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar
Element-wise multiplication of host scalar.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
- Parameters:
handle – [in] raft::resources
in – [in] the input buffer
out – [out] the output buffer
scalar – [in] the scalar used in the operations
Power#
#include <raft/linalg/power.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void power(
)# Elementwise power operation on the input buffers.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] raft::resources
in1 – [in] First Input
in2 – [in] Second Input
out – [out] Output
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void power_scalar( - raft::resources const &handle,
- InType in,
- OutType out,
- const raft::host_scalar_view<const typename InType::value_type, ScalarIdxType> scalar
Elementwise power of host scalar to input.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
- Parameters:
handle – [in] raft::resources
in – [in] Input
out – [out] Output
scalar – [in] raft::host_scalar_view
Square Root#
#include <raft/linalg/sqrt.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void sqrt(
)# Elementwise sqrt operation.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] raft::resources
in – [in] Input
out – [out] Output
Subtraction#
#include <raft/linalg/subtract.cuh>
namespace raft::linalg
-
template<typename InType, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void subtract(
)# Elementwise subtraction operation on the input buffers.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
- Parameters:
handle – raft::resources
in1 – [in] First Input
in2 – [in] Second Input
out – [out] Output
-
template<typename InType, typename OutType, typename ScalarIdxType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void subtract_scalar( - raft::resources const &handle,
- InType in,
- OutType out,
- raft::device_scalar_view<const typename InType::element_type, ScalarIdxType> scalar
Elementwise subtraction of device scalar to input.
Elementwise subtraction of host scalar to input.
- Template Parameters:
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
InType – Input Type raft::device_mdspan
OutType – Output Type raft::device_mdspan
ScalarIdxType – Index Type of scalar
- Parameters:
handle – [in] raft::resources
in – [in] Input
out – [out] Output
scalar – [in] raft::device_scalar_view
handle – [in] raft::resources
in – [in] Input
out – [out] Output
scalar – [in] raft::host_scalar_view
Ternary Op#
#include <raft/linalg/ternary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void ternary_op(
)# perform element-wise ternary operation on the input arrays
Note
Lambda must be a functor with the following signature:
OutType func(const InType& val1, const InType& val2, const InType& val3);- Template Parameters:
InType – Input Type raft::device_mdspan
Lambda – the device-lambda performing the actual operation
OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] raft::resources
in1 – [in] First input
in2 – [in] Second input
in3 – [in] Third input
out – [out] Output
op – [in] the device-lambda
Unary Op#
#include <raft/linalg/unary_op.cuh>
namespace raft::linalg
-
template<typename InType, typename Lambda, typename OutType, typename = raft::enable_if_input_device_mdspan<InType>, typename = raft::enable_if_output_device_mdspan<OutType>>
void unary_op(
)# Perform an element-wise unary operation into the output array.
- Template Parameters:
InType – Input Type raft::device_mdspan
Lambda – Device lambda performing the actual operation, with the signature
out_value_t func(const in_value_t& val);OutType – Output Type raft::device_mdspan
- Parameters:
handle – [in] The raft handle
in – [in] Input
out – [out] Output
op – [in] Device lambda
-
template<typename OutType, typename Lambda, typename = raft::enable_if_output_device_mdspan<OutType>>
void write_only_unary_op(
)# Perform an element-wise unary operation on the input index into the output array.
Note
This operation is deprecated. Please use map_offset in
raft/linalg/map.cuhinstead.- Template Parameters:
OutType – Output Type raft::device_mdspan
Lambda – Device lambda performing the actual operation, with the signature
void func(out_value_t* out_location, index_t idx);
- Parameters:
handle – [in] The raft handle
out – [out] Output
op – [in] Device lambda