Top Level Namespace

Defined Under Namespace

Modules: FFTW, NMath Classes: NArray, NArrayScalar, NMatrix, NMatrixLU, NVector

Instance Method Summary collapse

Instance Method Details

#__install_rbObject



38
# File 'ext/narray/extconf.rb', line 38

alias __install_rb :install_rb

#create_conf_h(file) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'ext/narray/extconf.rb', line 27

def create_conf_h(file)
  print "creating #{file}\n"
  hfile = open(file, "w")
  for line in $defs
    line =~ /^-D(.*)/
    hfile.printf "#define %s 1\n", $1
  end
  hfile.close
end

#have_type(type, header = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'ext/narray/extconf.rb', line 3

def have_type(type, header=nil)
  printf "checking for %s... ", type
  STDOUT.flush
  src = <<"SRC"
#include <ruby.h>
SRC
  unless header.nil?
  src << <<"SRC"
#include <#{header}>
SRC
  end
  r = try_link(src + <<"SRC")
  int main() { return 0; }
  int t() { #{type} a; return 0; }
SRC
  unless r
    print "no\n"
    return false
  end
  $defs.push(format("-DHAVE_%s", type.upcase))
  print "yes\n"
  return true
end

#install_rb(mfile, dest, srcdir = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'ext/narray/extconf.rb', line 39

def install_rb(mfile, dest, srcdir = nil)
  __install_rb(mfile, dest, srcdir)
  archdir = dest.sub(/sitelibdir/,"sitearchdir").sub(/rubylibdir/,"archdir")
  path = ['$(srcdir)/narray.h','narray_config.h']
  path << ['libnarray.a'] if /cygwin|mingw/ =~ RUBY_PLATFORM
  for f in path
    mfile.printf "\t@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)' %s %s\n", f, archdir
  end
end

#mkfuncs(name, t1, t2, func, idx = ["i"]*3) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/narray/mknafunc.rb', line 111

def mkfuncs(name,t1,t2,func,idx=["i"]*3)

  print "
/* ------------------------- #{name} --------------------------- */\n"
  c  = $type_codes
  td = $data_types
  tr = $real_types

  for i in 0...c.size
    if func[i] != nil && func[i] != "copy"
      if /Insp/ =~ name
        f = func[i].
          gsub(/p2\./,"(*((#{t2[i]}*)p2)).").
          gsub(/\*p1/,"*((#{t1[i]}*)p1)").
          gsub(/\*p2/,"*((#{t2[i]}*)p2)")
      else
        f = func[i].
          gsub(/p1\./,"(*((#{t1[i]}*)(p1+#{idx[0]}*i1))).").
          gsub(/p2\./,"(*((#{t2[i]}*)(p2+#{idx[1]}*i2))).").
          gsub(/p3\./,"(*((#{t2[i]}*)(p3+#{idx[2]}*i3))).").
          gsub(/\*p1/,"*((#{t1[i]}*)(p1+#{idx[0]}*i1))").
          gsub(/\*p2/,"*((#{t2[i]}*)(p2+#{idx[1]}*i2))").
          gsub(/\*p3/,"*((#{t2[i]}*)(p3+#{idx[2]}*i3))").
          gsub(/\(u_int8_t\*\)p3/,"(u_int8_t*)(p3+#{idx[2]}*i3)").
          gsub(/p2;/,'p2+i*i2;')
      end
      f = f.
        gsub(/type1/,td[i]).
        gsub(/typec/,t1[i]).
        gsub(/typef/,tr[i])
      puts $func_body.
	gsub(/type1/,td[i]).
	gsub(/typec/,t1[i]).
	gsub(/typef/,tr[i]).
	gsub(/#name/,name).
	gsub(/OPERATION/,f).
	gsub(/#C/,c[i])
    end
  end

  # Function Array

  print "\nna_func_t #{name}Funcs =\n{ "
  m = []
  for i in 0...c.size
    if func[i] == nil
      m += ['TpErr']
    elsif func[i]=='copy'
      m += ['Set'+c[$data_types.index(t1[i])]+c[i]]
    else
      m += [name+c[i]]
    end
  end
  print m.join(", ")+" };\n"

end

#mkmathfuncs(bsname, func) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'ext/narray/mkmath.rb', line 518

def mkmathfuncs(bsname,func)

  print "
/* ------------------------- #{bsname} --------------------------- */\n"
  c  = $type_codes
  tr = $real_types
  td = $data_types
  name = bsname

  # Function Definition
  head = "static void #{name}#code(void *p1, void *p2)"
  for i in 0...c.size
    if func[i] != nil && func[i]=~/^\{/
      f = func[i].
	gsub(/p1->/,"((#{td[i]}*)p1)->").
	gsub(/p2->/,"((#{td[i]}*)p2)->").
	gsub(/\*p1/,"*(#{td[i]}*)p1").
	gsub(/\*p2/,"*(#{td[i]}*)p2").
	gsub(/typer/, tr[i]).
	gsub(/typed/, td[i])
      puts( (head+f).gsub(/#code/,c[i]) )
    end
  end

  # Function Array

  print "\nna_mathfunc_t #{name}Funcs =\n{ "
  m = []
  for i in 0...c.size
    if func[i] == nil
      m += ['TpErr']
    elsif func[i]=='copy'
      m += ['Set'+c[i]*2]
    elsif !( func[i] =~ /^\{/ )
      m += [func[i]]
    else
      m += [name+c[i]]
    end
  end
  print m.join(", ")+" };\n"

end

#mkpowfuncs(name, funcs) ⇒ Object

Power



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'ext/narray/mkmath.rb', line 595

def mkpowfuncs(name,funcs)

  print "
/* ------------------------- #{name} --------------------------- */\n"
  c  = $type_codes
  n  = $type_codes.size
  td = $data_types
  tr = $real_types

  # Function Definition

  for i in 0...n
    for j in 0...n
      funcs.each do |k|
	if c[i]=~k[0] && c[j]=~k[1]
	  tu = $data_types[$upcast[i][j]]
	  f = k[2].
	    gsub(/p1->/,"((#{tu}*)p1)->").
	    gsub(/p2->/,"((#{td[i]}*)p2)->").
	    gsub(/p3->/,"((#{td[j]}*)p3)->").
	    gsub(/\*p1/,"*(#{tu}*)p1").
	    gsub(/\*p2/,"*(#{td[i]}*)p2").
	    gsub(/\*p3/,"*(#{td[j]}*)p3").
	    gsub(/typed/,td[i]).
            gsub(/typef/,tr[i])
	  puts $func_body.
            gsub(/#t1/,tu).
            gsub(/#t2/,td[i]).
            gsub(/#t3/,td[j]).
	    gsub(/#name/,name).
	    sub(/OPERATION/,f).
	    gsub(/#CC/,c[i]+c[j]).
	    gsub(/#C/, c[i])
	end
      end
    end
  end

  # function pointer array
  print "\nna_setfunc_t "+name+"Funcs = {\n"
  m = []
  for i in 0...n
    l = []
    for j in 0...n
      f = true
      for k in funcs
	if c[i]=~k[0] && c[j]=~k[1]
	  l += [name+c[i]+c[j]]
	  f = false
	  break
	end
      end
      if f
	l += ['TpErr']
      end
    end
    m += ['  { '+l.join(', ')+' }']
  end
  print m.join(",\n")+"\n};\n"

end

#mksetfuncs(name, op, id, funcs) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/narray/mknafunc.rb', line 44

def mksetfuncs(name,op,id,funcs)

  print "
/* ------------------------- #{name} --------------------------- */\n"
  c  = $type_codes
  n  = $type_codes.size
  td = $data_types
  tr = $real_types

  # Function Definition

  for i in 0...n
    for j in 0...n
      funcs.each do |k|
	if c[i]=~k[0] && c[j]=~k[1]
	  #if i==j
	  #  f = "memcpy(p1,p1,sizeof(typed));"
	  #else
	    f = k[2]
	  #end
	  f = f.
	    gsub(/p1\./,"((#{td[i]}*)p1)[i].").
	    gsub(/p2\./,"((#{td[j]}*)p2)[i].").
	    gsub(/\*p1/,"((#{td[i]}*)p1)[i]").
	    gsub(/\*p2/,"((#{td[j]}*)p2)[i]").
	    gsub(/ = /," = (#{tr[i]})").
            gsub(/#id/,id).
            gsub(/#op/,op).
	    gsub(/typed/,td[i]).
            gsub(/typef/,tr[i])
	  puts $func_body.
	    gsub(/typed/,td[i]).
            gsub(/typef/,tr[i]).
	    gsub(/#name/,name).
	    sub(/OPERATION/,f).
	    gsub(/#CC/,c[i]+c[j])
	end
      end
    end
  end

  # function pointer array
  print "\nna_setfunc_t "+name+"Funcs = {\n"
  m = []
  for i in 0...n
    l = []
    for j in 0...n
      f = true
      for k in funcs
	if c[i]=~k[0] && c[j]=~k[1]
	  l += [name+c[i]+c[j]]
	  f = false
	  break
	end
      end
      if f
	l += ['TpErr']
      end
    end
    m += ['  { '+l.join(', ')+' }']
  end
  print m.join(",\n")+"\n};\n"

end

#mksortfuncs(bsname, t1, t2, func) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'ext/narray/mknafunc.rb', line 170

def mksortfuncs(bsname,t1,t2,func)

  print "
/* ------------------------- #{bsname} --------------------------- */\n"
  c  = $type_codes
  tf = $real_types
  name = bsname

  # Function Definition
  head = "static int #{name}#code(const void *p1, const void *p2)"
  for i in 0...c.size
    if func[i] != nil && func[i]=~/^\{/
      f = func[i].
	gsub(/p1->/,"((#{t1[i]}*)p1)->").
	gsub(/p2->/,"((#{t2[i]}*)p2)->").
	gsub(/\*\*p1/,"**(#{t1[i]}**)p1").
	gsub(/\*\*p2/,"**(#{t2[i]}**)p2").
	gsub(/\*p1/,"*(#{t1[i]}*)p1").
	gsub(/\*p2/,"*(#{t2[i]}*)p2").
	gsub(/typef/,tf[i])
      puts( (head+f).gsub(/#code/,c[i]) )
    end
  end

  # Function Array

  print "\nna_sortfunc_t #{name}Funcs =\n{ "
  m = []
  for i in 0...c.size
    if func[i] == nil
      m += ['(int (*)(const void *, const void *))TpErrI']
    elsif func[i]=='copy'
      m += ['Set'+c[i]*2]
    elsif !( func[i] =~ /^\{/ )
      m += [func[i]]
    else
      m += [name+c[i]]
    end
  end
  print m.join(", ")+" };\n"

end