26 #ifndef _CXSC_SRVECTOR_HPP_INCLUDED
27 #define _CXSC_SRVECTOR_HPP_INCLUDED
30 #include <intvector.hpp>
31 #include <rvector.hpp>
32 #include <intmatrix.hpp>
38 #include <sparsedot.hpp>
39 #include <sparsevector.hpp>
72 explicit srvector(
const int s) : lb(1), ub(s), n(s) {
73 p.reserve((
int)(s*0.1));
74 x.reserve((
int)(s*0.1));
78 srvector(
const int s,
const int b) : lb(1), ub(s), n(s) {
85 for(
int i=lb ; i<=ub ; i++) {
96 for(
int i=0 ; i<nnz ; i++) {
98 p.push_back(index[
Lb(index)+i]);
108 for(
int i=0 ; i<nnz ; i++) {
110 p.push_back(index[i]);
155 const std::vector<real>&
values()
const {
166 return (
double)x.size()/n;
171 for(
int i=0 ; i<
get_nnz() ; i++) {
173 x.erase(x.begin()+i);
174 p.erase(p.begin()+i);
181 return sp_vs_assign<srvector,real,real>(*
this,v);
186 return spf_vv_assign<srvector,rvector,real>(*
this,v);
191 return spf_vv_assign<srvector,rvector_slice,real>(*
this,v);
203 #if(CXSC_INDEX_CHECK)
204 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector::operator[](const int)"));
208 for(k=0 ; k<
get_nnz() && p[k]<=i-lb ; k++) {
213 p.insert(p.begin() + k, i-lb);
214 x.insert(x.begin() + k, 0.0);
225 #if(CXSC_INDEX_CHECK)
226 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector::operator[](const int)"));
237 #if(CXSC_INDEX_CHECK)
238 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector::operator()(const int)"));
242 for(
int k=0 ; k<
get_nnz() && p[k]<=i-lb ; k++) {
263 std::map<int,real> work;
264 for(
int i=0 ; i<
get_nnz() ; i++)
265 work.insert(std::make_pair(pinv[
Lb(pinv)+p[i]], x[i]));
267 for(std::map<int,real>::iterator it=work.begin() ; it!=work.end() ; it++) {
268 v.p.push_back(it->first);
269 v.x.push_back(it->second);
289 return sp_vs_multassign(*
this,s);
294 return sp_vs_divassign(*
this,s);
300 return spf_vv_addassign(*
this,v);
305 return spf_vv_addassign(*
this,v);
310 return spsp_vv_addassign(*
this,v);
318 return spf_vv_subassign(*
this,v);
323 return spf_vv_subassign(*
this,v);
328 return spsp_vv_subassign(*
this,v);
375 #include "vector_friend_declarations.inl"
383 for(
int i=0 ; i<v.n ; i++)
385 for(
int i=0 ; i<v.
get_nnz() ; i++)
386 dat[v.p[i]] = v.x[i];
390 return fsp_vv_assign<rvector,srvector,real>(*
this,v);
394 return fsl_vv_assign<rvector,srvector_slice,real>(*
this,v);
404 v.ub = v.lb + v.n - 1;
413 v.lb = v.ub - v.n + 1;
455 return sp_v_negative(v);
466 return spf_vv_mult<srvector,rvector,real,sparse_dot>(v1,v2);
477 return fsp_vv_mult<rvector,srvector,real,sparse_dot>(v1,v2);
488 return spf_vv_mult<srvector,rvector_slice,real,sparse_dot>(v1,v2);
499 return fsp_vv_mult<rvector_slice,srvector,real,sparse_dot>(v1,v2);
510 return spsp_vv_mult<srvector,srvector,real,sparse_dot>(v1,v2);
515 return sp_vs_mult<srvector,real,srvector>(v,s);
520 return sp_vs_div<srvector,real,srvector>(v,s);
525 return sp_sv_mult<real,srvector,srvector>(s,v);
530 return fsp_vv_add<rvector,srvector,rvector>(v1,v2);
535 return spf_vv_add<srvector,rvector,rvector>(v1,v2);
540 return fsp_vv_add<rvector_slice,srvector,rvector>(v1,v2);
545 return spf_vv_add<srvector,rvector_slice,rvector>(v1,v2);
550 return spsp_vv_add<srvector,srvector,srvector,real>(v1,v2);
555 return fsp_vv_sub<rvector,srvector,rvector>(v1,v2);
560 return spf_vv_sub<srvector,rvector,rvector>(v1,v2);
565 return fsp_vv_sub<rvector_slice,srvector,rvector>(v1,v2);
570 return spf_vv_sub<srvector,rvector_slice,rvector>(v1,v2);
575 return spsp_vv_sub<srvector,srvector,srvector,real>(v1,v2);
579 return fsp_vv_addassign(*
this,v2);
583 return fsp_vv_addassign(*
this,v2);
587 return fsp_vv_subassign(*
this,v2);
591 return fsp_vv_subassign(*
this,v2);
599 return spsp_vv_comp(v1,v2);
607 return spf_vv_comp(v1,v2);
615 return fsp_vv_comp(v1,v2);
623 return spf_vv_comp(v1,v2);
631 return fsp_vv_comp(v1,v2);
639 return !spsp_vv_comp(v1,v2);
647 return !spf_vv_comp(v1,v2);
655 return !fsp_vv_comp(v1,v2);
663 return !spf_vv_comp(v1,v2);
671 return !fsp_vv_comp(v1,v2);
679 return spsp_vv_less<srvector,srvector,real>(v1,v2);
687 return spf_vv_less<srvector,rvector,real>(v1,v2);
695 return fsp_vv_less<rvector,srvector,real>(v1,v2);
703 return spf_vv_less<srvector,rvector_slice,real>(v1,v2);
711 return fsp_vv_less<rvector_slice,srvector,real>(v1,v2);
719 return spsp_vv_leq<srvector,srvector,real>(v1,v2);
727 return spf_vv_leq<srvector,rvector,real>(v1,v2);
735 return fsp_vv_leq<rvector,srvector,real>(v1,v2);
743 return spf_vv_leq<srvector,rvector_slice,real>(v1,v2);
751 return fsp_vv_leq<rvector_slice,srvector,real>(v1,v2);
759 return spsp_vv_greater<srvector,srvector,real>(v1,v2);
767 return spf_vv_greater<srvector,rvector,real>(v1,v2);
775 return fsp_vv_greater<rvector,srvector,real>(v1,v2);
783 return spf_vv_greater<srvector,rvector_slice,real>(v1,v2);
791 return fsp_vv_greater<rvector_slice,srvector,real>(v1,v2);
799 return spsp_vv_geq<srvector,srvector,real>(v1,v2);
807 return spf_vv_geq<srvector,rvector,real>(v1,v2);
815 return fsp_vv_geq<rvector,srvector,real>(v1,v2);
823 return spf_vv_geq<srvector,rvector_slice,real>(v1,v2);
831 return fsp_vv_geq<rvector_slice,srvector,real>(v1,v2);
848 inline std::ostream& operator<<(std::ostream& os,
const srvector& v) {
849 return sp_v_output<srvector,real>(os,v);
858 inline std::istream& operator>>(std::istream& is,
srvector& v) {
859 return sp_v_input<srvector,real>(is,v);
871 std::vector<real>& x;
888 for(i=0 ; i<v.
get_nnz() && p[i]<lb-v.lb ; i++);
892 for(i=start ; i<v.
get_nnz() && p[i]<=ub-v.lb ; i++);
907 return (
double)nnz/n;
916 #if(CXSC_INDEX_CHECK)
917 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector_slice::operator[](const int)"));
921 for(k=start ; k<end+1 && p[k]-start<=i-lb ; k++) {
922 if(p[k]-offset == i-lb)
926 p.insert(p.begin() + k, i-lb);
927 x.insert(x.begin() + k, 0.0);
939 #if(CXSC_INDEX_CHECK)
940 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector_slice::operator[](const int)"));
951 #if(CXSC_INDEX_CHECK)
952 if(i<lb || i>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector_slice::operator()(const int)"));
956 for(
int k=start ; k<end && p[k]-start<=i-lb ; k++) {
957 if(p[k]-start == i-lb)
966 return sl_vs_assign<srvector_slice,real,real,std::vector<real>::iterator>(*
this,v);
971 return slsl_vv_assign<srvector_slice,srvector_slice,real,std::vector<real>::iterator>(*
this,v);
976 return slsp_vv_assign<srvector_slice,srvector,real,std::vector<real>::iterator>(*
this,v);
981 return slf_vv_assign<srvector_slice,rvector,real,std::vector<real>::iterator>(*
this,v);
986 return slf_vv_assign<srvector_slice,rvector,real,std::vector<real>::iterator>(*
this,v);
991 return sl_vs_multassign(*
this,s);
996 return sl_vs_divassign(*
this,s);
1001 return slf_vv_addassign<srvector_slice,rvector,real>(*
this,v);
1006 return slf_vv_addassign<srvector_slice,rvector_slice,real>(*
this,v);
1011 return slsp_vv_addassign(*
this,v);
1016 return slsl_vv_addassign(*
this,v);
1021 return slf_vv_subassign<srvector_slice,rvector,real>(*
this,v);
1026 return slf_vv_subassign<srvector_slice,rvector_slice,real>(*
this,v);
1031 return slsp_vv_subassign(*
this,v);
1036 return slsl_vv_subassign(*
this,v);
1061 #include "vector_friend_declarations.inl"
1068 dat =
new real[v.n];
1069 for(
int i=0 ; i<v.n ; i++)
1071 for(
int i=v.start ; i<=v.end ; i++)
1072 dat[v.p[i]] = v.x[i];
1089 for(
int i=s.start ; i<=s.end ; i++) {
1090 p.push_back(s.p[i]-s.offset);
1091 x.push_back(s.x[i]);
1097 return spsl_vv_assign<srvector,srvector_slice,real>(*
this,v);
1101 #if(CXSC_INDEX_CHECK)
1102 if(i<lb || j>ub) cxscthrow(ELEMENT_NOT_IN_VEC(
"srvector::operator()(const int,const int)"));
1109 return sl_v_negative<srvector_slice,srvector>(v);
1130 std::vector<real>& x = ret.
values();
1131 for(
unsigned int i=0 ; i<x.size() ; i++)
1144 return slf_vv_mult<srvector_slice,rvector,real,sparse_dot>(v1,v2);
1148 inline real
operator*(
const rvector& v1,
const srvector_slice& v2) {
1154 return fsl_vv_mult<rvector,srvector_slice,real,sparse_dot>(v1,v2);
1158 inline real
operator*(
const srvector_slice& v1,
const rvector_slice& v2) {
1164 return slf_vv_mult<srvector_slice,rvector_slice,real,sparse_dot>(v1,v2);
1168 inline real
operator*(
const rvector_slice& v1,
const srvector_slice& v2) {
1174 return fsl_vv_mult<rvector_slice,srvector_slice,real,sparse_dot>(v1,v2);
1178 inline real
operator*(
const srvector& v1,
const srvector_slice& v2) {
1184 return spsl_vv_mult<srvector,srvector_slice,real,sparse_dot>(v1,v2);
1188 inline real
operator*(
const srvector_slice& v1,
const srvector& v2) {
1194 return slsp_vv_mult<srvector_slice,srvector,real,sparse_dot>(v1,v2);
1198 inline real
operator*(
const srvector_slice& v1,
const srvector_slice& v2) {
1204 return slsl_vv_mult<srvector_slice,srvector_slice,real,sparse_dot>(v1,v2);
1209 return sp_vs_mult<srvector_slice,real,srvector>(v,s);
1214 return sp_vs_div<srvector_slice,real,srvector>(v,s);
1219 return sp_sv_mult<real,srvector_slice,srvector>(s,v);
1224 return fsl_vv_add<rvector,srvector_slice,rvector>(v1,v2);
1229 return slf_vv_add<srvector_slice,rvector,rvector>(v1,v2);
1234 return fsl_vv_add<rvector_slice,srvector_slice,rvector>(v1,v2);
1239 return slf_vv_add<srvector_slice,rvector_slice,rvector>(v1,v2);
1244 return slsl_vv_add<srvector_slice,srvector_slice,srvector,real>(v1,v2);
1249 return spsl_vv_add<srvector,srvector_slice,srvector,real>(v1,v2);
1254 return slsp_vv_add<srvector_slice,srvector,srvector,real>(v1,v2);
1259 return fsl_vv_sub<rvector,srvector_slice,rvector>(v1,v2);
1264 return slf_vv_sub<srvector_slice,rvector,rvector>(v1,v2);
1269 return fsl_vv_sub<rvector_slice,srvector_slice,rvector>(v1,v2);
1274 return slf_vv_sub<srvector_slice,rvector_slice,rvector>(v1,v2);
1279 return slsl_vv_sub<srvector_slice,srvector_slice,srvector,real>(v1,v2);
1284 return spsl_vv_sub<srvector,srvector_slice,srvector,real>(v1,v2);
1289 return slsp_vv_sub<srvector_slice,srvector,srvector,real>(v1,v2);
1293 return fsl_vv_addassign(*
this,v2);
1297 return fsl_vv_addassign(*
this,v2);
1301 return spsl_vv_addassign(*
this,v2);
1305 return fsl_vv_subassign(*
this,v2);
1309 return fsl_vv_subassign(*
this,v2);
1313 return spsl_vv_subassign(*
this,v2);
1321 return slsl_vv_comp(v1,v2);
1329 return slsp_vv_comp(v1,v2);
1337 return spsl_vv_comp(v1,v2);
1345 return slf_vv_comp(v1,v2);
1353 return fsl_vv_comp(v1,v2);
1361 return slf_vv_comp(v1,v2);
1369 return fsl_vv_comp(v1,v2);
1377 return !slsl_vv_comp(v1,v2);
1385 return !slf_vv_comp(v1,v2);
1393 return !fsl_vv_comp(v1,v2);
1401 return !slsp_vv_comp(v1,v2);
1409 return !spsl_vv_comp(v1,v2);
1417 return !slf_vv_comp(v1,v2);
1425 return !fsl_vv_comp(v1,v2);
1433 return slsl_vv_less<srvector_slice,srvector_slice,real>(v1,v2);
1441 return slsp_vv_less<srvector_slice,srvector,real>(v1,v2);
1449 return spsl_vv_less<srvector,srvector_slice,real>(v1,v2);
1457 return slf_vv_less<srvector_slice,rvector,real>(v1,v2);
1465 return fsl_vv_less<rvector,srvector_slice,real>(v1,v2);
1473 return slf_vv_less<srvector_slice,rvector_slice,real>(v1,v2);
1481 return fsl_vv_less<rvector_slice,srvector_slice,real>(v1,v2);
1489 return slsl_vv_leq<srvector_slice,srvector_slice,real>(v1,v2);
1497 return slsp_vv_leq<srvector_slice,srvector,real>(v1,v2);
1505 return spsl_vv_leq<srvector,srvector_slice,real>(v1,v2);
1513 return slf_vv_leq<srvector_slice,rvector,real>(v1,v2);
1521 return fsl_vv_leq<rvector,srvector_slice,real>(v1,v2);
1529 return slf_vv_leq<srvector_slice,rvector_slice,real>(v1,v2);
1537 return fsl_vv_leq<rvector_slice,srvector_slice,real>(v1,v2);
1545 return slsl_vv_greater<srvector_slice,srvector_slice,real>(v1,v2);
1553 return slsp_vv_greater<srvector_slice,srvector,real>(v1,v2);
1561 return spsl_vv_greater<srvector,srvector_slice,real>(v1,v2);
1569 return slf_vv_greater<srvector_slice,rvector,real>(v1,v2);
1577 return fsl_vv_greater<rvector,srvector_slice,real>(v1,v2);
1585 return slf_vv_greater<srvector_slice,rvector_slice,real>(v1,v2);
1593 return fsl_vv_greater<rvector_slice,srvector_slice,real>(v1,v2);
1601 return slsl_vv_geq<srvector_slice,srvector_slice,real>(v1,v2);
1609 return slsp_vv_geq<srvector_slice,srvector,real>(v1,v2);
1617 return spsl_vv_geq<srvector,srvector_slice,real>(v1,v2);
1625 return slf_vv_geq<srvector_slice,rvector,real>(v1,v2);
1633 return fsl_vv_geq<rvector,srvector_slice,real>(v1,v2);
1641 return slf_vv_geq<srvector_slice,rvector_slice,real>(v1,v2);
1649 return fsl_vv_geq<rvector_slice,srvector_slice,real>(v1,v2);
1667 return sl_v_output<srvector_slice, real>(os,v);
1677 return sl_v_input<srvector_slice, real>(is,v);
1685 spsp_vv_accu<dotprecision,srvector,srvector,sparse_dot>(dot,x,y);
1693 spf_vv_accu<dotprecision,srvector,rvector,sparse_dot>(dot,x,y);
1701 spf_vv_accu<dotprecision,srvector,rvector_slice,sparse_dot>(dot,x,y);
1709 fsp_vv_accu<dotprecision,rvector,srvector,sparse_dot>(dot,x,y);
1717 fsp_vv_accu<dotprecision,rvector_slice,srvector,sparse_dot>(dot,x,y);
1725 slf_vv_accu<dotprecision,srvector_slice,rvector,sparse_dot>(dot,x,y);
1733 slf_vv_accu<dotprecision,srvector_slice,rvector_slice,sparse_dot>(dot,x,y);
1741 fsl_vv_accu<dotprecision,rvector,srvector_slice,sparse_dot>(dot,x,y);
1749 fsl_vv_accu<dotprecision,rvector_slice,srvector_slice,sparse_dot>(dot,x,y);
1757 slsl_vv_accu<dotprecision,srvector_slice,srvector_slice,sparse_dot>(dot,x,y);
1765 spsl_vv_accu<dotprecision,srvector,srvector_slice,sparse_dot>(dot,x,y);
1773 slsp_vv_accu<dotprecision,srvector_slice,srvector,sparse_dot>(dot,x,y);
1782 spsp_vv_accuapprox<dotprecision,srvector,srvector,sparse_dot>(dot,x,y);
1791 spf_vv_accuapprox<dotprecision,srvector,rvector,sparse_dot>(dot,x,y);
1800 spf_vv_accuapprox<dotprecision,srvector,rvector_slice,sparse_dot>(dot,x,y);
1809 fsp_vv_accuapprox<dotprecision,rvector,srvector,sparse_dot>(dot,x,y);
1818 fsp_vv_accuapprox<dotprecision,rvector_slice,srvector,sparse_dot>(dot,x,y);
1827 slf_vv_accuapprox<dotprecision,srvector_slice,rvector,sparse_dot>(dot,x,y);
1836 slf_vv_accuapprox<dotprecision,srvector_slice,rvector_slice,sparse_dot>(dot,x,y);
1845 fsl_vv_accuapprox<dotprecision,rvector,srvector_slice,sparse_dot>(dot,x,y);
1854 fsl_vv_accuapprox<dotprecision,rvector_slice,srvector_slice,sparse_dot>(dot,x,y);
1863 slsl_vv_accuapprox<dotprecision,srvector_slice,srvector_slice,sparse_dot>(dot,x,y);
1872 spsl_vv_accuapprox<dotprecision,srvector,srvector_slice,sparse_dot>(dot,x,y);
1881 slsp_vv_accuapprox<dotprecision,srvector_slice,srvector,sparse_dot>(dot,x,y);
1891 accumulate(tmp,x,y);
1902 accumulate(tmp,x,y);
1913 accumulate(tmp,x,y);
1924 accumulate(tmp,x,y);
1935 accumulate(tmp,x,y);
1946 accumulate(tmp,x,y);
1957 accumulate(tmp,x,y);
1968 accumulate(tmp,x,y);
1979 accumulate(tmp,x,y);
1990 accumulate(tmp,x,y);
2001 accumulate(tmp,x,y);
2012 accumulate(tmp,x,y);
2023 accumulate(tmp,x,y);
2034 accumulate(tmp,x,y);
2045 accumulate(tmp,x,y);
2056 accumulate(tmp,x,y);
2067 accumulate(tmp,x,y);
2078 accumulate(tmp,x,y);
2089 accumulate(tmp,x,y);
2100 accumulate(tmp,x,y);
2111 accumulate(tmp,x,y);
2122 accumulate(tmp,x,y);
2133 accumulate(tmp,x,y);
2144 accumulate(tmp,x,y);
2299 accumulate(tmp,x,y);
2310 accumulate(tmp,x,y);
2321 accumulate(tmp,x,y);
2332 accumulate(tmp,x,y);
2343 accumulate(tmp,x,y);
2354 accumulate(tmp,x,y);
2365 accumulate(tmp,x,y);
2376 accumulate(tmp,x,y);
2387 accumulate(tmp,x,y);
2398 accumulate(tmp,x,y);
2409 accumulate(tmp,x,y);
2420 accumulate(tmp,x,y);
2427 #include "sparsevector.inl"