Top Level Namespace

Defined Under Namespace

Classes: Array, N, NMatrix, NVector, Object, String

Constant Summary collapse

DTYPES =
[
	:uint8_t,
	:int8_t,
	:int16_t,
	:int32_t,
	:int64_t,
	:float32_t,
	:float64_t,
	:'nm::Complex64',
	:'nm::Complex128',
	:'nm::Rational32',
	:'nm::Rational64',
	:'nm::Rational128',
	:'nm::RubyObject'
]
ITYPES =
[
	:uint8_t,
	:uint16_t,
	:uint32_t,
	:uint64_t
]
EWOPS =
[
	:'nm::EW_ADD',
	:'nm::EW_SUB',
	:'nm::EW_MUL',
	:'nm::EW_DIV',
	:'nm::EW_MOD',
  :'nm::EW_EQEQ',
  :'nm::EW_NEQ',
  :'nm::EW_LT',
  :'nm::EW_GT',
  :'nm::EW_LEQ',
  :'nm::EW_GEQ'
]
LR_ALLOWED =
{
	:uint8_t	 		=> nullify([:RubyObject]),
	:int8_t				=> nullify([:RubyObject]),
	:int16_t			=> nullify([:RubyObject]),
	:int32_t			=> nullify([:RubyObject]),
	:int64_t			=> nullify([:RubyObject]),
	:float32_t		=> nullify([:RubyObject]),
	:float64_t		=> nullify([:RubyObject]),
	:Complex64		=> nullify([:RubyObject]),
	:Complex128		=> nullify([:RubyObject]),
	:Rational32		=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
	:Rational64		=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
	:Rational128	=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
	:RubyObject		=> nullify(DTYPES - [:RubyObject])
}

Instance Method Summary collapse

Instance Method Details

#create_conf_h(file) ⇒ Object

Function derived from NArray’s extconf.rb.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/nmatrix/extconf.rb', line 63

def create_conf_h(file)
  print "creating #{file}\n"
  File.open(file, 'w') do |hfile|
  	header_guard = file.upcase.sub(/\s|\./, '_')
		
		hfile.puts "#ifndef #{header_guard}"
		hfile.puts "#define #{header_guard}"
		hfile.puts
		
		for line in $defs
		  line =~ /^-D(.*)/
		  hfile.printf "#define %s 1\n", $1
		end
		
		hfile.puts
		hfile.puts "#endif"
  end
end

#find_newer_gplusplusObject



141
142
143
144
145
146
147
148
149
# File 'ext/nmatrix/extconf.rb', line 141

def find_newer_gplusplus
  [7,6,5,4,3].each do |minor|
    result = `which g++-4.#{minor}`
    next if result.empty?
    CONFIG['CXX'] = "g++-4.#{minor}"
    return CONFIG['CXX']
  end
  false
end

#gplusplus_versionObject



151
152
153
# File 'ext/nmatrix/extconf.rb', line 151

def gplusplus_version
  `#{CONFIG['CXX']} -v 2>&1`.lines.to_a.last.match(/gcc\sversion\s(\d\.\d.\d)/).captures.first
end

#have_type(type, header = nil) ⇒ Object

Function derived from NArray’s extconf.rb.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/nmatrix/extconf.rb', line 32

def have_type(type, header=nil)
  printf "checking for %s... ", type
  STDOUT.flush

  src = <<"SRC"
#include <ruby.h>
SRC


  src << <<"SRC" unless header.nil?
#include <#{header}>
SRC

  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

#nullify(disabled) ⇒ Object

A helper file for generating and maintaining template tables.



5
6
7
# File 'ext/nmatrix/ttable_helper.rb', line 5

def nullify(disabled)
	DTYPES.map { |t| if disabled.include?(t) then :NULL else t end }
end