|
Mila 0.13.48
Deep Neural Network Library
|
CPU specialization of TensorOps for mathematical operations. More...

Static Public Member Functions | |
| template<TensorDataType TDataType, typename TMemoryResource> requires isValidTensor<TDataType, TMemoryResource> | |
| static void | add (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, Tensor< TDataType, TMemoryResource > &result, IExecutionContext *exec_context=nullptr) |
| Element-wise addition of two tensors (CPU implementation). | |
| template<TensorDataType TDataType, typename TMemoryResource> requires isValidTensor<TDataType, TMemoryResource> | |
| static void | divide (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, Tensor< TDataType, TMemoryResource > &result, IExecutionContext *exec_context=nullptr) |
| Element-wise division of two tensors (CPU implementation). | |
| template<TensorDataType TDataType, typename TMemoryResource> requires isValidTensor<TDataType, TMemoryResource> | |
| static void | multiply (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, Tensor< TDataType, TMemoryResource > &result, IExecutionContext *exec_context=nullptr) |
| Element-wise multiplication of two tensors (CPU implementation). | |
| template<TensorDataType TDataType, typename TMemoryResource> requires isValidTensor<TDataType, TMemoryResource> | |
| static void | subtract (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, Tensor< TDataType, TMemoryResource > &result, IExecutionContext *exec_context=nullptr) |
| Element-wise subtraction of two tensors (CPU implementation). | |
| template<TensorDataType TDataType, typename TMemoryResource> requires isValidTensor<TDataType, TMemoryResource> | |
| static float | sum (const Tensor< TDataType, TMemoryResource > &tensor, IExecutionContext *exec_context=nullptr) |
| Computes sum of all tensor elements (CPU implementation). | |
Static Private Member Functions | |
| template<TensorDataType TDataType, typename TMemoryResource, typename TBinaryOp> requires isValidTensor<TDataType, TMemoryResource> | |
| static void | performElementwiseOperation (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, Tensor< TDataType, TMemoryResource > &result, TBinaryOp op) |
| Performs element-wise operation using the provided binary function. | |
| template<TensorDataType TDataType, typename TMemoryResource> | |
| static void | validateShapeCompatibility (const Tensor< TDataType, TMemoryResource > &a, const Tensor< TDataType, TMemoryResource > &b, const Tensor< TDataType, TMemoryResource > &result, const std::string &operation_name) |
| Validates that three tensors have compatible shapes for element-wise operations. | |
CPU specialization of TensorOps for mathematical operations.
Implements element-wise operations for CPU tensors using standard library algorithms with optional parallel execution for large tensors.
Key features:
|
inlinestatic |
Element-wise addition of two tensors (CPU implementation).
Performs element-wise addition a[i] + b[i] for all elements and stores the result in a pre-allocated result tensor. Both input tensors must have identical shapes matching the result tensor shape.
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource (must be CPU-accessible) |
| a | First operand tensor |
| b | Second operand tensor |
| result | Pre-allocated result tensor (must have matching shape) |
| exec_context | Optional execution context (unused for CPU, accepted for API consistency) |
| std::invalid_argument | If tensor shapes don't match or tensors are empty |

|
inlinestatic |
Element-wise division of two tensors (CPU implementation).
Performs element-wise division a[i] / b[i] for all elements and stores the result in a pre-allocated result tensor.
For floating-point types, follows IEEE 754 standards:
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource (must be CPU-accessible) |
| a | First operand tensor (dividend) |
| b | Second operand tensor (divisor) |
| result | Pre-allocated result tensor (must have matching shape) |
| exec_context | Optional execution context (unused for CPU, accepted for API consistency) |
| std::invalid_argument | If tensor shapes don't match or tensors are empty |
| std::runtime_error | If division by zero in integer division |

|
inlinestatic |
Element-wise multiplication of two tensors (CPU implementation).
Performs element-wise multiplication a[i] * b[i] for all elements and stores the result in a pre-allocated result tensor.
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource (must be CPU-accessible) |
| a | First operand tensor |
| b | Second operand tensor |
| result | Pre-allocated result tensor (must have matching shape) |
| exec_context | Optional execution context (unused for CPU, accepted for API consistency) |
| std::invalid_argument | If tensor shapes don't match or tensors are empty |

|
inlinestaticprivate |
Performs element-wise operation using the provided binary function.
Applies a binary operation to corresponding elements of two input tensors and stores the result in the output tensor. Uses parallel execution for improved performance on large tensors (>10000 elements).
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource type |
| TBinaryOp | Binary operation function type |
| a | First input tensor |
| b | Second input tensor |
| result | Output tensor (must be pre-allocated with correct shape) |
| op | Binary operation to apply (e.g., std::plus, std::minus) |


|
inlinestatic |
Element-wise subtraction of two tensors (CPU implementation).
Performs element-wise subtraction a[i] - b[i] for all elements and stores the result in a pre-allocated result tensor.
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource (must be CPU-accessible) |
| a | First operand tensor (minuend) |
| b | Second operand tensor (subtrahend) |
| result | Pre-allocated result tensor (must have matching shape) |
| exec_context | Optional execution context (unused for CPU, accepted for API consistency) |
| std::invalid_argument | If tensor shapes don't match or tensors are empty |

|
inlinestatic |
Computes sum of all tensor elements (CPU implementation).
Reduces tensor to a single scalar value representing the sum of all elements. Uses parallel reduction for large tensors.
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource (must be CPU-accessible) |
| tensor | Input tensor |
| exec_context | Optional execution context (unused for CPU, accepted for API consistency) |

|
inlinestaticprivate |
Validates that three tensors have compatible shapes for element-wise operations.
| TDataType | Abstract tensor data type |
| TMemoryResource | Memory resource type |
| a | First input tensor |
| b | Second input tensor |
| result | Result tensor |
| operation_name | Name of the operation for error reporting |
| std::invalid_argument | If shapes don't match or tensors are empty |

