Skip to content

Commit

Permalink
Build PyImath from MetaPy not Imath.
Browse files Browse the repository at this point in the history
  • Loading branch information
furby-tm committed Feb 14, 2024
1 parent c9236e4 commit e7e3537
Show file tree
Hide file tree
Showing 80 changed files with 26,274 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ let package = Package(
Arch.OS.python(),
],
exclude: [
/* prefer pybindimath */
/* metapy builds pyimath. */
"src/python/PyBindImath",
"src/python/PyImath",
"src/python/PyImathTest",
"src/python/PyImathNumpy",
Expand Down Expand Up @@ -527,6 +528,7 @@ let package = Package(
exclude: getConfig(for: .mpy).exclude,
publicHeadersPath: "include/python",
cxxSettings: [
.headerSearchPath("include/python/PyImath"),
.headerSearchPath("include/python/PyAlembic"),
.headerSearchPath("include/python/PyOIIO"),
]
Expand Down
27 changes: 27 additions & 0 deletions Sources/MetaPy/PyImath/PyImath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenEXR Project.
//

// clang-format off

#include "PyImath.h"
#include "PyImathExport.h"

namespace PyImath {

template <> PYIMATH_EXPORT const char * BoolArray::name() { return "BoolArray"; }
template <> PYIMATH_EXPORT const char * SignedCharArray::name() { return "SignedCharArray"; }
template <> PYIMATH_EXPORT const char * UnsignedCharArray::name() { return "UnsignedCharArray"; }
template <> PYIMATH_EXPORT const char * ShortArray::name() { return "ShortArray"; }
template <> PYIMATH_EXPORT const char * UnsignedShortArray::name(){ return "UnsignedShortArray"; }
template <> PYIMATH_EXPORT const char * IntArray::name() { return "IntArray"; }
template <> PYIMATH_EXPORT const char * UnsignedIntArray::name() { return "UnsignedIntArray"; }
template <> PYIMATH_EXPORT const char * FloatArray::name() { return "FloatArray"; }
template <> PYIMATH_EXPORT const char * DoubleArray::name() { return "DoubleArray"; }
template <> PYIMATH_EXPORT const char * VIntArray::name() { return "VIntArray"; }
template <> PYIMATH_EXPORT const char * VFloatArray::name() { return "VFloatArray"; }
template <> PYIMATH_EXPORT const char * VV2iArray::name() { return "VV2iArray"; }
template <> PYIMATH_EXPORT const char * VV2fArray::name() { return "VV2fArray"; }

}
90 changes: 90 additions & 0 deletions Sources/MetaPy/PyImath/PyImathAutovectorize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenEXR Project.
//

// clang-format off

#include "PyImathAutovectorize.h"


namespace PyImath {

namespace detail {
//
// cheek possible vectorizations to ensure correctness
//
// single argument should be ((false),(true))
//
BOOST_STATIC_ASSERT(( size<possible_vectorizations<1>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<1>::type,0>::type>::type::value == 1 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<1>::type,0>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<1>::type,1>::type>::type::value == 1 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<1>::type,1>::type,0>::type::value == true ));

//
// two argument should be ((false,false),(false,true),(true,false),(true,true))
//
BOOST_STATIC_ASSERT(( size<possible_vectorizations<2>::type>::type::value == 4 ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<2>::type,0>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,0>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,0>::type,1>::type::value == false ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<2>::type,1>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,1>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,1>::type,1>::type::value == true ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<2>::type,2>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,2>::type,0>::type::value == true ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,2>::type,1>::type::value == false ));
BOOST_STATIC_ASSERT(( size<at_c<possible_vectorizations<2>::type,3>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,3>::type,0>::type::value == true ));
BOOST_STATIC_ASSERT(( at_c<at_c<possible_vectorizations<2>::type,3>::type,1>::type::value == true ));
BOOST_STATIC_ASSERT(( size<possible_vectorizations<3>::type>::type::value == 8 ));

//
// Check disallow_vectorization for given vectorizable flags
//
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ > >::apply<vector<true_ > >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ > >::apply<vector<false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_> >::apply<vector<true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_> >::apply<vector<false_> >::type::value == false ));

BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , true_ > >::apply<vector<true_ , true_ > >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , true_ > >::apply<vector<false_, true_ > >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , true_ > >::apply<vector<true_ , false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , true_ > >::apply<vector<false_, false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , false_> >::apply<vector<true_ , true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , false_> >::apply<vector<false_, true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , false_> >::apply<vector<true_ , false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<true_ , false_> >::apply<vector<false_, false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, true_ > >::apply<vector<true_ , true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, true_ > >::apply<vector<false_, true_ > >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, true_ > >::apply<vector<true_ , false_> >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, true_ > >::apply<vector<false_, false_> >::type::value == false ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, false_> >::apply<vector<true_ , true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, false_> >::apply<vector<false_, true_ > >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, false_> >::apply<vector<true_ , false_> >::type::value == true ));
BOOST_STATIC_ASSERT(( disallow_vectorization<vector<false_, false_> >::apply<vector<false_, false_> >::type::value == false ));

