Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
comparisons.hpp File Reference

Defines element-wise comparison operations for tensor expressions. More...

#include "concepts.hpp"
#include "shape.hpp"
#include "tensor.hpp"
Include dependency graph for comparisons.hpp:

Go to the source code of this file.

Classes

class  tannic::expression::Comparison< Criteria, First, Second >
 Expression template for element-wise tensor comparisons. More...
 
struct  tannic::expression::EQ
 
struct  tannic::expression::NE
 
struct  tannic::expression::GT
 
struct  tannic::expression::GE
 
struct  tannic::expression::LT
 
struct  tannic::expression::LE
 

Namespaces

namespace  tannic
 
namespace  tannic::expression
 

Functions

template<Expression First, Expression Second>
constexpr auto tannic::expression::operator== (First &&lhs, Second &&rhs)
 
template<Expression First, Expression Second>
constexpr auto tannic::expression::operator!= (First &&lhs, Second &&rhs)
 
template<Expression First, Expression Second>
constexpr auto tannic::expression::operator< (First &&lhs, Second &&rhs)
 
template<Expression First, Expression Second>
constexpr auto tannic::expression::operator<= (First &&lhs, Second &&rhs)
 
template<Expression First, Expression Second>
constexpr auto tannic::expression::operator> (First &&lhs, Second &&rhs)
 
template<Expression First, Expression Second>
constexpr auto tannic::expression::operator>= (First &&lhs, Second &&rhs)
 
bool tannic::expression::allclose (Tensor const &first, Tensor const &second, double rtol=1e-5f, double atol=1e-8f)
 Determine whether two tensors are element-wise equal within a tolerance.
 

Detailed Description

Defines element-wise comparison operations for tensor expressions.

Author
Eric Hermosis
Date
2025

This header provides lazy-evaluated comparison operators for Tensor and expression types. All comparisons are element-wise and produce boolean tensors of the same shape as the operands.

Supported operators:

  • Equality and inequality:
    • == (equal)
    • != (not equal)
  • Relational comparisons:
    • < (less than)
    • <= (less than or equal)
    • > (greater than)
    • >= (greater than or equal)

Example

#include <iostream>
#include <tannic.hpp>
using namespace tannic;
int main() {
Tensor A = {1, 2, 3, 4, 5};
Tensor B = {5, 4, 3, 2, 1};
std::cout << "A == B: " << (A == B) << std::endl;
std::cout << "A != B: " << (A != B) << std::endl;
std::cout << "A > B: " << (A > B) << std::endl;
std::cout << "A >= B: " << (A >= B) << std::endl;
std::cout << "A < B: " << (A < B) << std::endl;
std::cout << "A <= B: " << (A <= B) << std::endl;
}
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:99
Defines element-wise comparison operations for tensor expressions.
Definition: buffer.hpp:41

Part of the Tannic Tensor Library.