Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79879543
Allocate.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 28, 18:36
Size
2 KB
Mime Type
text/x-c
Expires
Fri, Aug 30, 18:36 (2 d)
Engine
blob
Format
Raw Data
Handle
20250471
Attached To
rGOOSEFEM GooseFEM
Allocate.cpp
View Options
#include <catch2/catch.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor/xmath.hpp>
#include <GooseFEM/GooseFEM.h>
#define ISCLOSE(a,b) REQUIRE_THAT((a), Catch::WithinAbs((b), 1.e-12));
TEST_CASE
(
"GooseFEM::Allocate"
,
"Allocate.h"
)
{
SECTION
(
"asTensor - pre-allocated output"
)
{
xt
::
xtensor
<
int
,
2
>
a0
=
{
{
1
,
2
},
{
3
,
4
}};
xt
::
xtensor
<
int
,
3
>
a1
=
{
{{
1
,
1
,
1
},
{
2
,
2
,
2
}},
{{
3
,
3
,
3
},
{
4
,
4
,
4
}}};
xt
::
xtensor
<
int
,
4
>
a2
=
{
{{{
1
,
1
},
{
1
,
1
},
{
1
,
1
}},
{{
2
,
2
},
{
2
,
2
},
{
2
,
2
}}},
{{{
3
,
3
},
{
3
,
3
},
{
3
,
3
}},
{{
4
,
4
},
{
4
,
4
},
{
4
,
4
}}}};
xt
::
xtensor
<
int
,
3
>
b1
=
xt
::
empty
<
int
>
({
2
,
2
,
3
});
xt
::
xtensor
<
int
,
4
>
b2
=
xt
::
empty
<
int
>
({
2
,
2
,
3
,
2
});
GooseFEM
::
asTensor
(
a0
,
b1
);
GooseFEM
::
asTensor
(
a0
,
b2
);
REQUIRE
(
xt
::
all
(
xt
::
equal
(
a1
,
b1
)));
REQUIRE
(
xt
::
all
(
xt
::
equal
(
a2
,
b2
)));
}
SECTION
(
"asTensor - return"
)
{
xt
::
xtensor
<
int
,
2
>
a0
=
{
{
1
,
2
},
{
3
,
4
}};
xt
::
xtensor
<
int
,
3
>
a1
=
{
{{
1
,
1
,
1
},
{
2
,
2
,
2
}},
{{
3
,
3
,
3
},
{
4
,
4
,
4
}}};
xt
::
xtensor
<
int
,
4
>
a2
=
{
{{{
1
,
1
},
{
1
,
1
},
{
1
,
1
}},
{{
2
,
2
},
{
2
,
2
},
{
2
,
2
}}},
{{{
3
,
3
},
{
3
,
3
},
{
3
,
3
}},
{{
4
,
4
},
{
4
,
4
},
{
4
,
4
}}}};
auto
b1
=
GooseFEM
::
AsTensor
<
1
>
(
a0
,
3
);
auto
c1
=
GooseFEM
::
AsTensor
(
1
,
a0
,
3
);
auto
b2
=
GooseFEM
::
AsTensor
(
a0
,
{
3
,
2
});
static_assert
(
std
::
is_same
<
decltype
(
b1
),
decltype
(
a1
)
>::
value
,
"X"
);
static_assert
(
std
::
is_same
<
decltype
(
b2
),
decltype
(
a2
)
>::
value
,
"X"
);
static_assert
(
std
::
is_same
<
decltype
(
c1
),
xt
::
xarray
<
int
>>::
value
,
"X"
);
REQUIRE
(
xt
::
all
(
xt
::
equal
(
a1
,
b1
)));
REQUIRE
(
xt
::
all
(
xt
::
equal
(
a1
,
c1
)));
REQUIRE
(
xt
::
all
(
xt
::
equal
(
a2
,
b2
)));
}
SECTION
(
"as3d"
)
{
xt
::
xtensor
<
int
,
2
>
a1
=
{
{
1
},
{
3
}};
xt
::
xtensor
<
int
,
2
>
b1
=
{
{
1
,
0
,
0
},
{
3
,
0
,
0
}};
xt
::
xtensor
<
int
,
2
>
a2
=
{
{
1
,
2
},
{
3
,
4
}};
xt
::
xtensor
<
int
,
2
>
b2
=
{
{
1
,
2
,
0
},
{
3
,
4
,
0
}};
xt
::
xtensor
<
int
,
2
>
a3
=
{
{
1
,
2
,
5
},
{
3
,
4
,
6
}};
xt
::
xtensor
<
int
,
2
>
b3
=
{
{
1
,
2
,
5
},
{
3
,
4
,
6
}};
REQUIRE
(
xt
::
all
(
xt
::
equal
(
GooseFEM
::
as3d
(
a1
),
b1
)));
REQUIRE
(
xt
::
all
(
xt
::
equal
(
GooseFEM
::
as3d
(
a2
),
b2
)));
REQUIRE
(
xt
::
all
(
xt
::
equal
(
GooseFEM
::
as3d
(
a3
),
b3
)));
}
}
Event Timeline
Log In to Comment