Class: Renjin::Vector
- Includes:
- Enumerable, Index
- Defined in:
- lib/JRubyR/as_mdarray.rb,
lib/JRubyR/vector.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mdarray ⇒ Object
readonly
Returns the value of attribute mdarray.
Attributes included from RBSexp
Instance Method Summary collapse
-
#! ⇒ Object
—————————————————————————————-.
-
#!=(other_vec) ⇒ Object
—————————————————————————————-.
-
#%(other_vec) ⇒ Object
—————————————————————————————- modulus —————————————————————————————-.
-
#&(other_vec) ⇒ Object
—————————————————————————————-.
-
#*(other_vec) ⇒ Object
—————————————————————————————-.
-
#**(other_vec) ⇒ Object
—————————————————————————————- exponentiation —————————————————————————————-.
-
#+(other_vec) ⇒ Object
—————————————————————————————-.
-
#+@ ⇒ Object
—————————————————————————————-.
-
#-(other_vec) ⇒ Object
—————————————————————————————-.
-
#-@ ⇒ Object
—————————————————————————————-.
-
#/(other_vec) ⇒ Object
—————————————————————————————-.
-
#<(other_vec) ⇒ Object
—————————————————————————————-.
-
#<=(other_vec) ⇒ Object
—————————————————————————————-.
-
#==(other_val) ⇒ Object
—————————————————————————————-.
-
#>(other_vec) ⇒ Object
—————————————————————————————-.
-
#>=(other_vec) ⇒ Object
—————————————————————————————-.
-
#as__character ⇒ Object
—————————————————————————————-.
-
#as__complex ⇒ Object
—————————————————————————————-.
-
#as__double ⇒ Object
—————————————————————————————-.
-
#as__integer ⇒ Object
—————————————————————————————-.
-
#as__mdarray ⇒ Object
—————————————————————————————-.
-
#atomic? ⇒ Boolean
—————————————————————————————-.
-
#character? ⇒ Boolean
—————————————————————————————-.
-
#coerce(scalar) ⇒ Object
—————————————————————————————-.
-
#complex? ⇒ Boolean
—————————————————————————————-.
-
#double? ⇒ Boolean
—————————————————————————————-.
-
#eq(other_val) ⇒ Object
—————————————————————————————-.
-
#get(index = nil) ⇒ Object
—————————————————————————————-.
-
#gt(index = 0) ⇒ Object
—————————————————————————————-.
-
#gz ⇒ Object
—————————————————————————————-.
-
#initialize(sexp) ⇒ Vector
constructor
—————————————————————————————-.
-
#int_div(other_vec) ⇒ Object
—————————————————————————————-.
-
#integer? ⇒ Boolean
—————————————————————————————-.
-
#l_and(other_vec) ⇒ Object
—————————————————————————————- l_and looks at only the first element of the vector —————————————————————————————-.
-
#l_or(other_vec) ⇒ Object
—————————————————————————————-.
-
#logical? ⇒ Boolean
—————————————————————————————-.
-
#numeric? ⇒ Boolean
—————————————————————————————-.
-
#xor(other_vec) ⇒ Object
—————————————————————————————-.
-
#|(other_vec) ⇒ Object
—————————————————————————————- or —————————————————————————————-.
Methods included from Index
#[], #[]=, #each, #length, #method_missing, #parse
Methods inherited from RubySexp
Methods included from RBSexp
#destroy, #ncol, #nrow, #pp, #print, #r, #rclass, #sexp?, #typeof, #unbind
Constructor Details
#initialize(sexp) ⇒ Vector
56 57 58 59 60 |
# File 'lib/JRubyR/vector.rb', line 56 def initialize(sexp) super(sexp) @mdarray = nil @iterator = @sexp.iterator() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Renjin::Index
Instance Attribute Details
#mdarray ⇒ Object (readonly)
Returns the value of attribute mdarray.
50 51 52 |
# File 'lib/JRubyR/vector.rb', line 50 def mdarray @mdarray end |
Instance Method Details
#!=(other_vec) ⇒ Object
361 362 363 364 365 366 |
# File 'lib/JRubyR/vector.rb', line 361 def !=(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} != #{other_vec.r}") end |
#%(other_vec) ⇒ Object
modulus
284 285 286 287 288 289 |
# File 'lib/JRubyR/vector.rb', line 284 def %(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} %% #{other_vec.r}") end |
#&(other_vec) ⇒ Object
380 381 382 383 384 385 |
# File 'lib/JRubyR/vector.rb', line 380 def &(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} & #{other_vec.r}") end |
#*(other_vec) ⇒ Object
262 263 264 265 266 267 |
# File 'lib/JRubyR/vector.rb', line 262 def *(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} * #{other_vec.r}") end |
#**(other_vec) ⇒ Object
exponentiation
306 307 308 309 310 311 |
# File 'lib/JRubyR/vector.rb', line 306 def **(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} ** #{other_vec.r}") end |
#+(other_vec) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/JRubyR/vector.rb', line 239 def +(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} + #{other_vec.r}") end |
#-(other_vec) ⇒ Object
251 252 253 254 255 256 |
# File 'lib/JRubyR/vector.rb', line 251 def -(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} - #{other_vec.r}") end |
#/(other_vec) ⇒ Object
273 274 275 276 277 278 |
# File 'lib/JRubyR/vector.rb', line 273 def /(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} / #{other_vec.r}") end |
#<(other_vec) ⇒ Object
339 340 341 342 343 344 |
# File 'lib/JRubyR/vector.rb', line 339 def <(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} < #{other_vec.r}") end |
#<=(other_vec) ⇒ Object
350 351 352 353 354 355 |
# File 'lib/JRubyR/vector.rb', line 350 def <=(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} <= #{other_vec.r}") end |
#==(other_val) ⇒ Object
122 123 124 125 |
# File 'lib/JRubyR/vector.rb', line 122 def ==(other_val) other_val = (other_val.is_a? Renjin::RubySexp)? other_val.r : other_val (other_val == nil)? false : R.eval("#{r} == #{other_val}") end |
#>(other_vec) ⇒ Object
317 318 319 320 321 322 |
# File 'lib/JRubyR/vector.rb', line 317 def >(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} > #{other_vec.r}") end |
#>=(other_vec) ⇒ Object
328 329 330 331 332 333 |
# File 'lib/JRubyR/vector.rb', line 328 def >=(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} >= #{other_vec.r}") end |
#as__character ⇒ Object
163 164 165 |
# File 'lib/JRubyR/vector.rb', line 163 def as__character R.as__character(self) end |
#as__complex ⇒ Object
155 156 157 |
# File 'lib/JRubyR/vector.rb', line 155 def as__complex R.as__complex(self) end |
#as__double ⇒ Object
147 148 149 |
# File 'lib/JRubyR/vector.rb', line 147 def as__double R.as__double(self) end |
#as__integer ⇒ Object
139 140 141 |
# File 'lib/JRubyR/vector.rb', line 139 def as__integer R.as__integer(self) end |
#as__mdarray ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/JRubyR/vector.rb', line 171 def as__mdarray if (@mdarray) elsif (@sexp.instance_of? Java::RbScicom::MDDoubleVector) @mdarray = MDArray.build_from_nc_array(:double, @sexp.array) elsif (@sexp.instance_of? Java::OrgRenjinSexp::DoubleArrayVector) @mdarray = MDArray.from_jstorage("double", [@sexp.length()], @sexp.toDoubleArrayUnsafe()) elsif (@sexp.instance_of? Java::OrgRenjinSexp::IntArrayVector) @mdarray = MDArray.from_jstorage("int", [@sexp.length()], @sexp.toIntArrayUnsafe()) elsif (@sexp.instance_of? Java::OrgRenjinSexp::StringArrayVector) @mdarray = MDArray.from_jstorage("string", [@sexp.length()], @sexp.values) elsif (@sexp.instance_of? Java::OrgRenjinSexp::LogicalArrayVector) @mdarray = MDArray.from_jstorage("int", [@sexp.length()], @sexp.values) else p "sexp type needs to be specialized" p @sexp @mdarray = Renjin::RubySexp.new(@sexp) end raise "Cannot convert Vector to MDArray" if (!@mdarray) return @mdarray end |
#atomic? ⇒ Boolean
106 107 108 |
# File 'lib/JRubyR/vector.rb', line 106 def atomic? R.is__atomic(R.eval("#{r}")).gt end |
#character? ⇒ Boolean
98 99 100 |
# File 'lib/JRubyR/vector.rb', line 98 def character? R.is__character(R.eval("#{r}")).gt end |
#coerce(scalar) ⇒ Object
435 436 437 |
# File 'lib/JRubyR/vector.rb', line 435 def coerce(scalar) [R.d(scalar), self] end |
#complex? ⇒ Boolean
82 83 84 |
# File 'lib/JRubyR/vector.rb', line 82 def complex? R.is__complex(R.eval("#{r}")).gt end |
#double? ⇒ Boolean
74 75 76 |
# File 'lib/JRubyR/vector.rb', line 74 def double? R.is__double(R.eval("#{r}")).gt end |
#eq(other_val) ⇒ Object
131 132 133 |
# File 'lib/JRubyR/vector.rb', line 131 def eq(other_val) (other_val == nil)? false : R.eval("identical(#{r},#{other_val.r})") end |
#get(index = nil) ⇒ Object
199 200 201 |
# File 'lib/JRubyR/vector.rb', line 199 def get(index = nil) (index)? as__mdarray[index] : as__mdarray end |
#gt(index = 0) ⇒ Object
215 216 217 |
# File 'lib/JRubyR/vector.rb', line 215 def gt(index = 0) (get(index) == 0)? false : true end |
#gz ⇒ Object
207 208 209 |
# File 'lib/JRubyR/vector.rb', line 207 def gz get(0) end |
#int_div(other_vec) ⇒ Object
295 296 297 298 299 300 |
# File 'lib/JRubyR/vector.rb', line 295 def int_div(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} %/% #{other_vec.r}") end |
#integer? ⇒ Boolean
66 67 68 |
# File 'lib/JRubyR/vector.rb', line 66 def integer? R.is__integer(R.eval("#{r}")).gt end |
#l_and(other_vec) ⇒ Object
l_and looks at only the first element of the vector
391 392 393 394 395 396 |
# File 'lib/JRubyR/vector.rb', line 391 def l_and(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} && #{other_vec.r}") end |
#l_or(other_vec) ⇒ Object
413 414 415 416 417 418 |
# File 'lib/JRubyR/vector.rb', line 413 def l_or(other_vec) if (other_vec.is_a? Numeric) other_vec = R.d(other_vec) end R.eval("#{r} || #{other_vec.r}") end |
#logical? ⇒ Boolean
90 91 92 |
# File 'lib/JRubyR/vector.rb', line 90 def logical? R.is__logical(R.eval("#{r}")).gt end |
#numeric? ⇒ Boolean
114 115 116 |
# File 'lib/JRubyR/vector.rb', line 114 def numeric? R.is__numeric(R.eval("#{r}")).gt end |