Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_random.cpp
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5
//
6
// This Source Code Form is subject to the terms of the Mozilla
7
// Public License v. 2.0. If a copy of the MPL was not distributed
8
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
#include "
main.h
"
11
12
#include <Eigen/CXX11/Tensor>
13
14
static
void
test_default
()
15
{
16
Tensor<float, 1>
vec(6);
17
vec.
setRandom
();
18
19
// Fixme: we should check that the generated numbers follow a uniform
20
// distribution instead.
21
for
(
int
i
= 1;
i
< 6; ++
i
) {
22
VERIFY_IS_NOT_EQUAL
(vec(
i
), vec(
i
-1));
23
}
24
}
25
26
static
void
test_normal
()
27
{
28
Tensor<float, 1>
vec(6);
29
vec.
setRandom
<
Eigen::internal::NormalRandomGenerator<float>
>();
30
31
// Fixme: we should check that the generated numbers follow a gaussian
32
// distribution instead.
33
for
(
int
i
= 1;
i
< 6; ++
i
) {
34
VERIFY_IS_NOT_EQUAL
(vec(
i
), vec(
i
-1));
35
}
36
}
37
38
39
struct
MyGenerator
{
40
MyGenerator
() { }
41
MyGenerator
(
const
MyGenerator
&) { }
42
43
// Return a random value to be used. "element_location" is the
44
// location of the entry to set in the tensor, it can typically
45
// be ignored.
46
int
operator()
(
Eigen::DenseIndex
element_location,
Eigen::DenseIndex
/*unused*/
= 0)
const
{
47
return
static_cast<
int
>
(3 * element_location);
48
}
49
50
// Same as above but generates several numbers at a time.
51
internal::packet_traits<int>::type
packetOp
(
52
Eigen::DenseIndex
packet_location,
Eigen::DenseIndex
/*unused*/
= 0)
const
{
53
const
int
packetSize =
internal::packet_traits<int>::size
;
54
EIGEN_ALIGN_MAX
int
values
[packetSize];
55
for
(
int
i
= 0;
i
< packetSize; ++
i
) {
56
values[
i
] =
static_cast<
int
>
(3 * (packet_location +
i
));
57
}
58
return
internal::pload<typename internal::packet_traits<int>::type
>(
values
);
59
}
60
};
61
62
63
static
void
test_custom
()
64
{
65
Tensor<int, 1>
vec(6);
66
vec.
setRandom
<
MyGenerator
>();
67
68
for
(
int
i
= 0;
i
< 6; ++
i
) {
69
VERIFY_IS_EQUAL
(vec(
i
), 3*
i
);
70
}
71
}
72
73
void
test_cxx11_tensor_random
()
74
{
75
CALL_SUBTEST
(
test_default
());
76
CALL_SUBTEST
(
test_normal
());
77
CALL_SUBTEST
(
test_custom
());
78
}
gtsam.examples.DogLegOptimizerExample.type
type
Definition:
DogLegOptimizerExample.py:111
VERIFY_IS_NOT_EQUAL
#define VERIFY_IS_NOT_EQUAL(a, b)
Definition:
main.h:332
leaf::values
leaf::MyValues values
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setRandom
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition:
TensorBase.h:850
main.h
test_default
static void test_default()
Definition:
cxx11_tensor_random.cpp:14
size
Scalar Scalar int size
Definition:
benchVecAdd.cpp:17
MyGenerator::operator()
int operator()(Eigen::DenseIndex element_location, Eigen::DenseIndex=0) const
Definition:
cxx11_tensor_random.cpp:46
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:331
MyGenerator::packetOp
internal::packet_traits< int >::type packetOp(Eigen::DenseIndex packet_location, Eigen::DenseIndex=0) const
Definition:
cxx11_tensor_random.cpp:51
MyGenerator
Definition:
cxx11_tensor_random.cpp:39
Eigen::DenseIndex
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition:
Meta.h:25
Eigen::Triplet< double >
test_normal
static void test_normal()
Definition:
cxx11_tensor_random.cpp:26
MyGenerator::MyGenerator
MyGenerator()
Definition:
cxx11_tensor_random.cpp:40
Eigen::internal::NormalRandomGenerator
Definition:
TensorRandom.h:222
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:342
EIGEN_ALIGN_MAX
#define EIGEN_ALIGN_MAX
Definition:
Macros.h:757
test_custom
static void test_custom()
Definition:
cxx11_tensor_random.cpp:63
test_cxx11_tensor_random
void test_cxx11_tensor_random()
Definition:
cxx11_tensor_random.cpp:73
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
MyGenerator::MyGenerator
MyGenerator(const MyGenerator &)
Definition:
cxx11_tensor_random.cpp:41
gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:56