multiarray 0.22.0 → 0.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/Rakefile +1 -1
  2. data/lib/multiarray.rb +53 -16
  3. data/lib/multiarray/bool.rb +1 -1
  4. data/lib/multiarray/complex.rb +76 -68
  5. data/lib/multiarray/components.rb +11 -10
  6. data/lib/multiarray/composite.rb +1 -1
  7. data/lib/multiarray/diagonal.rb +11 -12
  8. data/lib/multiarray/element.rb +3 -3
  9. data/lib/multiarray/elementwise.rb +14 -14
  10. data/lib/multiarray/field.rb +380 -0
  11. data/lib/multiarray/float.rb +10 -10
  12. data/lib/multiarray/gcccache.rb +1 -1
  13. data/lib/multiarray/gcccontext.rb +35 -54
  14. data/lib/multiarray/gccfunction.rb +12 -19
  15. data/lib/multiarray/gcctype.rb +1 -1
  16. data/lib/multiarray/gccvalue.rb +63 -43
  17. data/lib/multiarray/histogram.rb +17 -19
  18. data/lib/multiarray/index.rb +7 -8
  19. data/lib/multiarray/inject.rb +11 -12
  20. data/lib/multiarray/int.rb +12 -11
  21. data/lib/multiarray/integral.rb +11 -12
  22. data/lib/multiarray/lambda.rb +23 -18
  23. data/lib/multiarray/list.rb +1 -1
  24. data/lib/multiarray/lookup.rb +18 -13
  25. data/lib/multiarray/lut.rb +13 -16
  26. data/lib/multiarray/malloc.rb +1 -1
  27. data/lib/multiarray/mask.rb +11 -8
  28. data/lib/multiarray/methods.rb +10 -10
  29. data/lib/multiarray/multiarray.rb +15 -44
  30. data/lib/multiarray/node.rb +64 -138
  31. data/lib/multiarray/object.rb +2 -6
  32. data/lib/multiarray/operations.rb +116 -134
  33. data/lib/multiarray/pointer.rb +7 -19
  34. data/lib/multiarray/random.rb +11 -8
  35. data/lib/multiarray/rgb.rb +53 -53
  36. data/lib/multiarray/sequence.rb +11 -496
  37. data/lib/multiarray/shortcuts.rb +4 -4
  38. data/lib/multiarray/store.rb +14 -11
  39. data/lib/multiarray/unmask.rb +10 -7
  40. data/lib/multiarray/variable.rb +11 -3
  41. data/test/tc_bool.rb +0 -8
  42. data/test/tc_compile.rb +72 -0
  43. data/test/tc_float.rb +0 -8
  44. data/test/tc_int.rb +0 -8
  45. data/test/tc_lazy.rb +22 -3
  46. data/test/tc_multiarray.rb +100 -126
  47. data/test/tc_object.rb +0 -16
  48. data/test/tc_rgb.rb +0 -16
  49. data/test/tc_sequence.rb +151 -165
  50. data/test/ts_multiarray.rb +2 -0
  51. metadata +7 -4
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/packagetask'
6
6
  require 'rbconfig'
7
7
 
8
8
  PKG_NAME = 'multiarray'
9
- PKG_VERSION = '0.22.0'
9
+ PKG_VERSION = '0.23.1'
10
10
  RB_FILES = FileList[ 'lib/**/*.rb' ]
11
11
  TC_FILES = FileList[ 'test/tc_*.rb' ]
12
12
  TS_FILES = FileList[ 'test/ts_*.rb' ]
data/lib/multiarray.rb CHANGED
@@ -98,6 +98,18 @@ class Object
98
98
 
99
99
  end
100
100
 
101
+ def sexp
102
+ self
103
+ end
104
+
105
+ def sexp?
106
+ false
107
+ end
108
+
109
+ def matched?
110
+ false
111
+ end
112
+
101
113
  # Boolean negation
102
114
  #
103
115
  # @return [FalseClass] Returns +false+.
@@ -105,7 +117,7 @@ class Object
105
117
  # @see NilClass#not
106
118
  # @see FalseClass#not
107
119
  def not
108
- false
120
+ false
109
121
  end
110
122
 
111
123
  # Boolean 'and' operation
@@ -116,7 +128,7 @@ class Object
116
128
  # @see FalseClass#and
