Logic functions

Note

A practical example of the vast majority of the operations in this page are included in a working example in our GitHub respository

Truth value testing

All

bool Tensor::all()

Test whether all elements evaluate to True.

Returns

bool

Tensor* t1 = new Tensor({true,false,false,false,true,true}, {2, 3});
bool condition =  t1->all(); //returns new tensor
//condition = false

//Other ways
bool condition =  Tensor::all(t1); //source

Any

bool Tensor::any()

Test whether any element evaluates to True.

Returns

bool

Tensor* t1 = new Tensor({true,false,false,false,true,true}, {2, 3});

bool condition =  t1->any(); //returns new tensor
//condition = true

//Other ways
bool condition =  Tensor::any(t1); //source

Array contents

Is finite?

Tensor *Tensor::isfinite()

Test element-wise for finiteness (not infinity or not Not a Number).

Returns

Tensor with the results of the test as booleans

Tensor* t1 = new Tensor({12, INFINITY, NAN, -INFINITY, 0.0f, +INFINITY}, {2,3});
// [
// [12.00 inf nan]
// [-inf 0.00 inf]
// ]

Tensor* r1 = t1->isfinite(); // returns new tensor

r1->print(2);  // Temp.
// [
// [1.00 0.00 0.00]
// [0.00 1.00 0.00]
// ]

//Other ways
Tensor::isfinite(t1, r1); // static

Is inf?

Tensor *Tensor::isinf()

Test element-wise for positive or negative infinity.

Returns

Tensor with the results of the test as booleans

Tensor* t1 = new Tensor({12, INFINITY, NAN, -INFINITY, 0.0f, +INFINITY}, {2,3});
// [
// [12.00 inf nan]
// [-inf 0.00 inf]
// ]

Tensor* r1 = t1->isinf(); // returns new tensor
// [
// [0.00 1.00 0.00]
// [1.00 0.00 1.00]
// ]

//Other ways
Tensor::isinf(t1, r1); // static

Is NaN?

Tensor *Tensor::isnan()

Test element-wise for Nan.

Returns

Tensor with the results of the test as booleans

Tensor* t1 = new Tensor({12, INFINITY, NAN, -INFINITY, 0.0f, +INFINITY}, {2,3});
// [
// [12.00 inf nan]
// [-inf 0.00 inf]
// ]

Tensor* r1 = t1->isnan(); // returns new tensor
// [
// [0.00 0.00 1.00]
// [0.00 0.00 0.00]
// ]

//Other ways
Tensor::isnan(t1, r1); // static

Is -inf?

Tensor *Tensor::isneginf()

Test element-wise for negative infinity.

Returns

Tensor with the results of the test as booleans

Tensor* t1 = new Tensor({12, INFINITY, NAN, -INFINITY, 0.0f, +INFINITY}, {2,3});
// [
// [12.00 inf nan]
// [-inf 0.00 inf]
// ]

Tensor* r1 = t1->isneginf(); // returns new tensor
// [
// [0.00 0.00 0.00]
// [1.00 0.00 0.00]
// ]

//Other ways
Tensor::isneginf(t1, r1); // static

Is +inf?

Tensor *Tensor::isposinf()

Test element-wise for positive infinity.

Returns

Tensor with the results of the test as booleans

Tensor* t1 = new Tensor({12, INFINITY, NAN, -INFINITY, 0.0f, +INFINITY}, {2,3});
// [
// [12.00 inf nan]
// [-inf 0.00 inf]
// ]

Tensor* r1 = t1->isposinf(); // returns new tensor
// [
// [0.00 1.00 0.00]
// [0.00 0.00 1.00]
// ]

//Other ways
Tensor::isposinf(t1, r1); // static

Logical operations

Logical AND: “A & B”

Tensor *Tensor::logical_and(Tensor *A)

Compute the truth value of A and B element-wise.

Parameters

A – Tensor

Returns

Tensor with the result of the operation

Tensor* t1 = Tensor::full({5,5}, 1.0f);
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]


Tensor* t2 = Tensor::full({5,5}, 0.0f);
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

Tensor* r = t1->logical_and(t2); // returns new tensor
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

//Other ways
Tensor::logical_and(t1, t2, r); // static

Logical OR: “A | B”

Tensor *Tensor::logical_or(Tensor *A)

Compute the truth value of A or B element-wise.

Parameters

A – Tensor

Returns

Tensor with the result of the operation

Tensor* t1 = Tensor::full({5,5}, 1.0f);
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]


Tensor* t2 = Tensor::full({5,5}, 0.0f);
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

Tensor* r = t1->logical_or(t2); // returns new tensor
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

//Other ways
Tensor::logical_or(t1, t2, r); // static

Logical NOT: “~A”

Tensor *Tensor::logical_not()

Compute the truth value of not A element-wise.

Parameters

A – Tensor

Returns

Tensor with the result of the operation

Tensor* t1 = Tensor::full({5,5}, 1.0f);
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

Tensor* r = t1->logical_not(); // returns new tensor
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

//Other ways
Tensor::logical_not(t1, r); // static

Logical XOR (Exclusive OR): “A ^ B”

Tensor *Tensor::logical_xor(Tensor *A)

Compute the truth value of A xor B element-wise.

Parameters

A – Tensor

Returns

Tensor with the result of the operation

Tensor* t1 = Tensor::full({5,5}, 1.0f);
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]


Tensor* t2 = Tensor::full({5,5}, 0.0f);
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

Tensor* r = t1->logical_xor(t2); // returns new tensor
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

