00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "AbstractLinAlgPack_SpVectorView.hpp"
00030
00031 namespace {
00032
00033
00034
00035 template<int N, class T>
00036 class assert_compile_time {
00037 public:
00038 assert_compile_time()
00039 {
00040
00041
00042
00043
00044
00045 T d;
00046 static_cast<int*>(d);
00047 }
00048 };
00049
00050
00051 template<>
00052 class assert_compile_time<0,double> {
00053 public:
00054 assert_compile_time()
00055 {}
00056 };
00057
00058
00059 assert_compile_time<
00060 ((int)sizeof(AbstractLinAlgPack::SpVectorSlice::element_type)
00061 % (int)sizeof(AbstractLinAlgPack::value_type))
00062 , double
00063 >
00064 validate_value_stride;
00065
00066
00067 assert_compile_time<
00068 ((int)sizeof(AbstractLinAlgPack::SpVectorSlice::element_type)
00069 % (int)sizeof(AbstractLinAlgPack::index_type))
00070 , double
00071 >
00072 validate_index_stride;
00073
00074
00075 const int values_stride = (int)sizeof(AbstractLinAlgPack::SpVectorSlice::element_type)
00076 / (int)sizeof(AbstractLinAlgPack::value_type);
00077
00078
00079 const int indices_stride = (int)sizeof(AbstractLinAlgPack::SpVectorSlice::element_type)
00080 / (int)sizeof(AbstractLinAlgPack::index_type);
00081
00082 }
00083
00084 RTOpPack::SparseSubVector
00085 AbstractLinAlgPack::sub_vec_view(
00086 const SpVectorSlice& sv_in
00087 ,const Range1D& rng_in
00088 )
00089 {
00090 const Range1D rng = RangePack::full_range(rng_in,1,sv_in.dim());
00091 const SpVectorSlice sv = sv_in(rng);
00092
00093 RTOpPack::SparseSubVector sub_vec;
00094
00095 if(!sv.nz()) {
00096 sub_vec.initialize(
00097 rng.lbound()-1
00098 ,rng.size()
00099 ,0
00100 ,NULL
00101 ,1
00102 ,NULL
00103 ,1
00104 ,0
00105 ,1
00106 );
00107 }
00108 else {
00109 SpVectorSlice::const_iterator
00110 itr = sv.begin();
00111 TEST_FOR_EXCEPT( !( itr != sv.end() ) );
00112 const value_type *values = &itr->value();
00113 if( sv.dim() && sv.nz() == sv.dim() && sv.is_sorted() ) {
00114 sub_vec.initialize(
00115 rng.lbound()-1
00116 ,rng.size()
00117 ,values
00118 ,values_stride
00119 );
00120 }
00121 else {
00122 const value_type *values = &itr->value();
00123 const index_type *indexes = &itr->index();
00124 sub_vec.initialize(
00125 rng.lbound()-1
00126 ,sv.dim()
00127 ,sv.nz()
00128 ,values
00129 ,values_stride
00130 ,indexes
00131 ,indices_stride
00132 ,sv.offset()
00133 ,sv.is_sorted()
00134 );
00135 }
00136 }
00137
00138 return sub_vec;
00139 }