117
129
  # @see NilClass#and
118
130
  def and( other )
119
- unless other.is_a? Hornetseye::Node
131
+ unless other.matched?
120
132
  other
121
133
  else
122
134
  x, y = other.coerce self
@@ -132,7 +144,7 @@ class Object
132
144
  # @see FalseClass#or
133
145
  # @see NilClass#or
134
146
  def or( other )
135
- unless other.is_a? Hornetseye::Node
147
+ unless other.matched?
136
148
  self
137
149
  else
138
150
  x, y = other.coerce self
@@ -150,7 +162,7 @@ class Object
150
162
  # @see Hornetseye::Node
151
163
  # @see Hornetseye::Binary_
152
164
  def eq( other )
153
- unless other.is_a? Hornetseye::Node
165
+ unless other.matched?
154
166
  self == other
155
167
  else
156
168
  x, y = other.coerce self
@@ -168,7 +180,7 @@ class Object
168
180
  # @see Hornetseye::Node
169
181
  # @see Hornetseye::Binary_
170
182
  def ne( other )
171
- unless other.is_a? Hornetseye::Node
183
+ unless other.matched?
172
184
  ( self == other ).not
173
185
  else
174
186
  x, y = other.coerce self
@@ -230,7 +242,7 @@ class NilClass
230
242
  # @see Object#and
231
243
  # @see FalseClass#and
232
244
  def and( other )
233
- unless other.is_a? Hornetseye::Node
245
+ unless other.matched?
234
246
  self
235
247
  else
236
248
  x, y = other.coerce self
@@ -246,7 +258,7 @@ class NilClass
246
258
  # @see Object#or
247
259
  # @see FalseClass#or
248
260
  def or( other )
249
- unless other.is_a? Hornetseye::Node
261
+ unless other.matched?
250
262
  other
251
263
  else
252
264
  x, y = other.coerce self
@@ -318,7 +330,7 @@ class FalseClass
318
330
  # @see Object#and
319
331
  # @see NilClass#and
320
332
  def and( other )
321
- unless other.is_a? Hornetseye::Node
333
+ unless other.matched?
322
334
  self
323
335
  else
324
336
  x, y = other.coerce self
@@ -334,7 +346,7 @@ class FalseClass
334
346
  # @see Object#or
335
347
  # @see NilClass#or
336
348
  def or( other )
337
- unless other.is_a? Hornetseye::Node
349
+ unless other.matched?
338
350
  other
339
351
  else
340
352
  x, y = other.coerce self
@@ -473,7 +485,7 @@ class Fixnum
473
485
  #
474
486
  # @private
475
487
  def power_with_hornetseye( other )
476
- if other.is_a? Hornetseye::Node
488
+ if other.matched?
477
489
  x, y = other.coerce self
478
490
  x ** y
479
491
  else
@@ -609,7 +621,13 @@ class Array
609
621
  #
610
622
  # @return [Array] An array with the filter elements.
611
623
  def gauss_blur_filter( sigma, max_error = 1.0 / 0x100 )
612
- def erf( x, sigma )
624
+ # Error function
625
+ #
626
+ # @param [Float] x Function argument
627
+ # @param [Float] sigma Function parameter
628
+ #
629
+ # @private
630
+ def erf(x, sigma)
613
631
  0.5 * Math.erf( x / ( Math.sqrt( 2.0 ) * sigma.abs ) )
614
632
  end
615
633
  raise 'Sigma must be greater than zero.' if sigma <= 0
@@ -639,7 +657,13 @@ class Array
639
657
  #
640
658
  # @return [Array] An array with the filter elements.
641
659
  def gauss_gradient_filter( sigma, max_error = 1.0 / 0x100 )
642
- def gauss( x, sigma )
660
+ # Gaussian function
661
+ #
662
+ # @param [Float] x Function argument
663
+ # @param [Float] sigma Function parameter
664
+ #
665
+ # @private
666
+ def gauss(x, sigma)
643
667
  1.0 / ( Math.sqrt( 2.0 * Math::PI ) * sigma.abs ) *
644
668
  Math.exp( -x**2 / ( 2.0 * sigma**2 ) )
645
669
  end
@@ -674,6 +698,18 @@ class Array
674
698
  zip( ( 0 ... size ).to_a ).collect &action
675
699
  end
676
700
 
