// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
float val = 1.0f; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 7; ++k) {
mat1(i,j,k) = val;
val += 1.0f;
}
}
}
mat2 = mat1.constant(3.14f);
mat3 = mat1.cwiseMax(7.3f).exp();
val = 1.0f; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 7; ++k) {
VERIFY_IS_APPROX(mat2(i,j,k), 3.14f);
VERIFY_IS_APPROX(mat3(i,j,k), expf((std::max)(val, 7.3f)));
val += 1.0f;
}
}
}
}
// Test ||.
Tensor<bool, 1> bool1 = vec < vec.constant(1) || vec > vec.constant(4); for (int i = 0; i < kSize; ++i) { bool expected = i < 1 || i > 4;
VERIFY_IS_EQUAL(bool1[i], expected);
}
// Test &&, including cast of operand vec.
Tensor<bool, 1> bool2 = vec.cast<bool>() && vec < vec.constant(4); for (int i = 0; i < kSize; ++i) { bool expected = bool(i) && i < 4;
VERIFY_IS_EQUAL(bool2[i], expected);
}
// Compilation tests: // Test Tensor<bool> against results of cast or comparison; verifies that // CoeffReturnType is set to match Op return type of bool for Unary and Binary // Ops.
Tensor<bool, 1> bool3 = vec.cast<bool>() && bool2;
bool3 = vec < vec.constant(4) && bool2;
}
// Test min and max reduction
Tensor<Scalar, 0> val;
val = vec_zero.minimum();
VERIFY_IS_EQUAL(val(), kZero);
val = vec_zero.template minimum<PropagateNaN>();
VERIFY_IS_EQUAL(val(), kZero);
val = vec_zero.template minimum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), kZero);
val = vec_zero.maximum();
VERIFY_IS_EQUAL(val(), kZero);
val = vec_zero.template maximum<PropagateNaN>();
VERIFY_IS_EQUAL(val(), kZero);
val = vec_zero.template maximum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), kZero);
// Test NaN propagation for tensor of all NaNs.
val = vec_all_nan.template minimum<PropagateNaN>();
VERIFY((numext::isnan)(val()));
val = vec_all_nan.template minimum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), kInf);
val = vec_all_nan.template maximum<PropagateNaN>();
VERIFY((numext::isnan)(val()));
val = vec_all_nan.template maximum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), -kInf);
// Test NaN propagation for tensor with a single NaN.
val = vec_one_nan.template minimum<PropagateNaN>();
VERIFY((numext::isnan)(val()));
val = vec_one_nan.template minimum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), (size == 1 ? kInf : kZero));
val = vec_one_nan.template maximum<PropagateNaN>();
VERIFY((numext::isnan)(val()));
val = vec_one_nan.template maximum<PropagateNumbers>();
VERIFY_IS_EQUAL(val(), (size == 1 ? -kInf : kZero));
}
}
// Nan propagation does currently not work like one would expect from std::max/std::min, // so we disable it for now #if !EIGEN_ARCH_ARM_OR_ARM64
CALL_SUBTEST(test_minmax_nan_propagation()); #endif
}
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.