ndtypes 0.2.0dev4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +2 -0
- data/History.md +0 -0
- data/README.md +19 -0
- data/Rakefile +125 -0
- data/ext/ruby_ndtypes/extconf.rb +55 -0
- data/ext/ruby_ndtypes/gc_guard.c +36 -0
- data/ext/ruby_ndtypes/gc_guard.h +12 -0
- data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
- data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
- data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
- data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
- data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
- data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
- data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
- data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
- data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
- data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
- data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
- data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
- data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
- data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
- data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
- data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
- data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
- data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
- data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
- data/lib/ndtypes.rb +45 -0
- data/lib/ndtypes/errors.rb +2 -0
- data/lib/ndtypes/version.rb +6 -0
- data/ndtypes.gemspec +47 -0
- data/spec/gc_table_spec.rb +10 -0
- data/spec/ndtypes_spec.rb +289 -0
- data/spec/spec_helper.rb +241 -0
- metadata +242 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
/* File containing headers for Ruby ndtypes wrapper.
|
2
|
+
*
|
3
|
+
* Author: Sameer Deshmukh (@v0dro)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef RUBY_NDTYPES_H
|
7
|
+
#define RUBY_NDTYPES_H
|
8
|
+
|
9
|
+
#if defined(__cplusplus)
|
10
|
+
extern "C" {
|
11
|
+
} /* satisfy cc-mode */
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#include "ruby.h"
|
15
|
+
#include "ndtypes.h"
|
16
|
+
|
17
|
+
/* Public interface for ndtypes. */
|
18
|
+
typedef struct NdtObject NdtObject;
|
19
|
+
extern VALUE cNDTypes;
|
20
|
+
|
21
|
+
int rb_ndtypes_check_type(VALUE obj);
|
22
|
+
NdtObject * rb_ndtypes_get_ndt_object(VALUE obj);
|
23
|
+
VALUE rb_ndtypes_make_ndt_object(NdtObject *ndt_p);
|
24
|
+
VALUE rb_ndtypes_wrap_ndt_object(void);
|
25
|
+
const ndt_t * rb_ndtypes_const_ndt(VALUE ndt);
|
26
|
+
VALUE rb_ndtypes_move_subtree(VALUE src, ndt_t *t);
|
27
|
+
VALUE rb_ndtypes_from_object(VALUE type);
|
28
|
+
VALUE rb_ndtypes_set_error(ndt_context_t *ctx);
|
29
|
+
VALUE rb_ndtypes_from_type(ndt_t *type);
|
30
|
+
|
31
|
+
#define INT2BOOL(t) (t ? Qtrue : Qfalse)
|
32
|
+
|
33
|
+
#if defined(__cplusplus)
|
34
|
+
} /* extern "C" { */
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#endif /* RUBY_NDTYPES_H */
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/* Various internal macros and function definitions. Not exposed to other Ruby C extensions. */
|
2
|
+
/* Author: Sameer Deshmukh (@v0dro) */
|
3
|
+
|
4
|
+
#ifndef RUBY_NDTYPES_INTERNAL_H
|
5
|
+
#define RUBY_NDTYPES_INTERNAL_H
|
6
|
+
|
7
|
+
#include "ruby.h"
|
8
|
+
#include "ndtypes.h"
|
9
|
+
#include "ruby_ndtypes.h"
|
10
|
+
|
11
|
+
extern VALUE mNDTypes_GCGuard;
|
12
|
+
|
13
|
+
/* typedefs */
|
14
|
+
typedef struct NdtObject NdtObject;
|
15
|
+
typedef struct ResourceBufferObject ResourceBufferObject;
|
16
|
+
|
17
|
+
/* macros */
|
18
|
+
#if SIZEOF_LONG == SIZEOF_VOIDP
|
19
|
+
# define PTR2NUM(x) (LONG2NUM((long)(x)))
|
20
|
+
# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
|
21
|
+
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
22
|
+
# define PTR2NUM(x) (LL2NUM((LONG_LONG)(x)))
|
23
|
+
# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
|
24
|
+
#else
|
25
|
+
# error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#endif /* RUBY_NDTYPES_INTERNAL_H */
|
data/lib/ndtypes.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'ndtypes/errors'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "ruby_ndtypes.so"
|
5
|
+
rescue LoadError
|
6
|
+
require 'ruby_ndtypes/ruby_ndtypes.so'
|
7
|
+
end
|
8
|
+
|
9
|
+
class NDTypes
|
10
|
+
# It so happens that over riding the .new method in a super class also
|
11
|
+
# tampers with the default .new method for class that inherit from the
|
12
|
+
# super class (Index in this case). Thus we first alias the original
|
13
|
+
# new method (from Object) to __new__ when the Index class is evaluated,
|
14
|
+
# and then we use an inherited hook such that the old new method (from
|
15
|
+
# Object) is once again the default .new for the subclass.
|
16
|
+
# Refer http://blog.sidu.in/2007/12/rubys-new-as-factory.html
|
17
|
+
class << self
|
18
|
+
alias :__new__ :new
|
19
|
+
|
20
|
+
def inherited subclass
|
21
|
+
class << subclass
|
22
|
+
alias :new :__new__
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def dup
|
28
|
+
str = self.serialize
|
29
|
+
NDT.deserialize str
|
30
|
+
end
|
31
|
+
|
32
|
+
# We over-ride the .new method so that even sending an NDTypes object can
|
33
|
+
# will allow the .new method to act as copy constructor and simply return
|
34
|
+
# copy of the argument.
|
35
|
+
def self.new *args, &block
|
36
|
+
type = args.first
|
37
|
+
|
38
|
+
return type.dup if type.is_a?(NDTypes)
|
39
|
+
|
40
|
+
allocate.tap { |i| i.send :initialize, *args, &block }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
NDT = NDTypes
|
45
|
+
|
data/ndtypes.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'ndtypes/version.rb'
|
5
|
+
|
6
|
+
def get_files
|
7
|
+
files = []
|
8
|
+
['ext', 'lib', 'spec'].each do |folder|
|
9
|
+
files.concat Dir.glob "#{folder}/**/*"
|
10
|
+
end
|
11
|
+
|
12
|
+
files.concat(
|
13
|
+
["CONTRIBUTING.md", "Gemfile", "History.md", "ndtypes.gemspec",
|
14
|
+
"README.md", "Rakefile"
|
15
|
+
])
|
16
|
+
|
17
|
+
files
|
18
|
+
end
|
19
|
+
files = get_files
|
20
|
+
|
21
|
+
NDTypes::DESCRIPTION = <<MSG
|
22
|
+
NDtypes is library for defining memory shapes using a easy and friendly interface.
|
23
|
+
|
24
|
+
It is a wrapper over the libndtypes C library.
|
25
|
+
MSG
|
26
|
+
|
27
|
+
Gem::Specification.new do |spec|
|
28
|
+
spec.name = 'ndtypes'
|
29
|
+
spec.version = NDTypes::VERSION
|
30
|
+
spec.authors = ['Sameer Deshmukh']
|
31
|
+
spec.email = ['sameer.deshmukh93@gmail.com']
|
32
|
+
spec.summary = %q{Ruby wrapper over libndtypes. A library for typing memory blocks.}
|
33
|
+
spec.description = NDTypes::DESCRIPTION
|
34
|
+
spec.homepage = "https://github.com/plures/ndtypes"
|
35
|
+
spec.license = 'BSD-3-Clause'
|
36
|
+
|
37
|
+
spec.files = files
|
38
|
+
spec.extensions = "ext/ruby_ndtypes/extconf.rb"
|
39
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
40
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
41
|
+
spec.require_paths = ["lib"]
|
42
|
+
|
43
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
44
|
+
spec.add_development_dependency 'rake-compiler'
|
45
|
+
spec.add_development_dependency 'pry'
|
46
|
+
spec.add_development_dependency 'pry-byebug'
|
47
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "global GC guard table" do
|
4
|
+
it "stores NDT objects as key and corresponding rbuf object as value" do
|
5
|
+
ndt = NDTypes.new("3 * int64")
|
6
|
+
|
7
|
+
gc_table = NDTypes::GCGuard.instance_variable_get(:@__gc_guard_table)
|
8
|
+
expect(gc_table.keys.size).to eq(1)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NDTypes do
|
4
|
+
context "::MAX_DIM" do
|
5
|
+
it "returns the maximum dimension possible" do
|
6
|
+
expect(NDTypes::MAX_DIM > 0).to eq(true)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context ".typedef" do
|
11
|
+
it "creates a typedef for an official type" do
|
12
|
+
NDTypes.typedef "node", "int32"
|
13
|
+
|
14
|
+
t = NDTypes.new "4 * node"
|
15
|
+
u = NDTypes.deserialize t.serialize
|
16
|
+
|
17
|
+
expect(t).to eq(u)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context ".instantiate" do
|
22
|
+
context "Typedef" do
|
23
|
+
it "instantiates NDTypes object from typedef and type" do
|
24
|
+
NDT.typedef "node", "int32"
|
25
|
+
NDT.typedef "cost", "int32"
|
26
|
+
NDT.typedef "graph", "var * var * (node, cost)"
|
27
|
+
|
28
|
+
t = NDT.new "var(offsets=[0,2]) * var(offsets=[0,3,10]) * (node, cost)"
|
29
|
+
u = NDT.instantiate "graph", t
|
30
|
+
expect(u.concrete?).to eq(true)
|
31
|
+
|
32
|
+
t = NDT.new "var(offsets=[0,2]) * var(offsets=[0,2,3]) * var(offsets=[0,1,2,3]) * (node, cost)"
|
33
|
+
expect {
|
34
|
+
NDT.instantiate("graph", t)
|
35
|
+
}.to raise_error(ValueError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context ".new" do
|
41
|
+
it "creates a basic shaped memory block" do
|
42
|
+
o = NDTypes.new("3 * uint64")
|
43
|
+
|
44
|
+
expect_serialize o
|
45
|
+
end
|
46
|
+
|
47
|
+
context "tests roundtrip" do
|
48
|
+
[
|
49
|
+
"2 * 3 * float64",
|
50
|
+
"2 * 3 * {a : uint8, b : complex64}",
|
51
|
+
].each do |s|
|
52
|
+
it "type: #{s}" do
|
53
|
+
t = NDT.new s
|
54
|
+
|
55
|
+
expect(t.to_s).to eq(s)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "from NDT" do
|
61
|
+
[
|
62
|
+
"2 * 3 * {a : 10 * bytes, b : 20 * string}",
|
63
|
+
"var(offsets=[0,2]) * var(offsets=[0,3,10]) * complex128"
|
64
|
+
].each do |s|
|
65
|
+
it "type: #{s}" do
|
66
|
+
t = NDT.new s
|
67
|
+
u = NDT.new t
|
68
|
+
|
69
|
+
expect(u).to eq(t)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "test with offset" do
|
74
|
+
t = NDT.new "{x: complex128, y: float64}", [[0, 2], [0, 3, 5]]
|
75
|
+
u = NDT.new t
|
76
|
+
|
77
|
+
expect(u).to eq(t)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "raises errors" do
|
82
|
+
[
|
83
|
+
"", "xyz", "var() * int64"
|
84
|
+
].each do |t|
|
85
|
+
it "type #{t} raises ValueError" do
|
86
|
+
expect { NDT.new(t) }.to raise_error(ValueError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "raises TypeError" do
|
91
|
+
expect { NDT.new(nil) }.to raise_error(TypeError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "FixedString" do
|
96
|
+
it "checks predicates" do
|
97
|
+
t = NDT.new "fixed_string(380, 'utf16')"
|
98
|
+
|
99
|
+
expect_serialize t
|
100
|
+
|
101
|
+
expect(t.abstract?).to eq(false)
|
102
|
+
expect(t.complex?).to eq(false)
|
103
|
+
expect(t.concrete?).to eq(true)
|
104
|
+
expect(t.float?).to eq(false)
|
105
|
+
expect(t.optional?).to eq(false)
|
106
|
+
expect(t.scalar?).to eq(true)
|
107
|
+
expect(t.signed?).to eq(false)
|
108
|
+
expect(t.unsigned?).to eq(false)
|
109
|
+
|
110
|
+
expect(t.c_contiguous?).to eq(true)
|
111
|
+
expect(t.f_contiguous?).to eq(true)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "checks fixed string common fields" do
|
115
|
+
[
|
116
|
+
['ascii', 1],
|
117
|
+
['utf8', 1],
|
118
|
+
['utf16', 2],
|
119
|
+
['utf32', 4]
|
120
|
+
].each do |encoding, codepoint_size|
|
121
|
+
t = NDT.new "fixed_string(20, '#{encoding}')"
|
122
|
+
|
123
|
+
expect_serialize t
|
124
|
+
expect(t.ndim).to eq(0)
|
125
|
+
|
126
|
+
if RUBY_PLATFORM != "i686-linux"
|
127
|
+
expect(t.itemsize).to eq(20 * codepoint_size)
|
128
|
+
expect(t.align).to eq(codepoint_size)
|
129
|
+
end
|
130
|
+
|
131
|
+
# raises tests.
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "#match" do
|
138
|
+
it "needs to contiguity requirements" do
|
139
|
+
p = NDT.new("... * 2 * 3 * float32")
|
140
|
+
c = NDT.new("2 * 3 * float32")
|
141
|
+
|
142
|
+
expect(p.match(c)).to eq(true)
|
143
|
+
end
|
144
|
+
|
145
|
+
context "C-contiguity required for inner dimensions" do
|
146
|
+
before do
|
147
|
+
@p = NDT.new "... * C[2 * 3 * float32]"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "with C input" do
|
151
|
+
c = NDT.new "2 * 3 * float32"
|
152
|
+
expect(@p.match(c)).to eq(true)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "with inner dimensionss C-contiguous" do
|
156
|
+
c = NDT.new "4 * 2 * 3 * float32"
|
157
|
+
expect(@p.match(c)).to eq(true)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "with inner dimensions C-contiguous" do
|
161
|
+
c = NDT.new "fixed(shape=4, step=-6) * 2 * 3 * float32"
|
162
|
+
expect(@p.match(c)).to eq(true)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "with F input" do
|
166
|
+
c = NDT.new "!2 * 3 * float32"
|
167
|
+
expect(@p.match(c)).to eq(false)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "F-contiguity required for inner dimensions" do
|
172
|
+
before do
|
173
|
+
@p = NDT.new "... * F[2 * 3 * float32]"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "with F input" do
|
177
|
+
c = NDT.new "fixed(shape=10, step=6) * fixed(shape=2, step=1) * fixed(shape=3, step=2) * float32"
|
178
|
+
expect(@p.match(c)).to eq(true)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "with C input" do
|
182
|
+
c = NDT.new "2 * 3 * float32"
|
183
|
+
expect(@p.match(c))
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "C-contiguity required for all dimensions after broadcast" do
|
188
|
+
before do
|
189
|
+
@p = NDT.new "C[... * 2 * 3 * float32]"
|
190
|
+
end
|
191
|
+
|
192
|
+
it "with C input" do
|
193
|
+
c = NDT.new "2 * 3 * float32"
|
194
|
+
expect(@p.match(c)).to eq(true)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "with all dimensions C-contiguous" do
|
198
|
+
c = NDT.new "4 * 2 * 3 * float32"
|
199
|
+
expect(@p.match(c)).to eq(true)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "with inner dimensions C-contiguous" do
|
203
|
+
c = NDT.new "fixed(shape=4, step=-6) * 2 * 3 * float32"
|
204
|
+
expect(@p.match(c)).to eq(false)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "with F input" do
|
208
|
+
c = NDT.new "!2 * 3 * float32"
|
209
|
+
expect(@p.match(c)).to eq(false)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "F-contiguity required for all dimensions after broadcast." do
|
214
|
+
before do
|
215
|
+
@p = NDT.new "F[... * 2 * 3 * float32]"
|
216
|
+
end
|
217
|
+
|
218
|
+
it "with C input" do
|
219
|
+
c = NDT.new "2 * 3 * float32"
|
220
|
+
expect(@p.match(c)).to eq(false)
|
221
|
+
|
222
|
+
c = NDT.new "4 * 2 * 3 * float32"
|
223
|
+
expect(@p.match(c)).to eq(false)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "with F input" do
|
227
|
+
c = NDT.new "!2 * 3 * float32"
|
228
|
+
expect(@p.match(c)).to eq(true)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "with all dimensions F-contiguous" do
|
232
|
+
c = NDT.new "!4 * 2 * 3 * float32"
|
233
|
+
expect(@p.match(c)).to eq(true)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "with inner dimensions C-contiguous" do
|
237
|
+
c = NDT.new "fixed(shape=10, step=6) * fixed(shape=2, step=1) * fixed(shape=3, step=2) * float32"
|
238
|
+
expect(@p.match(c)).to eq(false)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "#serialize" do
|
244
|
+
it "serializes the given shape" do
|
245
|
+
s = NDTypes.new "3 * char"
|
246
|
+
s.serialize
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "#to_s" do
|
251
|
+
it "converts to string using ndt_as_string" do
|
252
|
+
t = NDTypes.new "5 * int64"
|
253
|
+
|
254
|
+
expect(t.to_s).to eq("5 * int64")
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "#hidden_dtype" do
|
259
|
+
it "has hidden type" do
|
260
|
+
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context ".deserialize" do
|
265
|
+
it "deserializes the NDT object" do
|
266
|
+
s = NDTypes.new "3 * char"
|
267
|
+
t = s.serialize
|
268
|
+
u = NDTypes.deserialize t
|
269
|
+
|
270
|
+
expect(s).to eq(u)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "#dup" do
|
275
|
+
DTYPE_TEST_CASES.each do |dtype, mem|
|
276
|
+
it "dtype: #{dtype}" do
|
277
|
+
t = NDT.new dtype
|
278
|
+
u = t.dup
|
279
|
+
|
280
|
+
expect(t).to eq(u)
|
281
|
+
expect(t.ast).to eq(u.ast)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
skip "tests GC -- figure how to do this." do
|
286
|
+
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|