701
+ def strip
702
+ collect { |arg| arg.strip }.inject [[], [], []] do |retval,s|
703
+ [retval[0] + s[0], retval[1] + s[1], retval[2] + [s[2]]]
704
+ end
705
+ end
706
+
707
+ end
708
+
709
+ class String
710
+ def method_name
711
+ tr '(),+\-*/%.@?~&|^<=>', '0123\456789ABCDEFGH'
712
+ end
677
713
  end
678
714
 
679
715
  begin
@@ -711,6 +747,7 @@ require 'multiarray/integral'
711
747
  require 'multiarray/mask'
712
748
  require 'multiarray/unmask'
713
749
  require 'multiarray/components'
750
+ require 'multiarray/field'
714
751
  require 'multiarray/operations'
715
752
  require 'multiarray/methods'
716
753
  require 'multiarray/rgb'
@@ -748,8 +785,8 @@ module Hornetseye
748
785
  term = lazy *( shape + [ :arity => arity - 1 ] ) do |*args|
749
786
  action.call *( args + [ index ] )
750
787
  end
751
- term = Node.match( term ).new term unless term.is_a? Node
752
- Lambda.new index, term
788
+ term = Node.match(term).new term unless term.matched?
789
+ Lambda.new index, term.sexp
753
790
  end
754
791
  ensure
755
792
  Thread.current[ :lazy ] = previous
@@ -770,7 +807,7 @@ module Hornetseye
770
807
  Thread.current[ :lazy ] = false
771
808
  begin
772
809
  retval = lazy *shape, &action
773
- retval.is_a?( Node ) ? retval.force : retval
810
+ retval.matched? ? retval.force : retval
774
811
  ensure
775
812
  Thread.current[ :lazy ] = previous
776
813
  end
@@ -790,7 +827,7 @@ module Hornetseye
790
827
  arity = options[ :arity ] || [ action.arity, shape.size ].max
791
828
  if arity <= 0
792
829
  term = action.call
793
- term.is_a?( Node ) ? term.to_type( term.typecode.maxint ) : term
830
+ term.matched? ? term.to_type(term.typecode.maxint) : term
794
831
  else
795
832
  index = Variable.new shape.empty? ? Hornetseye::INDEX( nil ) :
796
833
  Hornetseye::INDEX( shape.pop )
@@ -1,5 +1,5 @@
1
1
  # multiarray - Lazy multi-dimensional arrays for Ruby
2
- # Copyright (C) 2010 Jan Wedekind
2
+ # Copyright (C) 2010, 2011 Jan Wedekind
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -1,5 +1,5 @@
1
1
  # multiarray - Lazy multi-dimensional arrays for Ruby
2
- # Copyright (C) 2010 Jan Wedekind
2
+ # Copyright (C) 2010, 2011 Jan Wedekind
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -14,6 +14,14 @@
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
+ class Complex
18
+
19
+ def decompose(i)
20
+ [real, imag][i]
21
+ end
22
+
23
+ end
24
+
17
25
  # Namespace of Hornetseye computer vision library
18
26
  module Hornetseye
19
27
 
@@ -35,8 +43,8 @@ module Hornetseye
35
43
  # coercion.
36
44
  #
37
45
  # @private
38
- def generic?( value )
39
- value.is_a?( Numeric ) or value.is_a?( GCCValue )
46
+ def generic?(value)
47
+ value.is_a?(Numeric) or value.is_a?(GCCValue)
40
48
  end
41
49
 
42
50
  # Construct complex number using polar coordinates
@@ -48,7 +56,7 @@ module Hornetseye
48
56
  #
49
57
  # @private
50
58
  def polar( r, theta )
51
- new r * Math.cos( theta ), r * Math.sin( theta )
59
+ new r * Math.cos(theta), r * Math.sin(theta)
52
60
  end
53
61
 
54
62
  end
@@ -98,7 +106,7 @@ module Hornetseye
98
106
  # @return [Object] Returns +value+.
99
107
  #
100
108
  # @private
101
- def assign( value )
109
+ def assign(value)
102
110
  @real, @imag = value.real, value.imag
103
111
  end
104
112
 
@@ -109,7 +117,7 @@ module Hornetseye
109
117
  # @return [Array<InternalComplex>] Result of coercion.
110
118
  #
111
119
  # @private
