Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.core
Commits
2ac8c84e
Commit
2ac8c84e
authored
Jul 31, 2014
by
André Anjos
💬
Browse files
Move cast into a header-only scenario
parent
67e753b6
Changes
4
Hide whitespace changes
Inline
Side-by-side
bob/core/cpp/complex_cast.cpp
deleted
100644 → 0
View file @
67e753b6
/**
* @date Wed Feb 9 16:19:18 2011 +0100
* @author Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
*
* @brief This file defines functions which add std::complex support to the
* static_cast function.
*
* Copyright (C) Idiap Research Institute, Martigny, Switzerland
*/
#include "complex_cast.h"
/**
* @brief Specializations of the cast function for the std::complex type.
*/
// Complex to regular
#define COMPLEX_TO_REGULAR(COMP, REG) template<> \
REG bob::core::cast<REG, COMP>( const COMP& in) \
{ \
return static_cast<REG>(in.real()); \
}
#define COMPLEX_TO_REGULAR_FULL(COMP) \
COMPLEX_TO_REGULAR(COMP, bool) \
COMPLEX_TO_REGULAR(COMP, int8_t) \
COMPLEX_TO_REGULAR(COMP, int16_t) \
COMPLEX_TO_REGULAR(COMP, int32_t) \
COMPLEX_TO_REGULAR(COMP, int64_t) \
COMPLEX_TO_REGULAR(COMP, uint8_t) \
COMPLEX_TO_REGULAR(COMP, uint16_t) \
COMPLEX_TO_REGULAR(COMP, uint32_t) \
COMPLEX_TO_REGULAR(COMP, uint64_t) \
COMPLEX_TO_REGULAR(COMP, float) \
COMPLEX_TO_REGULAR(COMP, double) \
COMPLEX_TO_REGULAR(COMP, long double)
COMPLEX_TO_REGULAR_FULL
(
std
::
complex
<
float
>
)
COMPLEX_TO_REGULAR_FULL
(
std
::
complex
<
double
>
)
COMPLEX_TO_REGULAR_FULL
(
std
::
complex
<
long
double
>
)
// Complex to complex
#define COMPLEX_TO_COMPLEX(FROM, TO) template<> \
TO bob::core::cast<TO, FROM>( const FROM& in) \
{ \
return static_cast<TO>(in); \
}
#define COMPLEX_TO_COMPLEX_FULL(COMP) \
COMPLEX_TO_COMPLEX(COMP, std::complex<float>) \
COMPLEX_TO_COMPLEX(COMP, std::complex<double>) \
COMPLEX_TO_COMPLEX(COMP, std::complex<long double>)
COMPLEX_TO_COMPLEX_FULL
(
std
::
complex
<
float
>
)
COMPLEX_TO_COMPLEX_FULL
(
std
::
complex
<
double
>
)
COMPLEX_TO_COMPLEX_FULL
(
std
::
complex
<
long
double
>
)
bob/core/cpp/complex_cast.h
deleted
100644 → 0
View file @
67e753b6
/**
* @date Wed Feb 9 12:26:11 2011 +0100
* @author Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
*
* @brief This file defines functions which add std::complex support to the
* static_cast function.
*
* Copyright (C) Idiap Research Institute, Martigny, Switzerland
*/
#ifndef BOB_CORE_COMPLEX_CAST_H
#define BOB_CORE_COMPLEX_CAST_H
#include <complex>
#include <stdint.h>
#include <bob.core/cast.h>
namespace
bob
{
namespace
core
{
// Complex to regular
# define COMPLEX_TO_REGULAR_DECL(COMP, REG) template<> \
REG cast<REG, COMP>( const COMP& in);
# define COMPLEX_TO_REGULAR_FULL_DECL(COMP) \
COMPLEX_TO_REGULAR_DECL(COMP, bool) \
COMPLEX_TO_REGULAR_DECL(COMP, int8_t) \
COMPLEX_TO_REGULAR_DECL(COMP, int16_t) \
COMPLEX_TO_REGULAR_DECL(COMP, int32_t) \
COMPLEX_TO_REGULAR_DECL(COMP, int64_t) \
COMPLEX_TO_REGULAR_DECL(COMP, uint8_t) \
COMPLEX_TO_REGULAR_DECL(COMP, uint16_t) \
COMPLEX_TO_REGULAR_DECL(COMP, uint32_t) \
COMPLEX_TO_REGULAR_DECL(COMP, uint64_t) \
COMPLEX_TO_REGULAR_DECL(COMP, float) \
COMPLEX_TO_REGULAR_DECL(COMP, double) \
COMPLEX_TO_REGULAR_DECL(COMP, long double)
COMPLEX_TO_REGULAR_FULL_DECL
(
std
::
complex
<
float
>
)
COMPLEX_TO_REGULAR_FULL_DECL
(
std
::
complex
<
double
>
)
COMPLEX_TO_REGULAR_FULL_DECL
(
std
::
complex
<
long
double
>
)
// Complex to complex
# define COMPLEX_TO_COMPLEX_DECL(FROM, TO) template<> \
TO cast<TO, FROM>( const FROM& in);
# define COMPLEX_TO_COMPLEX_FULL_DECL(COMP) \
COMPLEX_TO_COMPLEX_DECL(COMP, std::complex<float>) \
COMPLEX_TO_COMPLEX_DECL(COMP, std::complex<double>) \
COMPLEX_TO_COMPLEX_DECL(COMP, std::complex<long double>)
COMPLEX_TO_COMPLEX_FULL_DECL
(
std
::
complex
<
float
>
)
COMPLEX_TO_COMPLEX_FULL_DECL
(
std
::
complex
<
double
>
)
COMPLEX_TO_COMPLEX_FULL_DECL
(
std
::
complex
<
long
double
>
)
}}
#endif
/* BOB_CORE_COMPLEX_CAST_H */
bob/core/include/bob.core/cast.h
View file @
2ac8c84e
...
...
@@ -13,21 +13,27 @@
#include <bob.core/assert.h>
#include <blitz/array.h>
#include <complex>
namespace
bob
{
namespace
core
{
template
<
typename
T
,
typename
U
>
T
cast
(
const
U
&
in
)
{
return
static_cast
<
T
>
(
in
);
}
namespace
array
{
template
<
typename
T
,
typename
U
>
T
scalar_cast
(
const
U
&
u
)
{
return
static_cast
<
T
>
(
u
);
}
template
<
typename
T
,
typename
U
>
T
scalar_cast
(
const
std
::
complex
<
U
>&
u
)
{
return
static_cast
<
T
>
(
u
.
real
());
}
// when using matching complex or non-complex T and U
template
<
typename
T
,
typename
U
>
blitz
::
Array
<
T
,
1
>
cast
(
const
blitz
::
Array
<
U
,
1
>&
in
)
{
bob
::
core
::
array
::
assertZeroBase
(
in
);
blitz
::
Array
<
T
,
1
>
out
(
in
.
extent
(
0
));
for
(
int
i
=
0
;
i
<
in
.
extent
(
0
);
++
i
)
out
(
i
)
=
bob
::
core
::
cast
<
T
>
(
in
(
i
));
out
(
i
)
=
scalar_
cast
<
T
,
U
>
(
in
(
i
));
return
out
;
}
...
...
@@ -37,7 +43,7 @@ namespace bob { namespace core {
blitz
::
Array
<
T
,
2
>
out
(
in
.
extent
(
0
),
in
.
extent
(
1
));
for
(
int
i
=
0
;
i
<
in
.
extent
(
0
);
++
i
)
for
(
int
j
=
0
;
j
<
in
.
extent
(
1
);
++
j
)
out
(
i
,
j
)
=
bob
::
core
::
cast
<
T
>
(
in
(
i
,
j
)
);
out
(
i
,
j
)
=
scalar_
cast
<
T
,
U
>
(
in
(
i
,
j
));
return
out
;
}
...
...
@@ -48,7 +54,7 @@ namespace bob { namespace core {
for
(
int
i
=
0
;
i
<
in
.
extent
(
0
);
++
i
)
for
(
int
j
=
0
;
j
<
in
.
extent
(
1
);
++
j
)
for
(
int
k
=
0
;
k
<
in
.
extent
(
2
);
++
k
)
out
(
i
,
j
,
k
)
=
bob
::
core
::
cast
<
T
>
(
in
(
i
,
j
,
k
)
);
out
(
i
,
j
,
k
)
=
scalar_
cast
<
T
>
(
in
(
i
,
j
,
k
));
return
out
;
}
...
...
@@ -60,7 +66,7 @@ namespace bob { namespace core {
for
(
int
j
=
0
;
j
<
in
.
extent
(
1
);
++
j
)
for
(
int
k
=
0
;
k
<
in
.
extent
(
2
);
++
k
)
for
(
int
l
=
0
;
l
<
in
.
extent
(
3
);
++
l
)
out
(
i
,
j
,
k
,
l
)
=
bob
::
core
::
cast
<
T
>
(
in
(
i
,
j
,
k
,
l
)
);
out
(
i
,
j
,
k
,
l
)
=
scalar_
cast
<
T
,
U
>
(
in
(
i
,
j
,
k
,
l
));
return
out
;
}
...
...
setup.py
View file @
2ac8c84e
...
...
@@ -45,7 +45,6 @@ setup(
"bob/core/cpp/array.cpp"
,
"bob/core/cpp/array_type.cpp"
,
"bob/core/cpp/blitz_array.cpp"
,
"bob/core/cpp/complex_cast.cpp"
,
"bob/core/version.cpp"
,
],
version
=
version
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment