blob: 02b82807ac48f07a7fde85a09bb342bfc7e834f6 [file] [edit]
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// 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/.
// SPDX-License-Identifier: MPL-2.0
#include <vector>
#include "main.h"
#include <Eigen/LU>
using Eigen::placeholders::all;
using Eigen::placeholders::last;
using Eigen::placeholders::lastN;
using Eigen::placeholders::lastp1;
#include <array>
#include <climits>
using IndexPair = std::pair<Index, Index>;
int encode(Index i, Index j) { return int(i * 100 + j); }
IndexPair decode(Index ij) { return IndexPair(ij / 100, ij % 100); }
template <typename T>
bool match(const T& xpr, const std::string& ref, const std::string& str_xpr = "") {
EIGEN_UNUSED_VARIABLE(str_xpr);
std::stringstream str;
str << xpr;
if (!(str.str() == ref)) std::cout << str_xpr << "\n" << xpr << "\n\n";
return str.str() == ref;
}
#define MATCH(X, R) match(X, R, #X)
template <typename T1, typename T2>
std::enable_if_t<std::is_same<T1, T2>::value, bool> is_same_eq(const T1& a, const T2& b) {
return (a == b).all();
}
template <typename T1, typename T2>
bool is_same_seq(const T1& a, const T2& b) {
bool ok = a.first() == b.first() && a.size() == b.size() && Index(a.incrObject()) == Index(b.incrObject());
;
if (!ok) {
std::cerr << "seqN(" << a.first() << ", " << a.size() << ", " << Index(a.incrObject()) << ") != ";
std::cerr << "seqN(" << b.first() << ", " << b.size() << ", " << Index(b.incrObject()) << ")\n";
}
return ok;
}
template <typename T1, typename T2>
std::enable_if_t<std::is_same<T1, T2>::value, bool> is_same_seq_type(const T1& a, const T2& b) {
return is_same_seq(a, b);
}
#define VERIFY_EQ_INT(A, B) VERIFY_IS_APPROX(int(A), int(B))
enum DummyEnum { XX = 0, YY = 1 };
void check_indexed_view() {
Index n = 10;
ArrayXd a = ArrayXd::LinSpaced(n, 0, n - 1);
Array<double, 1, Dynamic> b = a.transpose();
ArrayXXi A = ArrayXXi::NullaryExpr(n, n, std::ref(encode));
for (Index i = 0; i < n; ++i)
for (Index j = 0; j < n; ++j) VERIFY(decode(A(i, j)) == IndexPair(i, j));
Array4i eii(4);
eii << 3, 1, 6, 5;
std::vector<int> veci(4);
Map<ArrayXi>(veci.data(), 4) = eii;
VERIFY(MATCH(A(3, seq(9, 3, -1)), "309 308 307 306 305 304 303"));
VERIFY(MATCH(A(seqN(2, 5), seq(9, 3, -1)),
"209 208 207 206 205 204 203\n"
"309 308 307 306 305 304 303\n"
"409 408 407 406 405 404 403\n"
"509 508 507 506 505 504 503\n"
"609 608 607 606 605 604 603"));
VERIFY(MATCH(A(seqN(2, 5), 5),
"205\n"
"305\n"
"405\n"
"505\n"
"605"));
VERIFY(MATCH(A(seqN(last, 5, -1), seq(2, last)),
"902 903 904 905 906 907 908 909\n"
"802 803 804 805 806 807 808 809\n"
"702 703 704 705 706 707 708 709\n"
"602 603 604 605 606 607 608 609\n"
"502 503 504 505 506 507 508 509"));
VERIFY(MATCH(A(eii, veci),
"303 301 306 305\n"
"103 101 106 105\n"
"603 601 606 605\n"
"503 501 506 505"));
VERIFY(MATCH(A(eii, all),
"300 301 302 303 304 305 306 307 308 309\n"
"100 101 102 103 104 105 106 107 108 109\n"
"600 601 602 603 604 605 606 607 608 609\n"
"500 501 502 503 504 505 506 507 508 509"));
// take row number 3, and repeat it 5 times
VERIFY(MATCH(A(seqN(3, 5, 0), all),
"300 301 302 303 304 305 306 307 308 309\n"
"300 301 302 303 304 305 306 307 308 309\n"
"300 301 302 303 304 305 306 307 308 309\n"
"300 301 302 303 304 305 306 307 308 309\n"
"300 301 302 303 304 305 306 307 308 309"));
VERIFY(MATCH(a(seqN(3, 3), 0), "3\n4\n5"));
VERIFY(MATCH(a(seq(3, 5)), "3\n4\n5"));
VERIFY(MATCH(a(seqN(3, 3, 1)), "3\n4\n5"));
VERIFY(MATCH(a(seqN(5, 3, -1)), "5\n4\n3"));
VERIFY(MATCH(b(0, seqN(3, 3)), "3 4 5"));
VERIFY(MATCH(b(seq(3, 5)), "3 4 5"));
VERIFY(MATCH(b(seqN(3, 3, 1)), "3 4 5"));
VERIFY(MATCH(b(seqN(5, 3, -1)), "5 4 3"));
VERIFY(MATCH(b(all), "0 1 2 3 4 5 6 7 8 9"));
VERIFY(MATCH(b(eii), "3 1 6 5"));
// The fixed-size strides below are spelled for column-major storage, so pin B's order.
Array<int, 4, 4, ColMajor> B;
B.setRandom();
VERIFY((A(seqN(2, 5), 5)).ColsAtCompileTime == 1);
VERIFY((A(seqN(2, 5), 5)).RowsAtCompileTime == Dynamic);
// A single-column view is column major whatever A is, so it walks A's columns.
VERIFY_EQ_INT((A(seqN(2, 5), 5)).InnerStrideAtCompileTime, A.col(5).InnerStrideAtCompileTime);
VERIFY_EQ_INT((A(seqN(2, 5), 5)).OuterStrideAtCompileTime, A.col(5).OuterStrideAtCompileTime);
VERIFY_EQ_INT((A(5, seqN(2, 5))).InnerStrideAtCompileTime, A.row(5).InnerStrideAtCompileTime);
VERIFY_EQ_INT((A(5, seqN(2, 5))).OuterStrideAtCompileTime, A.row(5).OuterStrideAtCompileTime);
VERIFY_EQ_INT((B(1, seqN(1, 2))).InnerStrideAtCompileTime, B.row(1).InnerStrideAtCompileTime);
VERIFY_EQ_INT((B(1, seqN(1, 2))).OuterStrideAtCompileTime, B.row(1).OuterStrideAtCompileTime);
VERIFY_EQ_INT((A(seqN(2, 5), seq(1, 3))).InnerStrideAtCompileTime, A.InnerStrideAtCompileTime);
VERIFY_EQ_INT((A(seqN(2, 5), seq(1, 3))).OuterStrideAtCompileTime, A.OuterStrideAtCompileTime);
VERIFY_EQ_INT((B(seqN(1, 2), seq(1, 3))).InnerStrideAtCompileTime, B.InnerStrideAtCompileTime);
VERIFY_EQ_INT((B(seqN(1, 2), seq(1, 3))).OuterStrideAtCompileTime, B.OuterStrideAtCompileTime);
VERIFY_EQ_INT((A(seqN(2, 5, 2), seq(1, 3, 2))).InnerStrideAtCompileTime, Dynamic);
VERIFY_EQ_INT((A(seqN(2, 5, 2), seq(1, 3, 2))).OuterStrideAtCompileTime, Dynamic);
// The inner increment is the row increment when A is column major, the column one otherwise.
VERIFY_EQ_INT((A(seqN(2, 5, fix<2>), seq(1, 3, fix<3>))).InnerStrideAtCompileTime, A.IsRowMajor ? 3 : 2);
VERIFY_EQ_INT((A(seqN(2, 5, fix<2>), seq(1, 3, fix<3>))).OuterStrideAtCompileTime, Dynamic);
VERIFY_EQ_INT((B(seqN(1, 2, fix<2>), seq(1, 3, fix<3>))).InnerStrideAtCompileTime, 2);
VERIFY_EQ_INT((B(seqN(1, 2, fix<2>), seq(1, 3, fix<3>))).OuterStrideAtCompileTime, 3 * 4);
VERIFY_EQ_INT((A(seqN(2, fix<5>), seqN(1, fix<3>))).RowsAtCompileTime, 5);
VERIFY_EQ_INT((A(seqN(2, fix<5>), seqN(1, fix<3>))).ColsAtCompileTime, 3);
VERIFY_EQ_INT((A(seqN(2, fix<5>(5)), seqN(1, fix<3>(3)))).RowsAtCompileTime, 5);
VERIFY_EQ_INT((A(seqN(2, fix<5>(5)), seqN(1, fix<3>(3)))).ColsAtCompileTime, 3);
VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).RowsAtCompileTime, Dynamic);
VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).ColsAtCompileTime, Dynamic);
VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).rows(), 5);
VERIFY_EQ_INT((A(seqN(2, fix<Dynamic>(5)), seqN(1, fix<Dynamic>(3)))).cols(), 3);
VERIFY(is_same_seq_type(seqN(2, 5, fix<-1>), seqN(2, 5, fix<-1>(-1))));
VERIFY(is_same_seq_type(seqN(2, 5), seqN(2, 5, fix<1>(1))));
VERIFY(is_same_seq_type(seqN(2, 5, 3), seqN(2, 5, fix<DynamicIndex>(3))));
VERIFY(is_same_seq_type(seq(2, 7, fix<3>), seqN(2, 2, fix<3>)));
VERIFY(is_same_seq_type(seqN(2, fix<Dynamic>(5), 3), seqN(2, 5, fix<DynamicIndex>(3))));
VERIFY(is_same_seq_type(seqN(2, fix<5>(5), fix<-2>), seqN(2, fix<5>, fix<-2>())));
VERIFY(is_same_seq_type(seq(2, fix<5>), seqN(2, 4)));
VERIFY(is_same_seq_type(seq(fix<2>, fix<5>), seqN(fix<2>, fix<4>)));
VERIFY(is_same_seq(seqN(2, std::integral_constant<int, 5>(), std::integral_constant<int, -2>()),
seqN(2, fix<5>, fix<-2>())));
VERIFY(is_same_seq(
seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>(), std::integral_constant<int, 2>()),
seq(fix<1>, fix<5>, fix<2>())));
VERIFY(is_same_seq_type(seqN(2, std::integral_constant<int, 5>(), std::integral_constant<int, -2>()),
seqN(2, fix<5>, fix<-2>())));
VERIFY(is_same_seq_type(
seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>(), std::integral_constant<int, 2>()),
seq(fix<1>, fix<5>, fix<2>())));
VERIFY(is_same_seq_type(seqN(2, std::integral_constant<int, 5>()), seqN(2, fix<5>)));
VERIFY(
is_same_seq_type(seq(std::integral_constant<int, 1>(), std::integral_constant<int, 5>()), seq(fix<1>, fix<5>)));
VERIFY((A(seqN(2, fix<5>), 5)).RowsAtCompileTime == 5);
// Compile-time single indices.
VERIFY_IS_EQUAL(A(fix<1>, fix<2>), A(1, 2));
VERIFY((A(fix<1>, all) == A.row(1)).all());
VERIFY_IS_EQUAL(a(fix<3>), a(3));
VERIFY((A(4, all)).ColsAtCompileTime == Dynamic);
VERIFY((A(4, all)).RowsAtCompileTime == 1);
VERIFY((B(1, all)).ColsAtCompileTime == 4);
VERIFY((B(1, all)).RowsAtCompileTime == 1);
VERIFY((B(all, 1)).ColsAtCompileTime == 1);
VERIFY((B(all, 1)).RowsAtCompileTime == 4);
VERIFY(int((A(all, eii)).ColsAtCompileTime) == int(eii.SizeAtCompileTime));
VERIFY_EQ_INT((A(eii, eii)).Flags & DirectAccessBit, (unsigned int)(0));
VERIFY_EQ_INT((A(eii, eii)).InnerStrideAtCompileTime, 0);
VERIFY_EQ_INT((A(eii, eii)).OuterStrideAtCompileTime, 0);
VERIFY_IS_APPROX(A(seq(n - 1, 2, -2), seqN(n - 1 - 6, 3, -1)), A(seq(last, 2, fix<-2>), seqN(last - 6, 3, fix<-1>)));
VERIFY_IS_APPROX(A(seq(n - 1, 2, -2), seqN(n - 1 - 6, 4)), A(seq(last, 2, -2), seqN(last - 6, 4)));
VERIFY_IS_APPROX(A(seq(n - 1 - 6, n - 1 - 2), seqN(n - 1 - 6, 4)),
A(seq(last - 6, last - 2), seqN(6 + last - 6 - 6, 4)));
VERIFY_IS_APPROX(A(seq((n - 1) / 2, (n) / 2 + 3), seqN(2, 4)),
A(seq(last / 2, (last + 1) / 2 + 3), seqN(last + 2 - last, 4)));
VERIFY_IS_APPROX(A(seq(n - 2, 2, -2), seqN(n - 8, 4)), A(seq(lastp1 - 2, 2, -2), seqN(lastp1 - 8, 4)));
// Check all combinations of seq:
VERIFY_IS_APPROX(A(seq(1, n - 1 - 2, 2), seq(1, n - 1 - 2, 2)), A(seq(1, last - 2, 2), seq(1, last - 2, fix<2>)));
VERIFY_IS_APPROX(A(seq(n - 1 - 5, n - 1 - 2, 2), seq(n - 1 - 5, n - 1 - 2, 2)),
A(seq(last - 5, last - 2, 2), seq(last - 5, last - 2, fix<2>)));
VERIFY_IS_APPROX(A(seq(n - 1 - 5, 7, 2), seq(n - 1 - 5, 7, 2)), A(seq(last - 5, 7, 2), seq(last - 5, 7, fix<2>)));
VERIFY_IS_APPROX(A(seq(1, n - 1 - 2), seq(n - 1 - 5, 7)), A(seq(1, last - 2), seq(last - 5, 7)));
VERIFY_IS_APPROX(A(seq(n - 1 - 5, n - 1 - 2), seq(n - 1 - 5, n - 1 - 2)),
A(seq(last - 5, last - 2), seq(last - 5, last - 2)));
VERIFY_IS_APPROX(A(A.rows() - 2, A.cols() / 2), A(last - 1, lastp1 / 2));
VERIFY_IS_APPROX(a(a.size() - 2), a(last - 1));
VERIFY_IS_APPROX(a(a.size() / 2), a((last + 1) / 2));
// Check fall-back to Block
{
VERIFY(is_same_eq(A.col(0), A(all, 0)));
VERIFY(is_same_eq(A.row(0), A(0, all)));
VERIFY(is_same_eq(A.block(0, 0, 2, 2), A(seqN(0, 2), seq(0, 1))));
VERIFY(is_same_eq(A.middleRows(2, 4), A(seqN(2, 4), all)));
VERIFY(is_same_eq(A.middleCols(2, 4), A(all, seqN(2, 4))));
VERIFY(is_same_eq(A.col(A.cols() - 1), A(all, last)));
const ArrayXXi& cA(A);
VERIFY(is_same_eq(cA.col(0), cA(all, 0)));
VERIFY(is_same_eq(cA.row(0), cA(0, all)));
VERIFY(is_same_eq(cA.block(0, 0, 2, 2), cA(seqN(0, 2), seq(0, 1))));
VERIFY(is_same_eq(cA.middleRows(2, 4), cA(seqN(2, 4), all)));
VERIFY(is_same_eq(cA.middleCols(2, 4), cA(all, seqN(2, 4))));
VERIFY(is_same_eq(a.head(4), a(seq(0, 3))));
VERIFY(is_same_eq(a.tail(4), a(seqN(last - 3, 4))));
VERIFY(is_same_eq(a.tail(4), a(seq(lastp1 - 4, last))));
VERIFY(is_same_eq(a.segment<4>(3), a(seqN(3, fix<4>))));
}
ArrayXXi A1 = A, A2 = ArrayXXi::Random(4, 4);
ArrayXi range25(4);
range25 << 3, 2, 4, 5;
A1(seqN(3, 4), seq(2, 5)) = A2;
VERIFY_IS_APPROX(A1.block(3, 2, 4, 4), A2);
A1 = A;
A2.setOnes();
A1(seq(6, 3, -1), range25) = A2;
VERIFY_IS_APPROX(A1.block(3, 2, 4, 4), A2);
// check reverse
{
VERIFY(is_same_seq_type(seq(3, 7).reverse(), seqN(7, 5, fix<-1>)));
VERIFY(is_same_seq_type(seq(7, 3, fix<-2>).reverse(), seqN(3, 3, fix<2>)));
VERIFY_IS_APPROX(a(seqN(2, last / 2).reverse()), a(seqN(2 + (last / 2 - 1) * 1, last / 2, fix<-1>)));
VERIFY_IS_APPROX(a(seqN(last / 2, fix<4>).reverse()), a(seqN(last / 2, fix<4>)).reverse());
VERIFY_IS_APPROX(A(seq(last - 5, last - 1, 2).reverse(), seqN(last - 3, 3, fix<-2>).reverse()),
A(seq(last - 5, last - 1, 2), seqN(last - 3, 3, fix<-2>)).reverse());
}
// check lastN
VERIFY_IS_APPROX(a(lastN(3)), a.tail(3));
VERIFY(MATCH(a(lastN(3)), "7\n8\n9"));
VERIFY_IS_APPROX(a(lastN(fix<3>())), a.tail<3>());
VERIFY(MATCH(a(lastN(3, 2)), "5\n7\n9"));
VERIFY(MATCH(a(lastN(3, fix<2>())), "5\n7\n9"));
VERIFY(a(lastN(fix<3>())).SizeAtCompileTime == 3);
VERIFY((A(all, std::array<int, 4>{{1, 3, 2, 4}})).ColsAtCompileTime == 4);
VERIFY_IS_APPROX((A(std::array<int, 3>{{1, 3, 5}}, std::array<int, 4>{{9, 6, 3, 0}})),
A(seqN(1, 3, 2), seqN(9, 4, -3)));
VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).RowsAtCompileTime, 3);
VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).ColsAtCompileTime, 4);
VERIFY_IS_EQUAL(a(std::array<int, 3>{1, 3, 5}).SizeAtCompileTime, 3);
VERIFY_IS_EQUAL(b(std::array<int, 3>{1, 3, 5}).SizeAtCompileTime, 3);
// check different index types (C-style array, STL container, Eigen type)
{
Index size = 10;
ArrayXd r = ArrayXd::Random(size);
ArrayXi idx = ArrayXi::EqualSpaced(size, 0, 1);
std::mt19937 rng(static_cast<unsigned int>(internal::random<int>(0, 1 << 30)));
std::shuffle(idx.begin(), idx.end(), rng);
int c_array[3] = {idx[0], idx[1], idx[2]};
std::vector<int> std_vector{idx[0], idx[1], idx[2]};
Matrix<int, 3, 1> eigen_matrix{idx[0], idx[1], idx[2]};
// non-const access
VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(c_array));
VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(std_vector));
VERIFY_IS_CWISE_EQUAL(r({idx[0], idx[1], idx[2]}), r(eigen_matrix));
const ArrayXd& r_ref = r;
// const access
VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(c_array));
VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(std_vector));
VERIFY_IS_CWISE_EQUAL(r_ref({idx[0], idx[1], idx[2]}), r_ref(eigen_matrix));
}
{
Index rows = 8;
Index cols = 11;
ArrayXXd R = ArrayXXd::Random(rows, cols);
ArrayXi r_idx = ArrayXi::EqualSpaced(rows, 0, 1);
ArrayXi c_idx = ArrayXi::EqualSpaced(cols, 0, 1);
std::mt19937 rng(static_cast<unsigned int>(internal::random<int>(0, 1 << 30)));
std::shuffle(r_idx.begin(), r_idx.end(), rng);
std::shuffle(c_idx.begin(), c_idx.end(), rng);
int c_array_rows[3] = {r_idx[0], r_idx[1], r_idx[2]};
int c_array_cols[4] = {c_idx[0], c_idx[1], c_idx[2], c_idx[3]};
std::vector<int> std_vector_rows{r_idx[0], r_idx[1], r_idx[2]};
std::vector<int> std_vector_cols{c_idx[0], c_idx[1], c_idx[2], c_idx[3]};
Matrix<int, 3, 1> eigen_matrix_rows{r_idx[0], r_idx[1], r_idx[2]};
Matrix<int, 4, 1> eigen_matrix_cols{c_idx[0], c_idx[1], c_idx[2], c_idx[3]};
// non-const access
VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R(c_array_rows, c_array_cols));
VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R(std_vector_rows, std_vector_cols));
VERIFY_IS_CWISE_EQUAL(R({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R(eigen_matrix_rows, eigen_matrix_cols));
const ArrayXXd& R_ref = R;
// const access
VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R_ref(c_array_rows, c_array_cols));
VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R_ref(std_vector_rows, std_vector_cols));
VERIFY_IS_CWISE_EQUAL(R_ref({r_idx[0], r_idx[1], r_idx[2]}, {c_idx[0], c_idx[1], c_idx[2], c_idx[3]}),
R_ref(eigen_matrix_rows, eigen_matrix_cols));
VERIFY_IS_CWISE_EQUAL(R_ref(std_vector_rows, std_vector_cols), R_ref(c_array_rows, c_array_cols));
VERIFY_IS_CWISE_EQUAL(R_ref(std_vector_rows, std_vector_cols), R_ref(eigen_matrix_rows, eigen_matrix_cols));
VERIFY_IS_CWISE_EQUAL(R_ref(eigen_matrix_rows, eigen_matrix_cols), R_ref(c_array_rows, c_array_cols));
}
// check mat(i,j) with unusual types for i and j
{
VERIFY_IS_APPROX(A(B.RowsAtCompileTime - 1, 1), A(3, 1));
VERIFY_IS_APPROX(A(B.RowsAtCompileTime, 1), A(4, 1));
VERIFY_IS_APPROX(A(B.RowsAtCompileTime - 1, B.ColsAtCompileTime - 1), A(3, 3));
VERIFY_IS_APPROX(A(B.RowsAtCompileTime, B.ColsAtCompileTime), A(4, 4));
const Index I_ = 3, J_ = 4;
VERIFY_IS_APPROX(A(I_, J_), A(3, 4));
}
// check extended block API
{
VERIFY(is_same_eq(A.block<3, 4>(1, 1), A.block(1, 1, fix<3>, fix<4>)));
VERIFY(is_same_eq(A.block<3, 4>(1, 1, 3, 4), A.block(1, 1, fix<3>(), fix<4>(4))));
VERIFY(is_same_eq(A.block<3, Dynamic>(1, 1, 3, 4), A.block(1, 1, fix<3>, 4)));
VERIFY(is_same_eq(A.block<Dynamic, 4>(1, 1, 3, 4), A.block(1, 1, fix<Dynamic>(3), fix<4>)));
VERIFY(is_same_eq(A.block(1, 1, 3, 4), A.block(1, 1, fix<Dynamic>(3), fix<Dynamic>(4))));
VERIFY(is_same_eq(A.topLeftCorner<3, 4>(), A.topLeftCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(A.bottomLeftCorner<3, 4>(), A.bottomLeftCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(A.bottomRightCorner<3, 4>(), A.bottomRightCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(A.topRightCorner<3, 4>(), A.topRightCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(A.leftCols<3>(), A.leftCols(fix<3>)));
VERIFY(is_same_eq(A.rightCols<3>(), A.rightCols(fix<3>)));
VERIFY(is_same_eq(A.middleCols<3>(1), A.middleCols(1, fix<3>)));
VERIFY(is_same_eq(A.topRows<3>(), A.topRows(fix<3>)));
VERIFY(is_same_eq(A.bottomRows<3>(), A.bottomRows(fix<3>)));
VERIFY(is_same_eq(A.middleRows<3>(1), A.middleRows(1, fix<3>)));
VERIFY(is_same_eq(a.segment<3>(1), a.segment(1, fix<3>)));
VERIFY(is_same_eq(a.head<3>(), a.head(fix<3>)));
VERIFY(is_same_eq(a.tail<3>(), a.tail(fix<3>)));
const ArrayXXi& cA(A);
VERIFY(is_same_eq(cA.block<Dynamic, 4>(1, 1, 3, 4), cA.block(1, 1, fix<Dynamic>(3), fix<4>)));
VERIFY(is_same_eq(cA.topLeftCorner<3, 4>(), cA.topLeftCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(cA.bottomLeftCorner<3, 4>(), cA.bottomLeftCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(cA.bottomRightCorner<3, 4>(), cA.bottomRightCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(cA.topRightCorner<3, 4>(), cA.topRightCorner(fix<3>, fix<4>)));
VERIFY(is_same_eq(cA.leftCols<3>(), cA.leftCols(fix<3>)));
VERIFY(is_same_eq(cA.rightCols<3>(), cA.rightCols(fix<3>)));
VERIFY(is_same_eq(cA.middleCols<3>(1), cA.middleCols(1, fix<3>)));
VERIFY(is_same_eq(cA.topRows<3>(), cA.topRows(fix<3>)));
VERIFY(is_same_eq(cA.bottomRows<3>(), cA.bottomRows(fix<3>)));
VERIFY(is_same_eq(cA.middleRows<3>(1), cA.middleRows(1, fix<3>)));
}
// Check compilation of enums as index type:
a(XX) = 1;
A(XX, YY) = 1;
enum { X = 0, Y = 1 };
a(X) = 1;
A(X, Y) = 1;
A(XX, Y) = 1;
A(X, YY) = 1;
// check symbolic indices
a(last) = 1.0;
A(last, last) = 1;
// check unusual non-const, non-lvalue scenarios
{
// in these scenarios, the objects are not declared 'const', and the compiler will attempt to use the non-const
// overloads without intervention
// non-const map to a const object
Map<const ArrayXd> a_map(a.data(), a.size());
Map<const ArrayXXi> A_map(A.data(), A.rows(), A.cols());
VERIFY_IS_EQUAL(a_map(last), a.coeff(a.size() - 1));
VERIFY_IS_EQUAL(A_map(last, last), A.coeff(A.rows() - 1, A.cols() - 1));
// non-const expressions that have no modifiable data
using Op = internal::scalar_constant_op<double>;
using VectorXpr = CwiseNullaryOp<Op, VectorXd>;
using MatrixXpr = CwiseNullaryOp<Op, MatrixXd>;
double constant_val = internal::random<double>();
Op op(constant_val);
VectorXpr vectorXpr(10, 1, op);
MatrixXpr matrixXpr(8, 11, op);
VERIFY_IS_EQUAL(vectorXpr.coeff(vectorXpr.size() - 1), vectorXpr(last));
VERIFY_IS_EQUAL(matrixXpr.coeff(matrixXpr.rows() - 1, matrixXpr.cols() - 1), matrixXpr(last, last));
}
// Check compilation of varying integer types as index types:
Index i = n / 2;
short i_short = static_cast<short>(i);
std::size_t i_sizet(i);
VERIFY_IS_EQUAL(a(i), a.coeff(i_short));
VERIFY_IS_EQUAL(a(i), a.coeff(i_sizet));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i_short, i_short));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i_short, i));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i, i_short));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i, i_sizet));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i_sizet, i));
VERIFY_IS_EQUAL(A(i, i), A.coeff(i_sizet, i_short));
VERIFY_IS_EQUAL(A(i, i), A.coeff(5, i_sizet));
// Regression test for Max{Rows,Cols}AtCompileTime
{
Matrix3i A3 = Matrix3i::Random();
ArrayXi ind(5);
ind << 1, 1, 1, 1, 1;
VERIFY_IS_EQUAL(A3(ind, ind).eval(), MatrixXi::Constant(5, 5, A3(1, 1)));
}
// Regression for bug 1736
{
VERIFY_IS_APPROX(A(all, eii).col(0).eval(), A.col(eii(0)));
A(all, eii).col(0) = A.col(eii(0));
}
// bug 1815: IndexedView should allow linear access
{
VERIFY(MATCH(b(eii)(0), "3"));
VERIFY(MATCH(a(eii)(0), "3"));
VERIFY(MATCH(A(1, eii)(0), "103"));
VERIFY(MATCH(A(eii, 1)(0), "301"));
VERIFY(MATCH(A(1, all)(1), "101"));
VERIFY(MATCH(A(all, 1)(1), "101"));
}
// bug #2375: indexing over matrices of dim >128 should compile on gcc
{
Matrix<double, 513, 3> large_mat = Matrix<double, 513, 3>::Random();
std::array<int, 2> test_indices = {0, 1};
Matrix<double, 513, 2> thin_slice = large_mat(all, test_indices);
for (int col = 0; col < int(test_indices.size()); ++col)
for (int row = 0; row < large_mat.rows(); ++row) VERIFY_IS_EQUAL(thin_slice(row, col), large_mat(row, col));
}
// Bug IndexView with a single static row should be RowMajor:
{
// A(1, seq(0,2,1)).cwiseAbs().colwise().replicate(2).eval();
STATIC_CHECK(((internal::evaluator<decltype(A(1, seq(0, 2, 1)))>::Flags & RowMajorBit) == RowMajorBit));
}
// Direct access.
{
int rows = 3;
int row_start = internal::random<int>(0, rows - 1);
int row_inc = internal::random<int>(1, rows - row_start);
int row_size = internal::random<int>(1, (rows - row_start) / row_inc);
auto row_seq = seqN(row_start, row_size, row_inc);
int cols = 3;
int col_start = internal::random<int>(0, cols - 1);
int col_inc = internal::random<int>(1, cols - col_start);
int col_size = internal::random<int>(1, (cols - col_start) / col_inc);
auto col_seq = seqN(col_start, col_size, col_inc);
MatrixXd m1 = MatrixXd::Random(rows, cols);
MatrixXd m2 = MatrixXd::Random(cols, rows);
VERIFY_IS_APPROX(m1(row_seq, indexing::all) * m2, m1(row_seq, indexing::all).eval() * m2);
VERIFY_IS_APPROX(m1 * m2(indexing::all, col_seq), m1 * m2(indexing::all, col_seq).eval());
VERIFY_IS_APPROX(m1(row_seq, col_seq) * m2(col_seq, row_seq),
m1(row_seq, col_seq).eval() * m2(col_seq, row_seq).eval());
VectorXd v1 = VectorXd::Random(cols);
VERIFY_IS_APPROX(m1(row_seq, col_seq) * v1(col_seq), m1(row_seq, col_seq).eval() * v1(col_seq).eval());
VERIFY_IS_APPROX(v1(col_seq).transpose() * m2(col_seq, row_seq),
v1(col_seq).transpose().eval() * m2(col_seq, row_seq).eval());
}
}
void check_tutorial_examples() {
constexpr int kRows = 11;
constexpr int kCols = 21;
// Several slices below are checked against a Map built from A.data() with column-major
// offsets and strides, so pin A's storage order.
using MatrixA = Matrix<double, kRows, kCols, ColMajor>;
MatrixA A = MatrixA::Random();
Vector<double, kRows> v = Vector<double, kRows>::Random();
{
auto slice = A(seqN(fix<0>, fix<5>, fix<2>), seqN(fix<2>, fix<7>, fix<1>));
EIGEN_UNUSED_VARIABLE(slice);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), 5);
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), 7);
}
{
auto slice = A(seqN(fix<0>, fix<5>, fix<2>), indexing::all);
EIGEN_UNUSED_VARIABLE(slice);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), 5);
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), kCols);
}
// Examples from slicing tutorial.
// Bottom-left corner.
{
Index i = 3;
Index n = 5;
auto slice = A(seq(i, indexing::last), seqN(0, n));
auto block = A.bottomLeftCorner(A.rows() - i, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), Dynamic);
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), Dynamic);
VERIFY_IS_EQUAL(slice, block);
}
{
auto i = fix<3>;
auto n = fix<5>;
auto slice = A(seq(i, indexing::last), seqN(fix<0>, n));
auto block = A.bottomLeftCorner(fix<kRows> - i, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), A.RowsAtCompileTime - i);
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), n);
VERIFY_IS_EQUAL(slice, block);
}
// Block starting at i,j of size m,n.
{
Index i = 4;
Index j = 2;
Index m = 3;
Index n = 5;
auto slice = A(seqN(i, m), seqN(j, n));
auto block = A.block(i, j, m, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto i = fix<4>;
auto j = fix<2>;
auto m = fix<3>;
auto n = fix<5>;
auto slice = A(seqN(i, m), seqN(j, n));
auto block = A.block(i, j, m, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Block starting at i0,j0 and ending at i1,j1.
{
Index i0 = 4;
Index i1 = 7;
Index j0 = 3;
Index j1 = 5;
auto slice = A(seq(i0, i1), seq(j0, j1));
auto block = A.block(i0, j0, i1 - i0 + 1, j1 - j0 + 1);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto i0 = fix<4>;
auto i1 = fix<7>;
auto j0 = fix<3>;
auto j1 = fix<5>;
auto slice = A(seq(i0, i1), seq(j0, j1));
auto block = A.block(i0, j0, i1 - i0 + fix<1>, j1 - j0 + fix<1>);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Even columns of A.
{
auto slice = A(all, seq(0, last, 2));
auto block = Eigen::Map<Eigen::Matrix<double, kRows, Dynamic, ColMajor>, 0, OuterStride<2 * kRows>>(
A.data(), kRows, (kCols + 1) / 2);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto slice = A(all, seq(fix<0>, last, fix<2>));
auto block =
Eigen::Map<Eigen::Matrix<double, kRows, (kCols + 1) / 2, ColMajor>, 0, OuterStride<2 * kRows>>(A.data());
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// First n odd rows of A.
{
Index n = 3;
auto slice = A(seqN(1, n, 2), all);
auto block =
Eigen::Map<Eigen::Matrix<double, Dynamic, kCols, ColMajor>, 0, Stride<kRows, 2>>(A.data() + 1, n, kCols);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto n = fix<3>;
auto slice = A(seqN(fix<1>, n, fix<2>), all);
auto block = Eigen::Map<Eigen::Matrix<double, 3, kCols, ColMajor>, 0, Stride<kRows, 2>>(A.data() + 1);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// The second-last column.
{
auto slice = A(all, last - 1);
auto block = A.col(A.cols() - 2);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto slice = A(all, last - fix<1>);
auto block = A.col(fix<kCols> - fix<2>);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// The middle row.
{
auto slice = A(last / 2, all);
auto block = A.row((A.rows() - 1) / 2);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto slice = A(last / fix<2>, all);
auto block = A.row(fix<(kRows - 1) / 2>);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Last elements of v starting at i.
{
Index i = 7;
auto slice = v(seq(i, last));
auto block = v.tail(v.size() - i);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto i = fix<7>;
auto slice = v(seq(i, last));
auto block = v.tail(fix<kRows> - i);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Last n elements of v.
{
Index n = 6;
auto slice = v(seq(last + 1 - n, last));
auto block = v.tail(n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto n = fix<6>;
auto slice = v(seq(last + fix<1> - n, last));
auto block = v.tail(n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Last n elements of v.
{
Index n = 6;
auto slice = v(lastN(n));
auto block = v.tail(n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto n = fix<6>;
auto slice = v(lastN(n));
auto block = v.tail(n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Bottom-right corner of A of size m times n.
{
Index m = 3;
Index n = 6;
auto slice = A(lastN(m), lastN(n));
auto block = A.bottomRightCorner(m, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
auto m = fix<3>;
auto n = fix<6>;
auto slice = A(lastN(m), lastN(n));
auto block = A.bottomRightCorner(m, n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Last n columns with a stride of 3.
{
Index n = 4;
constexpr Index stride = 3;
auto slice = A(all, lastN(n, stride));
auto block = Eigen::Map<Eigen::Matrix<double, kRows, Dynamic, ColMajor>, 0, OuterStride<stride * kRows>>(
A.data() + (kCols - 1 - (n - 1) * stride) * kRows, A.rows(), n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
{
constexpr auto n = fix<4>;
constexpr auto stride = fix<3>;
auto slice = A(all, lastN(n, stride));
auto block = Eigen::Map<Eigen::Matrix<double, kRows, n, ColMajor>, 0, OuterStride<stride * kRows>>(
A.data() + (kCols - 1 - (n - 1) * stride) * kRows, A.rows(), n);
VERIFY_IS_EQUAL(int(slice.RowsAtCompileTime), int(block.RowsAtCompileTime));
VERIFY_IS_EQUAL(int(slice.ColsAtCompileTime), int(block.ColsAtCompileTime));
VERIFY_IS_EQUAL(slice, block);
}
// Compile time size and increment.
{
auto slice1 = v(seq(last - fix<7>, last - fix<2>));
auto slice2 = v(seqN(last - 7, fix<6>));
VERIFY_IS_EQUAL(slice1, slice2);
VERIFY_IS_EQUAL(int(slice1.SizeAtCompileTime), 6);
VERIFY_IS_EQUAL(int(slice2.SizeAtCompileTime), 6);
auto slice3 = A(all, seq(fix<0>, last, fix<2>));
TEST_SET_BUT_UNUSED_VARIABLE(slice3);
VERIFY_IS_EQUAL(int(slice3.RowsAtCompileTime), kRows);
VERIFY_IS_EQUAL(int(slice3.ColsAtCompileTime), (kCols + 1) / 2);
}
// Reverse order.
{
auto slice = A(all, seq(20, 10, fix<-2>));
auto block = Eigen::Map<Eigen::Matrix<double, kRows, Dynamic, ColMajor>, 0, OuterStride<-2 * kRows>>(
A.data() + 20 * kRows, A.rows(), (20 - 10 + 2) / 2);
VERIFY_IS_EQUAL(slice, block);
}
{
Index n = 10;
auto slice1 = A(seqN(last, n, fix<-1>), all);
auto slice2 = A(lastN(n).reverse(), all);
VERIFY_IS_EQUAL(slice1, slice2);
}
// Array of indices.
{
std::vector<int> ind{4, 2, 5, 5, 3};
auto slice1 = A(all, ind);
for (size_t i = 0; i < ind.size(); ++i) {
VERIFY_IS_EQUAL(slice1.col(i), A.col(ind[i]));
}
auto slice2 = A(all, {4, 2, 5, 5, 3});
VERIFY_IS_EQUAL(slice1, slice2);
Eigen::ArrayXi indarray(5);
indarray << 4, 2, 5, 5, 3;
auto slice3 = A(all, indarray);
VERIFY_IS_EQUAL(slice1, slice3);
}
// Custom index list.
{
struct pad {
Index size() const { return out_size; }
Index operator[](Index i) const { return std::max<Index>(0, i - (out_size - in_size)); }
Index in_size, out_size;
};
auto slice = A(pad{3, 5}, pad{3, 5});
Eigen::MatrixXd B = slice;
VERIFY_IS_EQUAL(B.block(2, 2, 3, 3), A.block(0, 0, 3, 3));
}
}
// Regression test for bug #1943: IndexedView with temporary expression indices.
void check_expression_indices() {
MatrixXd m(3, 4);
m << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12;
// Reshaped temporary as column index (was segfault before fix).
{
auto view = m(all, Array<int, 1, 1>{0}.reshaped());
VectorXd result = view;
VERIFY_IS_APPROX(result, m.col(0));
}
// Block expression as index.
{
ArrayXi idx(3);
idx << 0, 1, 2;
auto view = m(all, idx.head(2));
MatrixXd result = view;
VERIFY_IS_APPROX(result, m.leftCols(2));
}
// CwiseBinaryOp expression as index.
{
Array<int, 2, 1> base;
base << 0, 1;
auto view = m(all, base + 0);
MatrixXd result = view;
VERIFY_IS_APPROX(result, m.leftCols(2));
}
// Reverse expression as index.
{
Array<int, 3, 1> idx;
idx << 2, 1, 0;
auto view = m(all, idx.reverse());
MatrixXd result = view;
MatrixXd expected(3, 3);
expected << m.col(0), m.col(1), m.col(2);
VERIFY_IS_APPROX(result, expected);
}
// 1D vector indexed view (VectorIndexedViewSelector path).
{
VectorXd v(5);
v << 10, 20, 30, 40, 50;
ArrayXi idx(3);
idx << 4, 2, 0;
auto view = v(idx.reverse());
VectorXd result = view;
VectorXd expected(3);
expected << 10, 30, 50;
VERIFY_IS_APPROX(result, expected);
}
}
template <typename SelectXpr>
struct check_direct_select_evaluator {
static constexpr bool value = false;
};
template <typename Arg1, typename Arg2, typename Scalar, typename CmpLhsType, typename CmpRhsType,
internal::ComparisonName cmp>
struct check_direct_select_evaluator<
CwiseTernaryOp<internal::scalar_boolean_select_op<Scalar, Scalar, bool>, Arg1, Arg2,
CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, cmp, false>, CmpLhsType, CmpRhsType>>> {
using SelectXpr =
CwiseTernaryOp<internal::scalar_boolean_select_op<Scalar, Scalar, bool>, Arg1, Arg2,
CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, cmp, false>, CmpLhsType, CmpRhsType>>;
using PacketXpr =
CwiseTernaryOp<internal::scalar_boolean_select_op<Scalar, Scalar, Scalar>, Arg1, Arg2,
CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, cmp, true>, CmpLhsType, CmpRhsType>>;
using Eval = internal::evaluator<SelectXpr>;
using PacketEval = internal::ternary_evaluator<PacketXpr>;
static constexpr bool value =
std::is_same<typename Eval::XprType, SelectXpr>::value &&
std::is_base_of<internal::evaluator_base<SelectXpr>, Eval>::value &&
!std::is_base_of<internal::ternary_evaluator<SelectXpr>, Eval>::value &&
!std::is_base_of<PacketEval, Eval>::value && int(Eval::Flags) == int(PacketEval::Flags) &&
int(Eval::Alignment) == int(PacketEval::Alignment) && int(Eval::CoeffReadCost) == int(PacketEval::CoeffReadCost);
};
// Regression test for bug #3092: IndexedView nested in a comparison-based select expression.
void check_indexed_view_select() {
ArrayXXd values(3, 4);
values << 0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11;
ArrayXi indices(5);
indices << 0, 1, 2, 1, 0;
ArrayXd condition = ArrayXd::Zero(5);
using IndirectSelectXpr = std::decay_t<decltype((condition > 0.0).select(0.0, values(indices, 1)))>;
using DenseSelectXpr = std::decay_t<decltype((condition > 0.0).select(condition, condition))>;
using ColValues = Array<double, Dynamic, Dynamic, ColMajor>;
using RowValues = Array<double, Dynamic, Dynamic, RowMajor>;
using MixedOrderSelectXpr =
std::decay_t<decltype((std::declval<const ColValues&>() < std::declval<const RowValues&>())
.select(std::declval<const ColValues&>(), std::declval<const ColValues&>()))>;
STATIC_CHECK(check_direct_select_evaluator<IndirectSelectXpr>::value);
STATIC_CHECK(check_direct_select_evaluator<DenseSelectXpr>::value);
STATIC_CHECK(check_direct_select_evaluator<MixedOrderSelectXpr>::value);
STATIC_CHECK((int(internal::evaluator<IndirectSelectXpr>::Flags) & PacketAccessBit) == 0);
STATIC_CHECK((int(internal::evaluator<MixedOrderSelectXpr>::Flags) & (PacketAccessBit | LinearAccessBit)) == 0);
constexpr bool expect_dense_packet =
((int(internal::evaluator<ArrayXd>::Flags) & PacketAccessBit) != 0) && internal::packet_traits<double>::HasCmp;
STATIC_CHECK(((int(internal::evaluator<DenseSelectXpr>::Flags) & PacketAccessBit) != 0) == expect_dense_packet);
using ColBlockSelectXpr = std::decay_t<decltype((std::declval<const ColValues&>().block(1, 1, 1, 1) <
std::declval<const ColValues&>().block(2, 0, 1, 1))
.select(std::declval<const ColValues&>().block(0, 1, 1, 1),
std::declval<const ColValues&>().block(1, 2, 1, 1)))>;
using RowBlockSelectXpr = std::decay_t<decltype((std::declval<const RowValues&>().block(1, 1, 1, 1) <
std::declval<const RowValues&>().block(2, 0, 1, 1))
.select(std::declval<const RowValues&>().block(0, 1, 1, 1),
std::declval<const RowValues&>().block(1, 2, 1, 1)))>;
STATIC_CHECK(check_direct_select_evaluator<ColBlockSelectXpr>::value);
STATIC_CHECK(check_direct_select_evaluator<RowBlockSelectXpr>::value);
STATIC_CHECK(((int(internal::evaluator<ColBlockSelectXpr>::Flags) & PacketAccessBit) != 0) == expect_dense_packet);
STATIC_CHECK((int(internal::evaluator<ColBlockSelectXpr>::Flags) & LinearAccessBit) == 0);
STATIC_CHECK(((int(internal::evaluator<RowBlockSelectXpr>::Flags) & PacketAccessBit) != 0) == expect_dense_packet);
STATIC_CHECK((int(internal::evaluator<RowBlockSelectXpr>::Flags) & LinearAccessBit) == 0);
ArrayXd expected(5);
expected << 3, 4, 5, 4, 3;
ArrayXd result = (condition > 0.0).select(0.0, values(indices, 1));
VERIFY_IS_APPROX(result, expected);
result = (condition > 0.0).select(condition, values(indices, 1));
VERIFY_IS_APPROX(result, expected);
expected << 6, 7, 8, 7, 6;
result = (condition == 0.0).select(values(indices, 2), 0.0);
VERIFY_IS_APPROX(result, expected);
expected << 0, 1, 1, 1, 0;
result = (values(indices, 0) > 0.0).select(1.0, condition);
VERIFY_IS_APPROX(result, expected);
for (Index n : {Index(0), Index(1), Index(3), Index(7), Index(9)}) {
ArrayXd lhs = ArrayXd::LinSpaced(n, -2.0, 2.0);
ArrayXd rhs = ArrayXd::Zero(n);
ArrayXd a = ArrayXd::LinSpaced(n, 10.0, 20.0);
ArrayXd b = ArrayXd::LinSpaced(n, -10.0, -5.0);
ArrayXi idx = ArrayXi::LinSpaced(n, 0, n > 0 ? 2 : 0);
ArrayXd dense_res = (lhs < rhs).select(a, b);
ArrayXd nbv_res = (lhs < rhs).select(a.nestByValue(), b);
ArrayXd ind_res = (lhs < rhs).select(values(idx, 1), values(idx, 2));
for (Index i = 0; i < n; ++i) {
VERIFY_IS_EQUAL(dense_res(i), lhs(i) < rhs(i) ? a(i) : b(i));
VERIFY_IS_EQUAL(nbv_res(i), lhs(i) < rhs(i) ? a(i) : b(i));
VERIFY_IS_EQUAL(ind_res(i), lhs(i) < rhs(i) ? values(idx(i), 1) : values(idx(i), 2));
}
}
for (Index rows : {Index(0), Index(1), Index(3), Index(5), Index(7), Index(9)}) {
for (Index cols : {Index(0), Index(1), Index(3), Index(5), Index(7), Index(9)}) {
ColValues col_l = ColValues::Random(rows + 3, cols + 3);
ColValues col_r = ColValues::Random(rows + 3, cols + 3);
ColValues col_a = ColValues::Random(rows + 3, cols + 3);
ColValues col_b = ColValues::Random(rows + 3, cols + 3);
ColValues col_res = (col_l.block(1, 1, rows, cols) < col_r.block(2, 0, rows, cols))
.select(col_a.block(0, 1, rows, cols), col_b.block(1, 2, rows, cols));
VERIFY_IS_EQUAL(col_res.rows(), rows);
VERIFY_IS_EQUAL(col_res.cols(), cols);
RowValues row_l = col_l;
RowValues row_r = col_r;
RowValues row_a = col_a;
RowValues row_b = col_b;
RowValues row_res = (row_l.block(1, 1, rows, cols) < row_r.block(2, 0, rows, cols))
.select(row_a.block(0, 1, rows, cols), row_b.block(1, 2, rows, cols));
VERIFY_IS_EQUAL(row_res.rows(), rows);
VERIFY_IS_EQUAL(row_res.cols(), cols);
for (Index r = 0; r < rows; ++r) {
for (Index c = 0; c < cols; ++c) {
VERIFY_IS_EQUAL(col_res(r, c), col_l(r + 1, c + 1) < col_r(r + 2, c) ? col_a(r, c + 1) : col_b(r + 1, c + 2));
VERIFY_IS_EQUAL(row_res(r, c), row_l(r + 1, c + 1) < row_r(r + 2, c) ? row_a(r, c + 1) : row_b(r + 1, c + 2));
}
}
}
}
for (std::pair<Index, Index> shape :
{std::make_pair(Index(0), Index(3)), std::make_pair(Index(3), Index(0)), std::make_pair(Index(1), Index(1)),
std::make_pair(Index(3), Index(5)), std::make_pair(Index(7), Index(9))}) {
const Index rows = shape.first;
const Index cols = shape.second;
ColValues lhs = ColValues::Random(rows, cols);
RowValues row_rhs = RowValues::Random(rows, cols);
ColValues col_rhs = row_rhs;
ColValues a = ColValues::Random(rows, cols);
ColValues b = ColValues::Random(rows, cols);
ColValues mixed_res = (lhs < row_rhs).select(a, b);
RowValues mixed_row_res = (lhs < row_rhs).select(a, b);
ArrayXi rowIdx = ArrayXi::LinSpaced(rows, 0, rows > 0 ? 2 : 0);
ArrayXi colIdx = ArrayXi::LinSpaced(cols, 0, cols > 0 ? 3 : 0);
ColValues ind_branch_res = (lhs < col_rhs).select(values(rowIdx, colIdx), b);
ColValues ind_cmp_res = (values(rowIdx, colIdx) < col_rhs).select(a, b);
for (Index r = 0; r < rows; ++r) {
for (Index c = 0; c < cols; ++c) {
const double mixed_expected = lhs(r, c) < row_rhs(r, c) ? a(r, c) : b(r, c);
VERIFY_IS_EQUAL(mixed_res(r, c), mixed_expected);
VERIFY_IS_EQUAL(mixed_row_res(r, c), mixed_expected);
const double v = values(rowIdx(r), colIdx(c));
VERIFY_IS_EQUAL(ind_branch_res(r, c), lhs(r, c) < col_rhs(r, c) ? v : b(r, c));
VERIFY_IS_EQUAL(ind_cmp_res(r, c), v < col_rhs(r, c) ? a(r, c) : b(r, c));
}
}
}
}
// A single-column IndexedView is column major and a single-row one is row major
// whatever the nested expression is. Inheriting the nested RowMajorBit on top of
// that contradicted it: the plain object of a Dynamic-by-1 row-major expression
// is an invalid Matrix/Array type, so forming one failed to compile.
void check_indexed_view_storage_order() {
Array<double, Dynamic, Dynamic, RowMajor> values(3, 4);
values << 0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11;
ArrayXi indices(5);
indices << 0, 1, 2, 1, 0;
using ColumnView = std::decay_t<decltype(values(indices, 1))>;
using RowView = std::decay_t<decltype(values(1, indices))>;
STATIC_CHECK((int(internal::traits<ColumnView>::Flags) & RowMajorBit) == 0);
STATIC_CHECK((int(internal::traits<RowView>::Flags) & RowMajorBit) == RowMajorBit);
ArrayXd condition = ArrayXd::Zero(5);
ArrayXd expected(5);
expected << 0, 1, 1, 1, 0;
ArrayXd result = (values(indices, 0) > 0.0).select(1.0, condition);
VERIFY_IS_APPROX(result, expected);
expected << 3, 4, 5, 4, 3;
result = (condition > 0.0).select(0.0, values(indices, 1));
VERIFY_IS_APPROX(result, expected);
Array<double, 1, Dynamic> row_expected(4);
row_expected << 1, 4, 7, 4;
Array<double, 1, Dynamic> row_result = (values(1, indices.head(4)) > 0.0).select(values(1, indices.head(4)), 0.0);
VERIFY_IS_APPROX(row_result, row_expected);
}
template <typename View>
void verify_strides_address_coeffs(const View& view) {
for (Index j = 0; j < view.cols(); ++j) {
for (Index i = 0; i < view.rows(); ++i) {
VERIFY_IS_EQUAL(view.data()[i * view.rowStride() + j * view.colStride()], view.coeff(i, j));
}
}
}
// A vector-shaped view takes its own storage order, which can differ from the nested one; its strides must still
// address its coefficients.
template <typename MatrixType>
void check_indexed_view_strides() {
const MatrixType A = MatrixType::Random(6, 8);
verify_strides_address_coeffs(A(2, seq(0, 7, 2)));
verify_strides_address_coeffs(A(2, seq(0, 7, fix<2>)));
verify_strides_address_coeffs(A(seq(0, 5, 2), 3));
verify_strides_address_coeffs(A(seq(0, 5, fix<2>), 3));
verify_strides_address_coeffs(A(seq(0, 5, 2), seq(1, 7, 3)));
const Ref<const RowVectorXd, 0, InnerStride<>> row = A(2, seq(0, 7, 2));
VERIFY_IS_EQUAL(row, RowVectorXd(A(2, seq(0, 7, 2))));
const Ref<const VectorXd, 0, InnerStride<>> col = A(seq(0, 5, 2), 3);
VERIFY_IS_EQUAL(col, VectorXd(A(seq(0, 5, 2), 3)));
// Matrix-vector products read a direct-access vector operand through data() and innerStride().
const MatrixXd M = MatrixXd::Random(3, 4);
VERIFY_IS_APPROX(M * A(2, seq(0, 7, 2)).transpose(), M * RowVectorXd(A(2, seq(0, 7, 2))).transpose());
const MatrixXd N = MatrixXd::Random(4, 3);
VERIFY_IS_APPROX(N * A(seq(0, 5, 2), 3), N * VectorXd(A(seq(0, 5, 2), 3)));
}
void check_aliasing() {
Eigen::Vector<float, 5> z = {0.0f, 1.1f, 2.2f, 3.3f, 4.4f};
std::vector<int> left_indices = {0, 1, 3, 4};
std::vector<int> right_indices = {1, 3, 4, 0};
z(left_indices) = z(right_indices);
Eigen::Vector<float, 5> expected = {1.1f, 3.3f, 2.2f, 4.4f, 0.0f};
VERIFY_IS_EQUAL(z, expected);
}
// Vector-shaped views provide linear coeffRef(), like every other writable vector expression.
void check_vector_coeffRef() {
MatrixXd A = MatrixXd::Random(6, 5);
const std::vector<int> rows = {4, 0, 2};
auto col = A.col(1)(rows);
col.coeffRef(1) = 1.5;
VERIFY_IS_EQUAL(A(0, 1), 1.5);
const auto& constCol = col;
VERIFY_IS_EQUAL(constCol.coeffRef(2), A(2, 1));
auto row = A.row(3)(placeholders::lastN(3, 2));
row.coeffRef(0) = 2.5;
VERIFY_IS_EQUAL(A(3, 0), 2.5);
VERIFY_IS_EQUAL(row.coeffRef(2), A(3, 4));
// makeHouseholder() writes its essential part through coeffRef(i).
const VectorXd x = VectorXd::Random(4);
VectorXd expected(3), essential = VectorXd::Zero(6);
double tau, beta, tauRef, betaRef;
x.makeHouseholder(expected, tauRef, betaRef);
const std::vector<int> slots = {5, 1, 3};
auto essentialView = essential(slots);
x.makeHouseholder(essentialView, tau, beta);
VERIFY_IS_EQUAL(tau, tauRef);
VERIFY_IS_EQUAL(beta, betaRef);
VERIFY_IS_EQUAL(VectorXd(essential(slots)), expected);
}
// The size of seq(first, last, incr) must not be computed through last - first + incr, which can overflow.
void check_seq_size_overflow() {
const Index highest = NumTraits<Index>::highest();
const Index lowest = NumTraits<Index>::lowest();
VectorXd v = VectorXd::LinSpaced(4, 1, 4);
Vector4d v4 = v;
VERIFY_IS_EQUAL(seq(0, 3, highest - 1).size(), Index(1));
VERIFY_IS_EQUAL(seq(0, 3, highest).size(), Index(1));
VERIFY_IS_EQUAL(seq(3, 0, lowest + 1).size(), Index(1));
VERIFY_IS_EQUAL(seq(3, 0, lowest).size(), Index(1));
VERIFY_IS_EQUAL(seq(fix<0>, fix<3>, highest - 1).size(), Index(1));
// Fixed operands whose Diff + Incr does not fit in int.
VERIFY_IS_EQUAL(seq(fix<0>, fix<3>, fix<INT_MAX>).size(), Index(1));
VERIFY_IS_EQUAL(seq(fix<3>, fix<0>, fix<INT_MIN + 1>).size(), Index(1));
VERIFY_IS_EQUAL(seq(fix<0>, fix<INT_MAX>, fix<INT_MAX>).size(), Index(2));
VERIFY(is_same_seq_type(seq(fix<0>, fix<3>, fix<INT_MAX>), seqN(fix<0>, fix<1>, fix<INT_MAX>)));
VERIFY_IS_EQUAL(v(seq(0, 3, highest - 1)).size(), Index(1));
VERIFY_IS_EQUAL(v(seq(0, last, highest - 1)).size(), Index(1));
VERIFY_IS_EQUAL(v(seq(3, 0, lowest + 1)).size(), Index(1));
VERIFY_IS_EQUAL(v(seq(last, 0, lowest + 1)).size(), Index(1));
VERIFY_IS_EQUAL(v(seq(last, fix<0>, lowest + 1)).size(), Index(1));
VERIFY_IS_EQUAL(v4(seq(0, last, highest - 1)).size(), Index(1));
Index count = 0;
for (double& x : v(seq(0, last, highest - 1))) {
x = 0;
++count;
}
VERIFY_IS_EQUAL(count, Index(1));
VERIFY_IS_EQUAL(v, Vector4d(0, 2, 3, 4));
// The sizes are otherwise those of (last - first + incr) / incr, empty sequences included.
for (Index f = -1; f <= 5; ++f)
for (Index l = -1; l <= 5; ++l)
for (Index incr = -4; incr <= 4; ++incr) {
if (incr == 0) continue;
VERIFY_IS_EQUAL(seq(f, l, incr).size(), (l - f + incr) / incr);
}
VERIFY_IS_EQUAL(v(seq(0, last, 2)).size(), Index(2));
VERIFY_IS_EQUAL(v(seq(0, last, 3)).size(), Index(2));
VERIFY_IS_EQUAL(v(seq(1, last, 3)).size(), Index(1));
VERIFY_IS_EQUAL(v(seq(last + 1, last, 2)).size(), Index(0));
VERIFY_IS_EQUAL(v(seq(last, 0, -2)).size(), Index(2));
VERIFY_IS_EQUAL(v(seq(last, 0, fix<-3>)).size(), Index(2));
// Compile-time sizes are preserved.
VERIFY(is_same_seq_type(seq(fix<1>, fix<6>, fix<2>), seqN(fix<1>, fix<3>, fix<2>)));
VERIFY_IS_EQUAL(int(v4(seq(fix<0>, last, fix<2>)).SizeAtCompileTime), 2);
VERIFY_IS_EQUAL(int(v4(seq(last, fix<0>, fix<-3>)).SizeAtCompileTime), 2);
VERIFY_IS_EQUAL(int(v4(seq(0, last, 2)).SizeAtCompileTime), int(Dynamic));
}
// lastN(size, incr) computes its first index, last - (size - 1) * incr, in Index whatever the types of its arguments.
void check_lastN_index_arithmetic() {
EIGEN_IF_CONSTEXPR (std::numeric_limits<Index>::digits > std::numeric_limits<int>::digits) {
// (count - 1) * step == 2^31 does not fit in an int.
int count = 3, step = 1 << 30;
Index back = 2 * Index(step) + 5;
VERIFY_IS_EQUAL(lastN(count, step).firstObject().eval(last = back), Index(5));
VERIFY_IS_EQUAL(lastN(count, fix<1 << 30>).firstObject().eval(last = back), Index(5));
VERIFY_IS_EQUAL(lastN(fix<3>, step).firstObject().eval(last = back), Index(5));
VERIFY_IS_EQUAL(lastN(3u, step).firstObject().eval(last = back), Index(5));
VERIFY_IS_EQUAL(lastN(fix<Dynamic>(count), fix<DynamicIndex>(step)).firstObject().eval(last = back), Index(5));
}
const VectorXd v = VectorXd::LinSpaced(6, 0, 5);
// An unsigned size of 0 must not wrap around in size - 1.
VERIFY_IS_EQUAL(v(lastN(0u, fix<1>)).size(), Index(0));
VERIFY_IS_EQUAL(v(lastN(0u, 2)).size(), Index(0));
VERIFY(MATCH(v(lastN(3u, 2)), "1\n3\n5"));
VERIFY(MATCH(v(lastN(std::size_t(3), short(2))), "1\n3\n5"));
VERIFY(MATCH(v(lastN(fix<3>, fix<2>)), "1\n3\n5"));
VERIFY(MATCH(v(lastN(fix<3>(3), fix<2>(2))), "1\n3\n5"));
VERIFY(MATCH(v(lastN(fix<Dynamic>(3), fix<DynamicIndex>(2))), "1\n3\n5"));
VERIFY(MATCH(v(lastN(lastp1 / 2, 2)), "1\n3\n5"));
VERIFY(v(lastN(fix<3>(3), fix<2>(2))).SizeAtCompileTime == 3);
}
// traits<>::Alignment promises an alignment of data(). MapBase asserts it (reached through reshaped()) and the
// vectorized 4x4 inverse stores with it. A view can start at any coefficient, so it must not inherit the promise.
template <typename Scalar>
void check_indexed_view_alignment() {
using ColMat = Matrix<Scalar, Dynamic, Dynamic, ColMajor>;
using RowMat = Matrix<Scalar, Dynamic, Dynamic, RowMajor>;
using Vec = Matrix<Scalar, Dynamic, 1>;
using Mat4 = Matrix<Scalar, 4, 4>;
STATIC_CHECK(int(internal::traits<decltype(std::declval<ColMat&>()(seqN(1, 4), seqN(1, 4, 2)))>::Alignment) == 0);
STATIC_CHECK(int(internal::traits<decltype(std::declval<Vec&>()(seqN(1, 4, 2)))>::Alignment) == 0);
const Vec v = Vec::Random(32);
const Mat4 m = Mat4::Random() + Scalar(8) * Mat4::Identity();
const Mat4 inv = m.inverse();
// start moves the first coefficient of each view across the scalar offsets inside a packet.
for (Index start = 0; start < 4; ++start) {
const Vec strided = v(seqN(start, 12, 2));
VERIFY_IS_EQUAL(ColMat(v(seqN(start, 12, 2)).reshaped(3, 4)), ColMat(strided.reshaped(3, 4)));
// Both views have a unit inner increment, so the kernel's packet stores are contiguous coefficients.
ColMat colGrid = ColMat::Zero(9, 9), colExpected = ColMat::Zero(9, 9);
RowMat rowGrid = RowMat::Zero(9, 9), rowExpected = RowMat::Zero(9, 9);
for (Index j = 0; j < 4; ++j) {
for (Index i = 0; i < 4; ++i) {
colExpected(start + i, 1 + 2 * j) = inv(i, j);
rowExpected(1 + 2 * i, start + j) = inv(i, j);
}
}
colGrid(seqN(start, 4), seqN(1, 4, 2)) = m.inverse();
VERIFY_IS_APPROX(colGrid, colExpected);
rowGrid(seqN(1, 4, 2), seqN(start, 4)) = m.inverse();
VERIFY_IS_APPROX(rowGrid, rowExpected);
}
}
EIGEN_DECLARE_TEST(indexed_view) {
for (int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1(check_indexed_view());
}
CALL_SUBTEST_1(check_tutorial_examples());
CALL_SUBTEST_1(check_expression_indices());
CALL_SUBTEST_1(check_indexed_view_select());
CALL_SUBTEST_1(check_indexed_view_storage_order());
CALL_SUBTEST_1(check_indexed_view_strides<MatrixXd>());
CALL_SUBTEST_1((check_indexed_view_strides<Matrix<double, Dynamic, Dynamic, RowMajor>>()));
CALL_SUBTEST_1((check_indexed_view_strides<Matrix<double, 6, 8>>()));
CALL_SUBTEST_1((check_indexed_view_strides<Matrix<double, 6, 8, RowMajor>>()));
CALL_SUBTEST_1(check_aliasing());
CALL_SUBTEST_1(check_vector_coeffRef());
CALL_SUBTEST_1(check_seq_size_overflow());
CALL_SUBTEST_1(check_lastN_index_arithmetic());
CALL_SUBTEST_1(check_indexed_view_alignment<float>());
CALL_SUBTEST_1(check_indexed_view_alignment<double>());
// static checks of some internals:
STATIC_CHECK((internal::is_valid_index_type<int>::value));
STATIC_CHECK((internal::is_valid_index_type<unsigned int>::value));
STATIC_CHECK((internal::is_valid_index_type<short>::value));
STATIC_CHECK((internal::is_valid_index_type<std::ptrdiff_t>::value));
STATIC_CHECK((internal::is_valid_index_type<std::size_t>::value));
STATIC_CHECK((!internal::valid_indexed_view_overload<int, int>::value));
STATIC_CHECK((!internal::valid_indexed_view_overload<int, std::ptrdiff_t>::value));
STATIC_CHECK((!internal::valid_indexed_view_overload<std::ptrdiff_t, int>::value));
STATIC_CHECK((!internal::valid_indexed_view_overload<std::size_t, int>::value));
}