112
- def coerce( other )
120
+ def coerce(other)
113
121
  if other.is_a? InternalComplex
114
122
  return other, self
115
123
  elsif other.is_a? Complex
@@ -180,8 +188,8 @@ module Hornetseye
180
188
  # @return [InternalComplex] The result
181
189
  #
182
190
  # @private
183
- def +( other )
184
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
191
+ def +(other)
192
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
185
193
  InternalComplex.new @real + other.real, @imag + other.imag
186
194
  elsif InternalComplex.generic? other
187
195
  InternalComplex.new @real + other, @imag
@@ -198,8 +206,8 @@ module Hornetseye
198
206
  # @return [InternalComplex] The result
199
207
  #
200
208
  # @private
201
- def -( other )
202
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
209
+ def -(other)
210
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
203
211
  InternalComplex.new @real - other.real, @imag - other.imag
204
212
  elsif InternalComplex.generic? other
205
213
  InternalComplex.new @real - other, @imag
@@ -216,8 +224,8 @@ module Hornetseye
216
224
  # @return [InternalComplex] The result
217
225
  #
218
226
  # @private
219
- def *( other )
220
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
227
+ def *(other)
228
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
221
229
  InternalComplex.new @real * other.real - @imag * other.imag,
222
230
  @real * other.imag + @imag * other.real
223
231
  elsif InternalComplex.generic? other
@@ -235,8 +243,8 @@ module Hornetseye
235
243
  # @return [InternalComplex] The result
236
244
  #
237
245
  # @private
238
- def /( other )
239
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
246
+ def /(other)
247
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
240
248
  self * other.conj / other.abs2
241
249
  elsif InternalComplex.generic? other
242
250
  InternalComplex.new @real / other, @imag / other
@@ -254,13 +262,13 @@ module Hornetseye
254
262
  # @return [InternalComplex] The result
255
263
  #
256
264
  # @private
257
- def **( other )
258
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
265
+ def **(other)
266
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
259
267
  r, theta = polar
260
268
  ore = other.real
261
269
  oim = other.imag
262
- nr = Math.exp ore * Math.log( r ) - oim * theta
263
- ntheta = theta * ore + oim * Math.log( r )
270
+ nr = Math.exp ore * Math.log(r) - oim * theta
271
+ ntheta = theta * ore + oim * Math.log(r)
264
272
  InternalComplex.polar nr, ntheta
265
273
  elsif InternalComplex.generic? other
266
274
  r, theta = polar
@@ -306,11 +314,11 @@ module Hornetseye
306
314
  # equal or not.
307
315
  #
308
316
  # @private
309
- def ==( other )
310
- if other.is_a?( InternalComplex ) or other.is_a?( Complex )
317
+ def ==(other)
318
+ if other.is_a?(InternalComplex) or other.is_a?(Complex)
311
319
  @real.eq( other.real ).and( @imag.eq( other.imag ) )
312
320
  elsif InternalComplex.generic? other
313
- @real.eq( other ).and( @imag.eq( 0 ) )
321
+ @real.eq(other).and( @imag.eq( 0 ) )
314
322
  else
315
323
  false
316
324
  end
@@ -323,8 +331,8 @@ module Hornetseye
323
331
  # @return [Numeric,GCCValue] Returns the requested component.
324
332
  #
325
333
  # @private
326
- def decompose( i )
327
- [ @real, @imag ][ i ]
334
+ def decompose(i)
335
+ [@real, @imag][i]
328
336
  end
329
337
 
330
338
  end
@@ -341,7 +349,7 @@ module Math
341
349
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
342
350
  #
343
351
  # @private
344
- def sqrt_with_internalcomplex( z )
352
+ def sqrt_with_internalcomplex(z)
345
353
  if z.is_a? Hornetseye::InternalComplex
346
354
  real = sqrt( ( z.abs + z.real ) / 2 )
347
355
  imag = ( z.imag < 0 ).conditional -sqrt( ( z.abs - z.real ) / 2 ),
@@ -363,7 +371,7 @@ module Math
363
371
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
364
372
  #
365
373
  # @private
366
- def exp_with_internalcomplex( z )
374
+ def exp_with_internalcomplex(z)
367
375
  if z.is_a? Hornetseye::InternalComplex
368
376
  real = exp( z.real ) * cos( z.imag )
