41 #ifndef SUBSCRIPTING_HPP
42 #define SUBSCRIPTING_HPP 1
129 template <
class VL,
class VR>
176 template <
class VL,
class VR>
279 static std::pair<const IntVector*, std::size_t>
318 static std::pair<const IntVector*, std::size_t>
346 static std::pair<const IntVector*, std::size_t>
397 static std::pair<const IntVector*, std::size_t>
497 template <
class VL,
class VR>
528 static V*
subset(
const V* v,
const PairList* subscripts,
bool drop);
575 template <
class VL,
class VR>
578 std::size_t>& indices_pr,
624 template <
class VL,
class VR>
628 const std::pair<const IntVector*, std::size_t>
629 pr(
canonicalize(subscripts, lhs->size(), lhs->names()));
680 indices(
canonicalize(subscripts, v->size(), v->names()).first);
687 unsigned int nindices;
691 unsigned int indexnum;
698 typedef std::vector<DimIndexer, Allocator<DimIndexer> > DimIndexerVector;
707 static std::size_t createDimIndexers(DimIndexerVector* dimindexers,
713 static void processUseNames(VectorBase* v,
const IntVector* indices);
717 static void setArrayAttributes(VectorBase*
subset,
718 const VectorBase* source,
719 const DimIndexerVector& dimindexers,
741 static void setVectorAttributes(VectorBase*
subset,
742 const VectorBase* source,
746 template <
class VL,
class VR>
750 typedef typename VL::value_type Lval;
751 typedef typename VR::value_type Rval;
753 std::size_t ndims = vdims->
size();
754 DimIndexerVector dimindexer(ndims);
755 std::size_t ni = createDimIndexers(&dimindexer, vdims, indices);
756 std::size_t rhs_size = rhs->size();
760 for (
unsigned int d = 0; d < ndims; ++d) {
761 DimIndexer& di = dimindexer[d];
762 for (
unsigned int i = 0; i < di.nindices; ++i)
763 if (
isNA((*di.indices)[i]))
764 Rf_error(_(
"NA subscripts are not allowed"
765 " in this context"));
779 Rf_error(_(
"replacement has length zero"));
780 if (ni%rhs_size != 0)
781 Rf_warning(_(
"number of items to replace is not"
782 " a multiple of replacement length"));
784 for (
unsigned int irhs = 0; irhs < ni; ++irhs) {
785 bool naindex =
false;
786 unsigned int iout = 0;
787 for (
unsigned int d = 0; d < ndims; ++d) {
788 const DimIndexer& di = dimindexer[d];
789 int index = (*di.indices)[di.indexnum];
794 iout += (index - 1)*di.stride;
798 Lval& lval = (*ans)[iout];
799 const Rval& rval = (*rhs)[irhs % rhs_size];
811 DimIndexer& di = dimindexer[d];
812 if (++di.indexnum >= di.nindices) {
814 done = (++d >= ndims);
828 std::size_t ndims = vdims->
size();
829 DimIndexerVector dimindexer(ndims);
830 std::size_t resultsize = createDimIndexers(&dimindexer, vdims, indices);
836 V* vnc =
const_cast<V*
>(v);
837 for (
unsigned int iout = 0; iout < resultsize; ++iout) {
838 bool naindex =
false;
839 unsigned int iin = 0;
840 for (
unsigned int d = 0; d < ndims; ++d) {
841 const DimIndexer& di = dimindexer[d];
842 int index = (*di.indices)[di.indexnum];
847 iin += (index - 1)*di.stride;
850 = (naindex ? NA<typename V::value_type>()
858 DimIndexer& di = dimindexer[d];
859 if (++di.indexnum >= di.nindices) {
861 done = (++d >= ndims);
867 setArrayAttributes(result, v, dimindexer, drop);
871 template <
class VL,
class VR>
879 if (dims && dims->
size() == nsubs)
892 if (dims && dims->
size() == nsubs)
898 template <
class VL,
class VR>
901 std::size_t>& indices_pr,
904 typedef typename VL::value_type Lval;
905 typedef typename VR::value_type Rval;
906 const IntVector* indices = indices_pr.first;
907 std::size_t newsize = indices_pr.second;
908 std::size_t ni = indices->
size();
909 std::size_t rhs_size = rhs->size();
913 for (
unsigned int i = 0; i < ni; ++i)
914 if (
isNA((*indices)[i]))
915 Rf_error(_(
"NA subscripts are not allowed"
916 " in this context"));
919 if (newsize > lhs->size())
925 if (ansvb == rhs || ansvb == indices)
931 Rf_error(_(
"replacement has length zero"));
932 if (ni%rhs_size != 0)
933 Rf_warning(_(
"number of items to replace is not"
934 " a multiple of replacement length"));
935 for (
unsigned int i = 0; i < ni; ++i) {
936 int index = (*indices)[i];
939 Lval& lval = (*ans)[index - 1];
940 const Rval& rval = (*rhs)[i % rhs_size];
947 processUseNames(ans, indices);
954 std::size_t ni = indices->
size();
956 std::size_t vsize = v->size();
959 V* vnc =
const_cast<V*
>(v);
960 for (
unsigned int i = 0; i < ni; ++i) {
961 int index = (*indices)[i];
963 if (
isNA(index) || index > int(vsize))
964 (*ans)[i] = NA<typename V::value_type>();
965 else (*ans)[i] = (*vnc)[index - 1];
967 setVectorAttributes(ans, v, indices);
972 #endif // SUBSCRIPTING_HPP