| 1 | /* |
| 2 | Copyright 2011 Thibaut Paumard |
| 3 | |
| 4 | This file is part of Gyoto. |
| 5 | |
| 6 | Gyoto is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | Gyoto is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with Gyoto. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "ygyoto_idx.h"cxx . . $ `<file>/yorick/ygyoto_idx.h`/ |
| 21 | #include "yapi.h" |
| 22 | #include "GyotoError.h"cxx . . $ `<file>/include/GyotoError.h`/ |
| 23 | #include "GyotoDefs.h"cxx . . $ `<file>/include/GyotoDefs.h`/ |
| 24 | #include "GyotoUtils.h"cxx . . $ `<file>/include/GyotoUtils.h`/ |
| 25 | #include <iostream> |
| 26 | using namespace YGyoto; |
| 27 | using namespace Gyoto; |
| 28 | using namespace std; |
| 29 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::isNullercxx . . $ YGyoto/Idx#isNuller(455f465bc33b4cdf).() const {return _is_nullercxx . . $ YGyoto/Idx#_is_nuller.;} |
| 30 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getNElementscxx . . $ YGyoto/Idx#getNElements(57a65ae535d7db84).() const {return _nelcxx . . $ YGyoto/Idx#_nel.;} |
| 31 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::currentcxx . . $ YGyoto/Idx#current(57a65ae535d7db84).() const { |
| 32 | if (_is_listcxx . . $ YGyoto/Idx#_is_list.) return _idxcxx . . $ YGyoto/Idx#_idx.[_curcxx . . $ YGyoto/Idx#_cur.]; |
| 33 | return _curcxx . . $ YGyoto/Idx#_cur.; |
| 34 | } |
| 35 | double YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getDValcxx . . $ YGyoto/Idx#getDVal(21b6c25e127938e2).() const {return _is_doublecxx . . $ YGyoto/Idx#_is_double.?_dvalcxx . . $ YGyoto/Idx#_dval.:_rangecxx . . $ YGyoto/Idx#_range.[0];} |
| 36 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::isDoublecxx . . $ YGyoto/Idx#isDouble(455f465bc33b4cdf).() const {return _is_doublecxx . . $ YGyoto/Idx#_is_double. || _is_dlistcxx . . $ YGyoto/Idx#_is_dlist.;} |
| 37 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::isRangeOrScalarcxx . . $ YGyoto/Idx#isRangeOrScalar(455f465bc33b4cdf).() const {return _is_rangecxx . . $ YGyoto/Idx#_is_range. || _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.;} |
| 38 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::isFirstcxx . . $ YGyoto/Idx#isFirst(455f465bc33b4cdf).() const {return _is_firstcxx . . $ YGyoto/Idx#_is_first.;} |
| 39 | |
| 40 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::isLastcxx . . $ YGyoto/Idx#isLast(455f465bc33b4cdf).() const { |
| 41 | if (_is_rangecxx . . $ YGyoto/Idx#_is_range.) return _curcxx . . $ YGyoto/Idx#_cur.+_rangecxx . . $ YGyoto/Idx#_range.[2] > _rangecxx . . $ YGyoto/Idx#_range.[1]; |
| 42 | if (_is_scalarcxx . . $ YGyoto/Idx#_is_scalar.) return 1; |
| 43 | if (_is_listcxx . . $ YGyoto/Idx#_is_list.) return _curcxx . . $ YGyoto/Idx#_cur. >= _nelcxx . . $ YGyoto/Idx#_nel.; |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::firstcxx . . $ YGyoto/Idx#first(da6335ded91d79c2).() { |
| 48 | _is_firstcxx . . $ YGyoto/Idx#_is_first.=1; |
| 49 | if (_is_rangecxx . . $ YGyoto/Idx#_is_range.) return _curcxx . . $ YGyoto/Idx#_cur.=_rangecxx . . $ YGyoto/Idx#_range.[0]; |
| 50 | if (_is_scalarcxx . . $ YGyoto/Idx#_is_scalar.) return _curcxx . . $ YGyoto/Idx#_cur.=_rangecxx . . $ YGyoto/Idx#_range.[0]; |
| 51 | if (_is_listcxx . . $ YGyoto/Idx#_is_list.) return _idxcxx . . $ YGyoto/Idx#_idx.[_curcxx . . $ YGyoto/Idx#_cur.=0]; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::validcxx . . $ YGyoto/Idx#valid(455f465bc33b4cdf).() const { |
| 56 | if (_is_rangecxx . . $ YGyoto/Idx#_is_range.) return _curcxx . . $ YGyoto/Idx#_cur.<=_rangecxx . . $ YGyoto/Idx#_range.[1]; |
| 57 | if (_is_scalarcxx . . $ YGyoto/Idx#_is_scalar.) return _curcxx . . $ YGyoto/Idx#_cur.==_rangecxx . . $ YGyoto/Idx#_range.[0]; |
| 58 | if (_is_listcxx . . $ YGyoto/Idx#_is_list.) return _curcxx . . $ YGyoto/Idx#_cur.<_nelcxx . . $ YGyoto/Idx#_nel.; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::nextcxx . . $ YGyoto/Idx#next(da6335ded91d79c2).() { |
| 64 | _is_firstcxx . . $ YGyoto/Idx#_is_first.=0; |
| 65 | if (_is_rangecxx . . $ YGyoto/Idx#_is_range.) return _curcxx . . $ YGyoto/Idx#_cur.+=_rangecxx . . $ YGyoto/Idx#_range.[2]; |
| 66 | if (_is_scalarcxx . . $ YGyoto/Idx#_is_scalar.) return ++_curcxx . . $ YGyoto/Idx#_cur.; |
| 67 | if (_is_listcxx . . $ YGyoto/Idx#_is_list. && (++_curcxx . . $ YGyoto/Idx#_cur.)<_nelcxx . . $ YGyoto/Idx#_nel.) return _idxcxx . . $ YGyoto/Idx#_idx.[_curcxx . . $ YGyoto/Idx#_cur.]; |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::range_mincxx . . $ YGyoto/Idx#range_min(57a65ae535d7db84).() const { |
| 73 | if (!(_is_rangecxx . . $ YGyoto/Idx#_is_range. || _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.)) GYOTO_ERRORcxx . . $ `include/GyotoError.h:196:9`!("BUG: not a range"); |
| 74 | return _rangecxx . . $ YGyoto/Idx#_range.[0]; |
| 75 | } |
| 76 | |
| 77 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::range_maxcxx . . $ YGyoto/Idx#range_max(57a65ae535d7db84).() const { |
| 78 | if (!(_is_rangecxx . . $ YGyoto/Idx#_is_range. || _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.)) GYOTO_ERRORcxx . . $ `include/GyotoError.h:196:9`!("BUG: not a range"); |
| 79 | return _rangecxx . . $ YGyoto/Idx#_range.[1]; |
| 80 | } |
| 81 | |
| 82 | long YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::range_dltcxx . . $ YGyoto/Idx#range_dlt(57a65ae535d7db84).() const { |
| 83 | if (!(_is_rangecxx . . $ YGyoto/Idx#_is_range. || _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.)) GYOTO_ERRORcxx . . $ `include/GyotoError.h:196:9`!("BUG: not a range"); |
| 84 | return _rangecxx . . $ YGyoto/Idx#_range.[2]; |
| 85 | } |
| 86 | |
| 87 | YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::Idxcxx . . $ YGyoto/Idx#Idx(3e454b8ccf442868).(int iarg, int res) : |
| 88 | _is_nullercxx . . $ YGyoto/Idx#_is_nuller.(0), _is_rangecxx . . $ YGyoto/Idx#_is_range.(0), _is_listcxx . . $ YGyoto/Idx#_is_list.(0), _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.(0), _is_doublecxx . . $ YGyoto/Idx#_is_double.(0), |
| 89 | _is_dlistcxx . . $ YGyoto/Idx#_is_dlist.(0), _bufcxx . . $ YGyoto/Idx#_buf.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 90 | { |
| 91 | int flags = yget_range(iarg, _rangecxx . . $ YGyoto/Idx#_range.); |
| 92 | if (flags) { |
| 93 | _is_rangecxx . . $ YGyoto/Idx#_is_range.=1; |
| 94 | if (flags>=Y_MAX_DFLTcxx . . $ `<external>/13312585737040429147/yapi.h:218:9`!) { |
| 95 | flags-=Y_MAX_DFLTcxx . . $ `<external>/13312585737040429147/yapi.h:218:9`!; |
| 96 | _rangecxx . . $ YGyoto/Idx#_range.[1]=res; |
| 97 | } |
| 98 | if (flags>=Y_MIN_DFLTcxx . . $ `<external>/13312585737040429147/yapi.h:217:9`!) { |
| 99 | flags-=Y_MIN_DFLTcxx . . $ `<external>/13312585737040429147/yapi.h:217:9`!; |
| 100 | _rangecxx . . $ YGyoto/Idx#_range.[0]=1; |
| 101 | } |
| 102 | if (flags==Y_NULLERcxx . . $ `<external>/13312585737040429147/yapi.h:216:9`!) { |
| 103 | _is_nullercxx . . $ YGyoto/Idx#_is_nuller.=1; |
| 104 | flags=0; |
| 105 | _nelcxx . . $ YGyoto/Idx#_nel.=0; |
| 106 | } |
| 107 | if (flags>1) |
| 108 | y_error("unsupported range syntax"); |
| 109 | |
| 110 | if (_rangecxx . . $ YGyoto/Idx#_range.[0]<=0) _rangecxx . . $ YGyoto/Idx#_range.[0]+=res; |
| 111 | if (_rangecxx . . $ YGyoto/Idx#_range.[1]<=0) _rangecxx . . $ YGyoto/Idx#_range.[1]+=res; |
| 112 | if (_rangecxx . . $ YGyoto/Idx#_range.[0]>res || _rangecxx . . $ YGyoto/Idx#_range.[1]>res) y_error("max index too large"); |
| 113 | |
| 114 | |
| 115 | _nelcxx . . $ YGyoto/Idx#_nel.=(_rangecxx . . $ YGyoto/Idx#_range.[1]-_rangecxx . . $ YGyoto/Idx#_range.[0]+_rangecxx . . $ YGyoto/Idx#_range.[2])/_rangecxx . . $ YGyoto/Idx#_range.[2]; |
| 116 | _dimscxx . . $ YGyoto/Idx#_dims.[0]=1; _dimscxx . . $ YGyoto/Idx#_dims.[1]=_nelcxx . . $ YGyoto/Idx#_nel.; |
| 117 | return; |
| 118 | } |
| 119 | if (yarg_number(iarg)==1){ |
| 120 | if (yarg_rank(iarg) > 0) { |
| 121 | _is_listcxx . . $ YGyoto/Idx#_is_list.=1; |
| 122 | _idxcxx . . $ YGyoto/Idx#_idx. = ygeta_l(iarg, &_nelcxx . . $ YGyoto/Idx#_nel., _dimscxx . . $ YGyoto/Idx#_dims.); |
| 123 | return; |
| 124 | } |
| 125 | _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.=1; |
| 126 | long val=ygets_l(iarg); |
| 127 | if (val>res) y_error("max index too large"); |
| 128 | if (val<=0) val+=res; |
| 129 | _rangecxx . . $ YGyoto/Idx#_range.[0]=_rangecxx . . $ YGyoto/Idx#_range.[1]=val; |
| 130 | _rangecxx . . $ YGyoto/Idx#_range.[2]=1; |
| 131 | _nelcxx . . $ YGyoto/Idx#_nel.=1; |
| 132 | _dimscxx . . $ YGyoto/Idx#_dims.[0]=0; |
| 133 | return; |
| 134 | } |
| 135 | if (yarg_number(iarg)==2) { |
| 136 | _is_doublecxx . . $ YGyoto/Idx#_is_double.=1; |
| 137 | _bufcxx . . $ YGyoto/Idx#_buf.=ygeta_d(iarg, &_nelcxx . . $ YGyoto/Idx#_nel., _dimscxx . . $ YGyoto/Idx#_dims.); |
| 138 | _dvalcxx . . $ YGyoto/Idx#_dval.=_bufcxx . . $ YGyoto/Idx#_buf.[0]; |
| 139 | if (_dimscxx . . $ YGyoto/Idx#_dims.[0]) _is_dlistcxx . . $ YGyoto/Idx#_is_dlist.=1; |
| 140 | else _is_scalarcxx . . $ YGyoto/Idx#_is_scalar.=1; |
| 141 | GYOTO_DEBUG_ARRAYcxx . . $ `include/GyotoDefs.h:313:9`!(_dims, Y_DIMSIZEcxx . . $ `<external>/13312585737040429147/yapi.h:133:9`!); |
| 142 | GYOTO_DEBUG_EXPRcxx . . $ `include/GyotoDefs.h:280:9`!(_is_scalar); |
| 143 | GYOTO_DEBUG_EXPRcxx . . $ `include/GyotoDefs.h:280:9`!(_is_dlist); |
| 144 | return; |
| 145 | } |
| 146 | if (iarg<0 || yarg_nil(iarg)) { |
| 147 | _is_rangecxx . . $ YGyoto/Idx#_is_range.=1; |
| 148 | _rangecxx . . $ YGyoto/Idx#_range.[0]=1; |
| 149 | _rangecxx . . $ YGyoto/Idx#_range.[1]=res; |
| 150 | _rangecxx . . $ YGyoto/Idx#_range.[2]=1; |
| 151 | _nelcxx . . $ YGyoto/Idx#_nel.=res; |
| 152 | _dimscxx . . $ YGyoto/Idx#_dims.[0]=1; |
| 153 | _dimscxx . . $ YGyoto/Idx#_dims.[1]=_nelcxx . . $ YGyoto/Idx#_nel.; |
| 154 | return; |
| 155 | } |
| 156 | y_error("unsupported range syntax"); |
| 157 | } |
| 158 | |
| 159 | int YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getNDimscxx . . $ YGyoto/Idx#getNDims(455f465bc33b4cdf).() const { |
| 160 | if (_is_rangecxx . . $ YGyoto/Idx#_is_range.) return 1; |
| 161 | if (_is_listcxx . . $ YGyoto/Idx#_is_list.) return 1; |
| 162 | if (_is_scalarcxx . . $ YGyoto/Idx#_is_scalar.) return 0; |
| 163 | GYOTO_ERRORcxx . . $ `include/GyotoError.h:196:9`!("BUG: What does this YGyoto::Idx instance hold?"); |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | long const * YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getDimscxx . . $ YGyoto/Idx#getDims(3ab49b861b332b22).() const {return _dimscxx . . $ YGyoto/Idx#_dims.;} |
| 168 | |
| 169 | long const * YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getBuffercxx . . $ YGyoto/Idx#getBuffer(3ab49b861b332b22).() const {return _idxcxx . . $ YGyoto/Idx#_idx.;} |
| 170 | double const * YGyotocxx . . $ YGyoto/::Idxcxx . . $ YGyoto/Idx#::getDoubleBuffercxx . . $ YGyoto/Idx#getDoubleBuffer(d06acfa185f8726d).() const {return _bufcxx . . $ YGyoto/Idx#_buf.;} |