369
377
  imag = exp( z.real ) * sin( z.imag )
@@ -384,7 +392,7 @@ module Math
384
392
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
385
393
  #
386
394
  # @private
387
- def cos_with_internalcomplex( z )
395
+ def cos_with_internalcomplex(z)
388
396
  if z.is_a? Hornetseye::InternalComplex
389
397
  real = cos( z.real ) * cosh( z.imag )
390
398
  imag = -sin( z.real ) * sinh( z.imag )
@@ -405,7 +413,7 @@ module Math
405
413
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
406
414
  #
407
415
  # @private
408
- def sin_with_internalcomplex( z )
416
+ def sin_with_internalcomplex(z)
409
417
  if z.is_a? Hornetseye::InternalComplex
410
418
  real = sin( z.real ) * cosh( z.imag )
411
419
  imag = cos( z.real ) * sinh( z.imag )
@@ -426,9 +434,9 @@ module Math
426
434
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
427
435
  #
428
436
  # @private
429
- def tan_with_internalcomplex( z )
437
+ def tan_with_internalcomplex(z)
430
438
  if z.is_a? Hornetseye::InternalComplex
431
- sin( z ) / cos( z )
439
+ sin(z) / cos(z)
432
440
  else
433
441
  tan_without_internalcomplex z
434
442
  end
@@ -445,7 +453,7 @@ module Math
445
453
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
446
454
  #
447
455
  # @private
448
- def cosh_with_internalcomplex( z )
456
+ def cosh_with_internalcomplex(z)
449
457
  if z.is_a? Hornetseye::InternalComplex
450
458
  real = cosh( z.real ) * cos( z.imag )
451
459
  imag = sinh( z.real ) * sin( z.imag )
@@ -466,7 +474,7 @@ module Math
466
474
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
467
475
  #
468
476
  # @private
469
- def sinh_with_internalcomplex( z )
477
+ def sinh_with_internalcomplex(z)
470
478
  if z.is_a? Hornetseye::InternalComplex
471
479
  real = sinh( z.real ) * cos( z.imag )
472
480
  imag = cosh( z.real ) * sin( z.imag )
@@ -487,9 +495,9 @@ module Math
487
495
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
488
496
  #
489
497
  # @private
490
- def tanh_with_internalcomplex( z )
498
+ def tanh_with_internalcomplex(z)
491
499
  if z.is_a? Hornetseye::InternalComplex
492
- sinh( z ) / cosh( z )
500
+ sinh(z) / cosh(z)
493
501
  else
494
502
  tanh_without_internalcomplex z
495
503
  end
@@ -506,7 +514,7 @@ module Math
506
514
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
507
515
  #
508
516
  # @private
509
- def log_with_internalcomplex( z )
517
+ def log_with_internalcomplex(z)
510
518
  if z.is_a? Hornetseye::InternalComplex
511
519
  r, theta = z.polar
512
520
  Hornetseye::InternalComplex.new log( r.abs ), theta
@@ -526,9 +534,9 @@ module Math
526
534
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
527
535
  #
528
536
  # @private
529
- def log10_with_internalcomplex( z )
537
+ def log10_with_internalcomplex(z)
530
538
  if z.is_a? Hornetseye::InternalComplex
531
- log( z ) / log( 10 )
539
+ log(z) / log( 10 )
532
540
  else
533
541
  log10_without_internalcomplex z
534
542
  end
@@ -545,7 +553,7 @@ module Math
545
553
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
546
554
  #
547
555
  # @private
548
- def acos_with_internalcomplex( z )
556
+ def acos_with_internalcomplex(z)
549
557
  if z.is_a? Hornetseye::InternalComplex
550
558
  -1.0.im * log( z + 1.0.im * sqrt( 1.0 - z * z ) )
551
559
  else
@@ -564,7 +572,7 @@ module Math
564
572
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
565
573
  #
566
574
  # @private
567
- def asin_with_internalcomplex( z )
575
+ def asin_with_internalcomplex(z)
568
576
  if z.is_a? Hornetseye::InternalComplex
569
577
  -1.0.im * log( 1.0.im * z + sqrt( 1.0 - z * z ) )
570
578
  else
@@ -583,7 +591,7 @@ module Math
583
591
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
584
592
  #
585
593
  # @private