//
// Check allowable_vectorizations, single argument not vectorizable, and two argument second argument vectorizable.
//
typedef allowable_vectorizations<vector<false_> > AV1f;
BOOST_STATIC_ASSERT(( size<AV1f::possible>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV1f::possible,0>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV1f::possible,1>::type,0>::type::value == true ));
BOOST_STATIC_ASSERT(( size<AV1f::type>::type::value == 1 ));
BOOST_STATIC_ASSERT(( size<at_c<AV1f::type,0>::type>::type::value == 1 ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV1f::type,0>::type,0>::type::value == false ));

typedef allowable_vectorizations<vector<false_,true_> > AV2ft;
BOOST_STATIC_ASSERT(( size<AV2ft::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( size<at_c<AV2ft::type,0>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV2ft::type,0>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV2ft::type,0>::type,1>::type::value == false ));
BOOST_STATIC_ASSERT(( size<at_c<AV2ft::type,1>::type>::type::value == 2 ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV2ft::type,1>::type,0>::type::value == false ));
BOOST_STATIC_ASSERT(( at_c<at_c<AV2ft::type,1>::type,1>::type::value == true ));

} // namespace detail

} // namespace PyImath
95 changes: 95 additions & 0 deletions Sources/MetaPy/PyImath/PyImathBasicTypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenEXR Project.
//

// clang-format off

#include <Python.h>
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <boost/python.hpp>
#include "PyImath.h"
#include "PyImathExport.h"
#include "PyImathBasicTypes.h"
#include "PyImathFixedArray.h"
#include "PyImathFixedVArray.h"
#include "PyImathBufferProtocol.h"

using namespace boost::python;

namespace PyImath {

void
register_basicTypes()
{
class_<BoolArray> bclass = BoolArray::register_("Fixed length array of bool");
add_comparison_functions(bclass);

class_<SignedCharArray> scclass = SignedCharArray::register_("Fixed length array of signed chars");
add_arithmetic_math_functions(scclass);
add_mod_math_functions(scclass);
add_comparison_functions(scclass);
add_ordered_comparison_functions(scclass);

class_<UnsignedCharArray> ucclass = UnsignedCharArray::register_("Fixed length array of unsigned chars");
add_arithmetic_math_functions(ucclass);
add_mod_math_functions(ucclass);
add_comparison_functions(ucclass);
add_ordered_comparison_functions(ucclass);
add_buffer_protocol<UnsignedCharArray>(ucclass);

class_<ShortArray> sclass = ShortArray::register_("Fixed length array of shorts");
add_arithmetic_math_functions(sclass);
add_mod_math_functions(sclass);
add_comparison_functions(sclass);
add_ordered_comparison_functions(sclass);

class_<UnsignedShortArray> usclass = UnsignedShortArray::register_("Fixed length array of unsigned shorts");
add_arithmetic_math_functions(usclass);
add_mod_math_functions(usclass);
add_comparison_functions(usclass);
add_ordered_comparison_functions(usclass);

class_<IntArray> iclass = IntArray::register_("Fixed length array of ints");
add_arithmetic_math_functions(iclass);
add_mod_math_functions(iclass);
add_comparison_functions(iclass);
add_ordered_comparison_functions(iclass);
add_explicit_construction_from_type<float>(iclass);
add_explicit_construction_from_type<double>(iclass);
add_buffer_protocol<IntArray>(iclass);

class_<UnsignedIntArray> uiclass = UnsignedIntArray::register_("Fixed length array of unsigned ints");
add_arithmetic_math_functions(uiclass);
add_mod_math_functions(uiclass);
add_comparison_functions(uiclass);
add_ordered_comparison_functions(uiclass);
add_explicit_construction_from_type<float>(uiclass);
add_explicit_construction_from_type<double>(uiclass);

class_<FloatArray> fclass = FloatArray::register_("Fixed length array of floats");
add_arithmetic_math_functions(fclass);
add_pow_math_functions(fclass);
add_comparison_functions(fclass);
add_ordered_comparison_functions(fclass);
add_explicit_construction_from_type<int>(fclass);
add_explicit_construction_from_type<double>(fclass);
add_buffer_protocol<FloatArray>(fclass);

class_<DoubleArray> dclass = DoubleArray::register_("Fixed length array of doubles");
add_arithmetic_math_functions(dclass);
add_pow_math_functions(dclass);
add_comparison_functions(dclass);
add_ordered_comparison_functions(dclass);
add_explicit_construction_from_type<int>(dclass);
add_explicit_construction_from_type<float>(dclass);
add_buffer_protocol<DoubleArray>(dclass);

class_<VIntArray> ivclass = VIntArray::register_("Variable fixed length array of ints");
class_<VFloatArray> fvclass = VFloatArray::register_("Variable fixed length array of floats");
class_<VV2iArray> v2ivclass = VV2iArray::register_("Variable fixed length array of V2i");
class_<VV2fArray> v2fvclass = VV2fArray::register_("Variable fixed length array of V2f");
// Don't add other functionality until its defined better.
}

} // namespace PyImath
Loading

0 comments on commit e7e3537

Please sign in to comment.