Skip to content

Commit e1909fe

Browse files
committed
cleanup
1 parent 9c345ac commit e1909fe

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

core/src/G3Vector.cxx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void G3Vector<int64_t>::save(A &ar, const unsigned v) const
7575
}
7676
}
7777

78-
template <typename V, typename T=typename V::value_type>
78+
template <typename T, typename V>
7979
auto vector_from_python(const py::array_t<T> &buf, bool contiguous=true) {
8080
if (buf.ndim() != 1)
8181
throw py::type_error("Only valid 1D buffers can be copied to a vector");
@@ -91,11 +91,6 @@ auto vector_from_python(const py::array_t<T> &buf, bool contiguous=true) {
9191
return vec;
9292
}
9393

94-
template <typename V>
95-
auto time_vector_from_python(const py::array &buf) {
96-
return vector_from_python<V, G3TimeStamp>(buf, false);
97-
}
98-
9994
template <typename V>
10095
auto vector_buffer_info(V &v) {
10196
using T = typename V::value_type;
@@ -123,7 +118,9 @@ template <typename V, typename C, typename... Args>
123118
struct vector_buffer<G3Time, V, C, Args...> {
124119
static void impl(C &cls) {
125120
cls.def_buffer(&time_vector_buffer_info<V>);
126-
cls.def(py::init(&time_vector_from_python<V>));
121+
cls.def(py::init([](const py::array &v) {
122+
return vector_from_python<G3TimeStamp, V>(v, false);
123+
}), "Copy constructor from numpy array");
127124
py::implicitly_convertible<py::buffer, V>();
128125
}
129126
};
@@ -133,7 +130,8 @@ template <typename V, typename C, typename... Args> \
133130
struct vector_buffer<T, V, C, Args...> { \
134131
static void impl(C &cls) { \
135132
cls.def_buffer(&vector_buffer_info<V>); \
136-
cls.def(py::init(&vector_from_python<V>)); \
133+
cls.def(py::init([](const py::array &v) { \
134+
return vector_from_python<T, V>(v, true); })); \
137135
py::implicitly_convertible<py::buffer, V>(); \
138136
} \
139137
}

maps/src/FlatSkyMap.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,19 @@ flatskymap_fill(FlatSkyMap &skymap, const py::cbuffer &v)
810810
}
811811

812812
static FlatSkyMapPtr
813-
flatskymap_from_numpy(const py::cbuffer &v, double res,
813+
flatskymap_from_numpy(const py::array &v, double res,
814814
bool weighted, MapProjection proj,
815815
double alpha_center, double delta_center,
816816
MapCoordReference coord_ref, G3Timestream::TimestreamUnits u,
817817
G3SkyMap::MapPolType pol_type, double x_res,
818818
double x_center, double y_center,
819819
bool flat_pol, G3SkyMap::MapPolConv pol_conv)
820820
{
821-
auto info = v.request_contiguous();
822-
823-
if (info.ndim != 2)
821+
if (v.ndim() != 2)
824822
throw py::value_error("Only 2-D maps supported");
825823

826-
size_t ypix = info.shape[0];
827-
size_t xpix = info.shape[1];
824+
size_t ypix = v.shape(0);
825+
size_t xpix = v.shape(1);
828826

829827
FlatSkyProjection proj_info(xpix, ypix, res, alpha_center,
830828
delta_center, x_res, proj, x_center, y_center);
@@ -838,7 +836,7 @@ flatskymap_from_numpy(const py::cbuffer &v, double res,
838836
}
839837

840838
static FlatSkyMapPtr
841-
flatskymap_array_clone(const FlatSkyMap &m, const py::cbuffer &v)
839+
flatskymap_array_clone(const FlatSkyMap &m, const py::array &v)
842840
{
843841
auto skymap = std::dynamic_pointer_cast<FlatSkyMap>(m.Clone(false));
844842
flatskymap_fill(*skymap, v);

0 commit comments

Comments
 (0)