586
- def atan_with_internalcomplex( z )
594
+ def atan_with_internalcomplex(z)
587
595
  if z.is_a? Hornetseye::InternalComplex
588
596
  1.0.im * log( ( 1.0.im + z ) / ( 1.0.im - z ) ) / 2.0
589
597
  else
@@ -602,7 +610,7 @@ module Math
602
610
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
603
611
  #
604
612
  # @private
605
- def acosh_with_internalcomplex( z )
613
+ def acosh_with_internalcomplex(z)
606
614
  if z.is_a? Hornetseye::InternalComplex
607
615
  log( z + sqrt( z * z - 1.0 ) )
608
616
  else
@@ -621,7 +629,7 @@ module Math
621
629
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
622
630
  #
623
631
  # @private
624
- def asinh_with_internalcomplex( z )
632
+ def asinh_with_internalcomplex(z)
625
633
  if z.is_a? Hornetseye::InternalComplex
626
634
  log( z + sqrt( 1.0 + z * z ) )
627
635
  else
@@ -640,7 +648,7 @@ module Math
640
648
  # @return [Object,Hornetseye::InternalComplex] Result of method call.
641
649
  #
642
650
  # @private
643
- def atanh_with_internalcomplex( z )
651
+ def atanh_with_internalcomplex(z)
644
652
  if z.is_a? Hornetseye::InternalComplex
645
653
  log( ( 1.0 + z ) / ( 1.0 - z ) ) / 2.0
646
654
  else
@@ -701,10 +709,16 @@ module Hornetseye
701
709
  # @return The return value should be ignored.
702
710
  #
703
711
  # @private
704
- def inherited( subclass )
712
+ def inherited(subclass)
705
713
  subclass.num_elements = 2
706
714
  end
707
715
 
716
+ def inherit(element_type)
717
+ retval = Class.new self
718
+ retval.element_type = element_type
719
+ retval
720
+ end
721
+
708
722
  # Construct new object from arguments
709
723
  #
710
724
  # @param [Object] real Real component of complex number.
@@ -747,11 +761,7 @@ module Hornetseye
747
761
  # "SCOMPLEX").
748
762
  def inspect
749
763
  unless element_type.nil?
750
- retval = IDENTIFIER[ element_type ] || "COMPLEX(#{element_type.inspect})"
751
- ( class << self; self; end ).instance_eval do
752
- define_method( :inspect ) { retval }
753
- end
754
- retval
764
+ IDENTIFIER[ element_type ] || "COMPLEX(#{element_type.inspect})"
755
765
  else
756
766
  super
757
767
  end
@@ -782,11 +792,11 @@ module Hornetseye
782
792
  # @return [Class] Result of coercion.
783
793
  #
784
794
  # @private
785
- def coercion( other )
795
+ def coercion(other)
786
796
  if other < COMPLEX_
787
797
  Hornetseye::COMPLEX element_type.coercion( other.element_type )
788
798
  elsif other < INT_ or other < FLOAT_
789
- Hornetseye::COMPLEX element_type.coercion( other )
799
+ Hornetseye::COMPLEX element_type.coercion(other)
790
800
  else
791
801
  super other
792
802
  end
@@ -799,11 +809,11 @@ module Hornetseye
799
809
  # @return [Array<Class>] Result of coercion.
800
810
  #
801
811
  # @private
802
- def coerce( other )
812
+ def coerce(other)
803
813
  if other < COMPLEX_
804
814
  return other, self
805
815
  elsif other < INT_ or other < FLOAT_
806
- return Hornetseye::COMPLEX( other ), self
816
+ return Hornetseye::COMPLEX(other), self
807
817
  else
808
818
  super other
809
819
  end
@@ -814,7 +824,7 @@ module Hornetseye
814
824
  # @param [Object] other Object to compare with.
815
825
  #
816
826
  # @return [Boolean] Boolean indicating whether classes are equal.
817
- def ==( other )
827
+ def ==(other)
818
828
  other.is_a? Class and other < COMPLEX_ and
819
829
  element_type == other.element_type
820
830
  end
@@ -835,7 +845,7 @@ module Hornetseye
835
845
  # @return [Boolean] Returns +true+ if objects are equal.
836
846
  #
837
847
  # @private
838
- def eql?( other )
848
+ def eql?(other)
839
849
  self == other