//Other ways
Tensor::logical_xor(t1, t2, r); // static

Comparison

Unary Operations

Greater than: “A > B”

Tensor *Tensor::greater(float v)

Return the truth value of the input elements > v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f, 1); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

t1->greater_(3.0f); // In-place
// [
// [0.00 0.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor* t2 = t1->greater(3.0f); // returns new tensor
Tensor::greater(t1, t2, 3.0f); // static

Greater equal: “A >= B”

Tensor *Tensor::greater_equal(float v)

Return the truth value of the input elements >= v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f, 1); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

t1->greater_equal_(3.0f); // In-place
// [
// [0.00 0.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor* t2 = t1->greater_equal(3.0f); // returns new tensor
Tensor::greater_equal(t1, t2, 3.0f); // static

Less than: “A < B”

Tensor *Tensor::less(float v)

Return the truth value of the input elements < v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f, 1); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

t1->less_(3.0f); // In-place
// [
// [1.00 1.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

// Other Ways
Tensor* t2 = t1->less(3.0f); // returns new tensor
Tensor::less_(t1, t2, 3.0f); // static

Less equal: “A <= B”

Tensor *Tensor::less_equal(float v)

Return the truth value of the input elements <= v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(-2, 3); t1->reshape_({2, 3});

Tensor* t2 = Tensor::randn({2, 3});

Tensor* t3 = t1->less_equal(t2); // returns new tensor

// Other Ways
Tensor::less_equal(t1, t2, t3); // static

Equal: “A == B”

Tensor *Tensor::equal(float v)

Return the truth value of the input elements == v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f, 1); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

t1->equal_(3.0f); // In-place
// [
// [0.00 0.00 1.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

// Other Ways
Tensor* t2 = t1->equal(3.0f); // returns new tensor
Tensor::equal(t1, t2, 3.0f); // static

Not Equal: “A != B”

Tensor *Tensor::not_equal(float v)

Return the truth value of the input elements != v element-wise.

Parameters

v – Value to make the comparison with.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f, 1); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

t1->not_equal_(3.0f); // In-place
// [
// [1.00 1.00 0.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor* t2 = t1->not_equal(3.0f); // returns new tensor
Tensor::not_equal(t1, t2, 3.0f); // static

Binary Operations

All Close?

bool Tensor::allclose(Tensor *A, float rtol = 1e-05, float atol = 1e-08, bool equal_nan = false)

Returns True if two arrays accomplish, element-wise, the condition \(|A-B| \leq atol+rtol\times|B|\).

Parameters
  • A – Input tensor.

  • rtol – relative tolerance.

  • atol – absolute tolerance.

  • equal_nan – if True, then two NaNs will be considered equal.

Returns

boolean indicating if all elements in tensor hold the condition

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

float result = t1->allclose(t2);
// 1.00

//Other ways
result = Tensor::allclose(t1, t2); //static

Is Close?

Tensor *Tensor::isclose(Tensor *A, float rtol = 1e-05, float atol = 1e-08, bool equal_nan = false)

Returns a boolean array where a position is true if elements in A and B accomplish \(|A-B| \leq atol+rtol\times|B|\).

Parameters
  • A – Input tensor.

  • rtol – relative tolerance.

  • atol – absolute tolerance.

  • equal_nan – if True, then two NaNs will be considered equal.

Returns

boolean indicating if all elements in tensor hold the condition

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->isclose(t2); // returns new tensor
// [
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

//Other ways
Tensor::isclose(t1, t2, t3); //static

Greater Than: “A > B”

Tensor *Tensor::greater(Tensor *A)

Return the truth value of this > A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->greater(t2); // returns new tensor
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

// Other Ways
Tensor::greaterl(t1, t2, t3); // static

Greater Equal: “A >= B”

Tensor *Tensor::greater_equal(Tensor *A)

Return the truth value of this >= A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->greater_equal(t2); // returns new tensor
// [
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor::greater_equal(t1, t2, t3); // static

Less Than: “A < B”

Tensor *Tensor::less(Tensor *A)

Return the truth value of this < A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->less(t2); // returns new tensor
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

// Other Ways
Tensor::less(t1, t2, t3); // static

Less Equal: “A <= B”

Tensor *Tensor::less_equal(Tensor *A)

Return the truth value of this <= A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->less_equal(t2); // returns new tensor
// [
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor::less_equal(t1, t2, t3); // static

Equal: “A == B”

Tensor *Tensor::equal(Tensor *A)

Return the truth value of this == A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->equal(t2); // returns new tensor
// [
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// [1.00 1.00 1.00 1.00 1.00]
// ]

// Other Ways
Tensor::equal(t1, t2, t3); // static

Not Equal: “A != B”

Tensor *Tensor::not_equal(Tensor *A)

Return the truth value of this != A element-wise.

Parameters

A – Input tensor.

Returns

A tensor with the true values.

Tensor* t1 = Tensor::range(1.0f, 25.0f); t1->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]


Tensor* t2 = Tensor::range(1.0f, 25.0f); t2->reshape_({5,5});
// [
// [1.00 2.00 3.00 4.00 5.00]
// [6.00 7.00 8.00 9.00 10.00]
// [11.00 12.00 13.00 14.00 15.00]
// [16.00 17.00 18.00 19.00 20.00]
// [21.00 22.00 23.00 24.00 25.00]
// ]

Tensor* t3 = t1->not_equal(t2); // returns new tensor
// [
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// [0.00 0.00 0.00 0.00 0.00]
// ]

// Other Ways
Tensor::not_equal(t1, t2, t3); // static