Top Level Namespace

Defined Under Namespace

Classes: DataTypeError, NMGCHolder, NMatrix, StorageTypeError

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_POW',
 :'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	 		=> DTYPES,
  :int8_t				=> DTYPES,
  :int16_t			=> DTYPES,
  :int32_t			=> DTYPES,
  :int64_t			=> DTYPES,
  :float32_t		=> DTYPES,
  :float64_t		=> DTYPES,
  :'nm::Complex64'		=> DTYPES,
  :'nm::Complex128'		=> DTYPES,
  :'nm::Rational32'		=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
  :'nm::Rational64'		=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
  :'nm::Rational128'	=> nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
  :'nm::RubyObject'		=> DTYPES
}

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
81
82
83
84
# File 'ext/nmatrix_gemv/extconf.rb', line 63

def create_conf_h(file) #:nodoc:
  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

    # FIXME: Find a better way to do this:
    hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0'
    hfile.puts "#define OLD_RB_SCAN_ARGS" if RUBY_VERSION < '1.9.3'

    for line in $defs
      line =~ /^-D(.*)/
      hfile.printf "#define %s 1\n", $1
    end

    hfile.puts
    hfile.puts "#endif"
  end
end

#find_newer_gplusplusObject

:nodoc:



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/nmatrix_gemv/extconf.rb', line 112

def find_newer_gplusplus #:nodoc:
  print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
  [9,8,7,6,5,4,3].each do |minor|
    ver = "4.#{minor}"
    gpp = "g++-#{ver}"
    result = `which #{gpp}`
    next if result.empty?
    CONFIG['CXX'] = gpp
    puts ver
    return CONFIG['CXX']
  end
  false
end

#gplusplus_versionObject

:nodoc:



126
127
128
129
130
131
132
133
134
135
# File 'ext/nmatrix_gemv/extconf.rb', line 126

def gplusplus_version #:nodoc:
  cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM - </dev/null | grep #{n}`.chomp.split(' ')[2] }
  major = cxxvar.call('__GNUC__')
  minor = cxxvar.call('__GNUC_MINOR__')
  patch = cxxvar.call('__GNUC_PATCHLEVEL__')

  raise("unable to determine g++ version (match to get version was nil)") if major.nil? || minor.nil? || patch.nil?

  "#{major}.#{minor}.#{patch}"
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_gemv/extconf.rb', line 32

def have_type(type, header=nil) #:nodoc:
  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

:nodoc:



22
23
24
# File 'ext/nmatrix_gemv/ttable_helper.rb', line 22

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