840
850
  end
841
851
 
@@ -877,7 +887,7 @@ module Hornetseye
877
887
  # @return [Object] Returns +value+.
878
888
  #
879
889
  # @private
880
- def assign( value )
890
+ def assign(value)
881
891
  value = value.simplify
882
892
  if @value.real.respond_to? :assign
883
893
  @value.real.assign value.get.real
@@ -954,9 +964,9 @@ module Hornetseye
954
964
  # @return [Class] Result of type alignment.
955
965
  #
956
966
  # @private
957
- def align( context )
967
+ def align(context)
958
968
  if self < COMPLEX_
959
- Hornetseye::COMPLEX element_type.align( context )
969
+ Hornetseye::COMPLEX element_type.align(context)
960
970
  else
961
971
  super context
962
972
  end
@@ -969,7 +979,7 @@ module Hornetseye
969
979
  end
970
980
 
971
981
  # Module providing the operations to manipulate array expressions
972
- module Operations
982
+ class Node
973
983
 
974
984
  define_unary_op :real, :scalar
975
985
  define_unary_op :imag, :scalar
@@ -978,7 +988,7 @@ module Hornetseye
978
988
  #
979
989
  # @return [Node] Array with real values.
980
990
  def real_with_decompose
981
- if typecode == OBJECT or is_a?( Variable )
991
+ if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy]
982
992
  real_without_decompose
983
993
  elsif typecode < COMPLEX_
984
994
  decompose 0
@@ -994,7 +1004,7 @@ module Hornetseye
994
1004
  # @param [Object] Value or array of values to assign to real components.
995
1005
  #
996
1006
  # @return [Object] Returns +value+.
997
- def real=( value )
1007
+ def real=(value)
998
1008
  if typecode < COMPLEX_
999
1009
  decompose( 0 )[] = value
1000
1010
  elsif typecode == OBJECT
@@ -1010,7 +1020,7 @@ module Hornetseye
1010
1020
  #
1011
1021
  # @return [Node] Array with imaginary values.
1012
1022
  def imag_with_decompose
1013
- if typecode == OBJECT or is_a?( Variable )
1023
+ if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy]
1014
1024
  imag_without_decompose
1015
1025
  elsif typecode < COMPLEX_
1016
1026
  decompose 1
@@ -1026,7 +1036,7 @@ module Hornetseye
1026
1036
  # @param [Object] Value or array of values to assign to imaginary components.
1027
1037
  #
1028
1038
  # @return [Object] Returns +value+.
1029
- def imag=( value )
1039
+ def imag=(value)
1030
1040
  if typecode < COMPLEX_
1031
1041
  decompose( 1 )[] = value
1032
1042
  elsif typecode == OBJECT
@@ -1034,7 +1044,7 @@ module Hornetseye
1034
1044
  real + value * Complex::I
1035
1045
  end
1036
1046
  else
1037
- raise "Cannot assign imaginary values to object of type #{array_type.inspect}"
1047
+ raise "Cannot assign imaginary values to elements of type #{typecode.inspect}"
1038
1048
  end
1039
1049
  end
1040
1050
 
@@ -1052,9 +1062,7 @@ module Hornetseye
1052
1062
  # @see COMPLEX_
1053
1063
  # @see COMPLEX_.element_type
1054
1064
  def COMPLEX( element_type )
1055
- retval = Class.new COMPLEX_
1056
- retval.element_type = element_type
1057
- retval
1065
+ COMPLEX_.inherit element_type
1058
1066
  end
1059
1067
 
1060
1068
  module_function :COMPLEX
@@ -1074,7 +1082,7 @@ module Hornetseye
1074
1082
  # @return [SCOMPLEX] The wrapped Complex value.
1075
1083
  #
1076
1084
  # @private
1077
- def SCOMPLEX( value )
1085
+ def SCOMPLEX(value)
1078
1086
  SCOMPLEX.new value
1079
1087
  end
1080
1088
 
@@ -1087,7 +1095,7 @@ module Hornetseye
1087
1095
  # @return [DCOMPLEX] The wrapped Complex value.
1088
1096
  #
1089
1097
  # @private
1090
- def DCOMPLEX( value )
1098
+ def DCOMPLEX(value)
1091
1099
  DCOMPLEX.new value
1092
1100
  end
1093
1101