Class: VectorSSE::Array
- Inherits:
-
Array
- Object
- Array
- VectorSSE::Array
- Defined in:
- lib/vector_sse.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #*(other) ⇒ Object
-
#+(other) ⇒ Object
Note: This method replaces the base class implementation of ‘+’, which performs concatenation.
-
#-(other) ⇒ Object
Note: This method replaces the base class implementation of ‘-’, which removes items that are found in ‘other’.
- #<<(value) ⇒ Object
- #[]=(index, value) ⇒ Object
-
#initialize(type, size = 0, val = nil) ⇒ Array
constructor
A new instance of Array.
- #insert(index, *values) ⇒ Object
- #sum ⇒ Object
Constructor Details
#initialize(type, size = 0, val = nil) ⇒ Array
326 327 328 329 330 331 332 333 334 |
# File 'lib/vector_sse.rb', line 326 def initialize( type, size=0, val=nil ) super( size, val ) if VectorSSE::valid_type( type ) @type = type else raise "invalid SSE vector type" end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
324 325 326 |
# File 'lib/vector_sse.rb', line 324 def type @type end |
Instance Method Details
#*(other) ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/vector_sse.rb', line 443 def *( other ) unless [ Integer, Float ].include? other.class raise ArgumentError.new( "expected argument of type Float or Integer for argument 0" ) end other = self.class.new( @type, self.length, other ) result = self.class.new( @type ) case @type when Type::S32 result.replace( VectorSSE::vec_mul_s32( self, other ) ) when Type::S64 result.replace( VectorSSE::vec_mul_s64( self, other ) ) when Type::F32 result.replace( VectorSSE::vec_mul_f32( self, other ) ) when Type::F64 result.replace( VectorSSE::vec_mul_f64( self, other ) ) end result end |
#+(other) ⇒ Object
Note: This method replaces the base class implementation of ‘+’, which performs concatenation. To concatenate, see #concat.
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/vector_sse.rb', line 366 def +( other ) if [ Integer, Float ].include? other.class other = ::Array.new( self.length, other ) elsif other.class != self.class raise ArgumentError.new( "expect argument of type #{self.class}, Integer, or Float for argument 0" ) end result = self.class.new( @type ) case @type when Type::S32 result.replace( VectorSSE::add_s32( self, other ) ) when Type::S64 result.replace( VectorSSE::add_s64( self, other ) ) when Type::F32 result.replace( VectorSSE::add_f32( self, other ) ) when Type::F64 result.replace( VectorSSE::add_f64( self, other ) ) end result end |
#-(other) ⇒ Object
Note: This method replaces the base class implementation of ‘-’, which removes items that are found in ‘other’.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/vector_sse.rb', line 399 def -( other ) if [ Integer, Float ].include? other.class other = ::Array.new( self.length, other ) elsif other.class != self.class raise ArgumentError.new( "expected argument of type #{self.class}, Integer, or Float for argument 0" ) end result = self.class.new( @type ) case @type when Type::S32 result.replace( VectorSSE::sub_s32( self, other ) ) when Type::S64 result.replace( VectorSSE::sub_s64( self, other ) ) when Type::F32 result.replace( VectorSSE::sub_f32( self, other ) ) when Type::F64 result.replace( VectorSSE::sub_f64( self, other ) ) end result end |
#<<(value) ⇒ Object
336 337 338 339 340 341 342 |
# File 'lib/vector_sse.rb', line 336 def <<( value ) unless [ Integer, Float ].include? value.class raise ArgumentError.new( "expected argument of type Integer or Float for argument 0" ) end super( value ) end |
#[]=(index, value) ⇒ Object
354 355 356 357 358 359 360 |
# File 'lib/vector_sse.rb', line 354 def []=( index, value ) unless [ Integer, Float ].include? value.class raise ArgumentError.new( "expected argument of type Integer or Float for argument 1" ) end super( index, value ) end |
#insert(index, *values) ⇒ Object
344 345 346 347 348 349 350 351 352 |
# File 'lib/vector_sse.rb', line 344 def insert( index, *values ) values.each_with_index do |value,arg_index| unless [ Integer, Float ].include? value.class raise ArgumentError.new( "expected argument of type Integer or Float for argument #{arg_index}" ) end end super( index, values ) end |
#sum ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/vector_sse.rb', line 424 def sum sum_result = 0 case @type when Type::S32 sum_result = VectorSSE::sum_s32( self ) when Type::S64 sum_result = VectorSSE::sum_s64( self ) when Type::F32 sum_result = VectorSSE::sum_f32( self ) when Type::F64 sum_result = VectorSSE::sum_f64( self ) else raise "invalid SSE vector type" end sum_result end |