mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-08 11:29:02 +00:00
Introductory pyexpander macros for Math functions
This commit is contained in:
parent
1442400018
commit
b4a4534dbe
@ -139,7 +139,7 @@ vtkm_install_headers(
|
||||
# * Meta programming language
|
||||
find_package(BoostHeaders ${VTKm_REQUIRED_BOOST_VERSION} REQUIRED)
|
||||
|
||||
#####find_package(Pyexpander)
|
||||
find_package(Pyexpander)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Add subdirectories
|
||||
|
@ -24,6 +24,7 @@ set(headers
|
||||
CellType.h
|
||||
Extent.h
|
||||
ListTag.h
|
||||
Math.h
|
||||
Pair.h
|
||||
RegularConnectivity.h
|
||||
RegularStructure.h
|
||||
@ -33,6 +34,8 @@ set(headers
|
||||
VecTraits.h
|
||||
)
|
||||
|
||||
vtkm_pyexpander_generated_file(Math.h)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
86
vtkm/Math.h
Normal file
86
vtkm/Math.h
Normal file
@ -0,0 +1,86 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2015 Sandia Corporation.
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//
|
||||
//=============================================================================
|
||||
// **** DO NOT EDIT THIS FILE!!! ****
|
||||
// This file is automatically generated by FunctionInterfaceDetailPre.h.in
|
||||
|
||||
#ifndef vtk_m_Math_h
|
||||
#define vtk_m_Math_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#ifndef VTKM_CUDA
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#define VTKM_SYS_MATH_FUNCTION_32(func) func ## f
|
||||
#define VTKM_SYS_MATH_FUNCTION_64(func) func
|
||||
|
||||
|
||||
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// Compute the square root of \p x.
|
||||
///
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Float32 Sqrt(vtkm::Float32 x) {
|
||||
return VTKM_SYS_MATH_FUNCTION_32(sqrt)(x);
|
||||
}
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Float64 Sqrt(vtkm::Float64 x) {
|
||||
return VTKM_SYS_MATH_FUNCTION_64(sqrt)(x);
|
||||
}
|
||||
template<typename T, vtkm::IdComponent N>
|
||||
vtkm::Vec<T,N> Sqrt(const vtkm::Vec<T,N> x) {
|
||||
vtkm::Vec<T,N> result;
|
||||
for (vtkm::IdComponent index = 0; index < N; index++)
|
||||
{
|
||||
result[index] = vtkm::Sqrt(x[index]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,4> Sqrt(const vtkm::Vec<T,4> x) {
|
||||
return vtkm::Vec<T,4>(vtkm::Sqrt(x[0]),
|
||||
vtkm::Sqrt(x[1]),
|
||||
vtkm::Sqrt(x[2]),
|
||||
vtkm::Sqrt(x[3]));
|
||||
}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,3> Sqrt(const vtkm::Vec<T,3> x) {
|
||||
return vtkm::Vec<T,3>(vtkm::Sqrt(x[0]),
|
||||
vtkm::Sqrt(x[1]),
|
||||
vtkm::Sqrt(x[2]));
|
||||
}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,2> Sqrt(const vtkm::Vec<T,2> x) {
|
||||
return vtkm::Vec<T,2>(vtkm::Sqrt(x[0]),
|
||||
vtkm::Sqrt(x[1]));
|
||||
}
|
||||
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_Math_h
|
109
vtkm/Math.h.in
Normal file
109
vtkm/Math.h.in
Normal file
@ -0,0 +1,109 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2015 Sandia Corporation.
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//
|
||||
//=============================================================================
|
||||
$# This file uses the pyexpander macro processing utility to build the
|
||||
$# FunctionInterface facilities that use a variable number of arguments.
|
||||
$# Information, documentation, and downloads for pyexpander can be found at:
|
||||
$#
|
||||
$# http://pyexpander.sourceforge.net/
|
||||
$#
|
||||
$# To build the source code, execute the following (after installing
|
||||
$# pyexpander, of course):
|
||||
$#
|
||||
$# expander.py Math.h.in > Math.h
|
||||
$#
|
||||
$# Ignore the following comment. It is meant for the generated file.
|
||||
// **** DO NOT EDIT THIS FILE!!! ****
|
||||
// This file is automatically generated by FunctionInterfaceDetailPre.h.in
|
||||
|
||||
#ifndef vtk_m_Math_h
|
||||
#define vtk_m_Math_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#ifndef VTKM_CUDA
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#define VTKM_SYS_MATH_FUNCTION_32(func) func ## f
|
||||
#define VTKM_SYS_MATH_FUNCTION_64(func) func
|
||||
|
||||
$py(
|
||||
def unary_function(name, type, expression):
|
||||
return '''VTKM_EXEC_CONT_EXPORT
|
||||
{1} {0}({1} x) {{
|
||||
return {2};
|
||||
}}
|
||||
'''.format(name, type, expression)
|
||||
|
||||
def unary_Vec_function(vtkmname):
|
||||
return '''template<typename T, vtkm::IdComponent N>
|
||||
vtkm::Vec<T,N> {0}(const vtkm::Vec<T,N> x) {{
|
||||
vtkm::Vec<T,N> result;
|
||||
for (vtkm::IdComponent index = 0; index < N; index++)
|
||||
{{
|
||||
result[index] = vtkm::{0}(x[index]);
|
||||
}}
|
||||
return result;
|
||||
}}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,4> {0}(const vtkm::Vec<T,4> x) {{
|
||||
return vtkm::Vec<T,4>(vtkm::{0}(x[0]),
|
||||
vtkm::{0}(x[1]),
|
||||
vtkm::{0}(x[2]),
|
||||
vtkm::{0}(x[3]));
|
||||
}}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,3> {0}(const vtkm::Vec<T,3> x) {{
|
||||
return vtkm::Vec<T,3>(vtkm::{0}(x[0]),
|
||||
vtkm::{0}(x[1]),
|
||||
vtkm::{0}(x[2]));
|
||||
}}
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,2> {0}(const vtkm::Vec<T,2> x) {{
|
||||
return vtkm::Vec<T,2>(vtkm::{0}(x[0]),
|
||||
vtkm::{0}(x[1]));
|
||||
}}
|
||||
'''.format(vtkmname)
|
||||
|
||||
def unary_math_function(vtkmname, sysname):
|
||||
return unary_function(vtkmname,
|
||||
'vtkm::Float32',
|
||||
'VTKM_SYS_MATH_FUNCTION_32(' + sysname + ')(x)') + \
|
||||
unary_function(vtkmname,
|
||||
'vtkm::Float64',
|
||||
'VTKM_SYS_MATH_FUNCTION_64(' + sysname + ')(x)') + \
|
||||
unary_Vec_function(vtkmname)
|
||||
)
|
||||
$extend(unary_math_function)
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// Compute the square root of \p x.
|
||||
///
|
||||
$unary_math_function('Sqrt', 'sqrt')
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_Math_h
|
Loading…
Reference in New Issue
Block a user