-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccumarray.cpp
More file actions
52 lines (49 loc) · 1.84 KB
/
accumarray.cpp
File metadata and controls
52 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#include "accumarray.h"
#include <cassert>
template <
typename DerivedS,
typename DerivedV,
typename DerivedA
>
void igl::accumarray(
const Eigen::MatrixBase<DerivedS> & S,
const Eigen::MatrixBase<DerivedV> & V,
Eigen::PlainObjectBase<DerivedA> & A)
{
assert(V.size() == S.size() && "S and V should be same size");
if(S.size() == 0) { A.resize(0,1); return; }
A.setZero(S.maxCoeff()+1,1);
for(int s = 0;s<S.size();s++)
{
A(S(s)) += V(s);
}
}
template <
typename DerivedS,
typename DerivedA
>
void igl::accumarray(
const Eigen::MatrixBase<DerivedS> & S,
const typename DerivedA::Scalar V,
Eigen::PlainObjectBase<DerivedA> & A)
{
if(S.size() == 0) { A.resize(0,1); return; }
A.setZero(S.maxCoeff()+1,1);
for(int s = 0;s<S.size();s++)
{
A(S(s)) += V;
}
}
#ifdef IGL_STATIC_LIBRARY
// Explicit template instantiation
// generated by autoexplicit.sh
template void igl::accumarray<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1>::Scalar, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
template void igl::accumarray<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
#endif