mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -13,7 +13,6 @@
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
|
||||
struct InsertZeros {
|
||||
DSizes<DenseIndex, 2> dimensions(const Tensor<float, 2>& input) const {
|
||||
DSizes<DenseIndex, 2> result;
|
||||
@@ -23,41 +22,38 @@ struct InsertZeros {
|
||||
}
|
||||
|
||||
template <typename Output, typename Device>
|
||||
void eval(const Tensor<float, 2>& input, Output& output, const Device& device) const
|
||||
{
|
||||
void eval(const Tensor<float, 2>& input, Output& output, const Device& device) const {
|
||||
array<DenseIndex, 2> strides;
|
||||
strides[0] = 2;
|
||||
strides[1] = 2;
|
||||
output.stride(strides).device(device) = input;
|
||||
|
||||
Eigen::DSizes<DenseIndex, 2> offsets(1,1);
|
||||
Eigen::DSizes<DenseIndex, 2> extents(output.dimension(0)-1, output.dimension(1)-1);
|
||||
Eigen::DSizes<DenseIndex, 2> offsets(1, 1);
|
||||
Eigen::DSizes<DenseIndex, 2> extents(output.dimension(0) - 1, output.dimension(1) - 1);
|
||||
output.slice(offsets, extents).stride(strides).device(device) = input.constant(0.0f);
|
||||
}
|
||||
};
|
||||
|
||||
static void test_custom_unary_op()
|
||||
{
|
||||
Tensor<float, 2> tensor(3,5);
|
||||
static void test_custom_unary_op() {
|
||||
Tensor<float, 2> tensor(3, 5);
|
||||
tensor.setRandom();
|
||||
|
||||
Tensor<float, 2> result = tensor.customOp(InsertZeros());
|
||||
VERIFY_IS_EQUAL(result.dimension(0), 6);
|
||||
VERIFY_IS_EQUAL(result.dimension(1), 10);
|
||||
|
||||
for (int i = 0; i < 6; i+=2) {
|
||||
for (int j = 0; j < 10; j+=2) {
|
||||
VERIFY_IS_EQUAL(result(i, j), tensor(i/2, j/2));
|
||||
for (int i = 0; i < 6; i += 2) {
|
||||
for (int j = 0; j < 10; j += 2) {
|
||||
VERIFY_IS_EQUAL(result(i, j), tensor(i / 2, j / 2));
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < 6; i+=2) {
|
||||
for (int j = 1; j < 10; j+=2) {
|
||||
for (int i = 1; i < 6; i += 2) {
|
||||
for (int j = 1; j < 10; j += 2) {
|
||||
VERIFY_IS_EQUAL(result(i, j), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct BatchMatMul {
|
||||
DSizes<DenseIndex, 3> dimensions(const Tensor<float, 3>& input1, const Tensor<float, 3>& input2) const {
|
||||
DSizes<DenseIndex, 3> result;
|
||||
@@ -68,9 +64,8 @@ struct BatchMatMul {
|
||||
}
|
||||
|
||||
template <typename Output, typename Device>
|
||||
void eval(const Tensor<float, 3>& input1, const Tensor<float, 3>& input2,
|
||||
Output& output, const Device& device) const
|
||||
{
|
||||
void eval(const Tensor<float, 3>& input1, const Tensor<float, 3>& input2, Output& output,
|
||||
const Device& device) const {
|
||||
typedef Tensor<float, 3>::DimensionPair DimPair;
|
||||
array<DimPair, 1> dims;
|
||||
dims[0] = DimPair(1, 0);
|
||||
@@ -80,12 +75,10 @@ struct BatchMatMul {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void test_custom_binary_op()
|
||||
{
|
||||
Tensor<float, 3> tensor1(2,3,5);
|
||||
static void test_custom_binary_op() {
|
||||
Tensor<float, 3> tensor1(2, 3, 5);
|
||||
tensor1.setRandom();
|
||||
Tensor<float, 3> tensor2(3,7,5);
|
||||
Tensor<float, 3> tensor2(3, 7, 5);
|
||||
tensor2.setRandom();
|
||||
|
||||
Tensor<float, 3> result = tensor1.customOp(tensor2, BatchMatMul());
|
||||
@@ -103,9 +96,7 @@ static void test_custom_binary_op()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_custom_op)
|
||||
{
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_custom_op) {
|
||||
CALL_SUBTEST(test_custom_unary_op());
|
||||
CALL_SUBTEST(test_custom_binary_op());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user