multiarray 0.2.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'tc_int'
3
2
  require 'tc_object'
4
3
  require 'tc_sequence'
5
4
  require 'tc_multiarray'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiarray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Wedekind
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 +00:00
12
+ date: 2010-01-26 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,19 +37,17 @@ files:
37
37
  - .document
38
38
  - lib/multiarray.rb
39
39
  - lib/multiarray/sequence_.rb
40
- - lib/multiarray/composite_type.rb
40
+ - lib/multiarray/pointer.rb
41
41
  - lib/multiarray/multiarray.rb
42
+ - lib/multiarray/lazy.rb
42
43
  - lib/multiarray/sequence.rb
43
44
  - lib/multiarray/list.rb
44
- - lib/multiarray/descriptortype.rb
45
- - lib/multiarray/type_operation.rb
45
+ - lib/multiarray/malloc.rb
46
46
  - lib/multiarray/int.rb
47
+ - lib/multiarray/pointer_.rb
47
48
  - lib/multiarray/type.rb
48
- - lib/multiarray/storage.rb
49
49
  - lib/multiarray/object.rb
50
50
  - lib/multiarray/int_.rb
51
- - lib/multiarray/memory.rb
52
- - lib/multiarray/sequence_operation.rb
53
51
  - test/ts_multiarray.rb
54
52
  - test/tc_multiarray.rb
55
53
  - test/tc_object.rb
@@ -1,67 +0,0 @@
1
- module Hornetseye
2
-
3
- # Abstract class for arrays and composite numbers
4
- #
5
- # @abstract
6
- class CompositeType < Type
7
-
8
- class << self
9
-
10
- # Type of elements this type is composed of
11
- #
12
- # @return [Type,Sequence_] The element type of this type.
13
- attr_accessor :element_type
14
-
15
- # Number of elements this type is composed of
16
- #
17
- # @return [Integer] The number of elements this type is composed of.
18
- attr_accessor :num_elements
19
-
20
- # Returns the type of storage object for storing values
21
- #
22
- # @return [Class] Returns the storage type for the element type.
23
- #
24
- # @private
25
- def storage
26
- element_type.storage
27
- end
28
-
29
- # Number of bytes for storing an object of this type
30
- #
31
- # @return [Integer] Number of bytes to store +num_elements+ elements of
32
- # type +element_type+.
33
- #
34
- # @private
35
- def bytesize
36
- element_type.bytesize * num_elements
37
- end
38
-
39
- # Returns the element type of this composite type
40
- #
41
- # @return [Class] Returns +element_type.basetype+.
42
- #
43
- # @private
44
- def basetype
45
- element_type.basetype
46
- end
47
-
48
- end
49
-
50
- # The element type of this object's type
51
- #
52
- # @return [Type,Sequence_] The element type of this object's type.
53
- def element_type
54
- self.class.element_type
55
- end
56
-
57
- # The number of elements this object's type is composed of
58
- #
59
- # @return [Integer] The number of elements this object's type is composed
60
- # of.
61
- def num_elements
62
- self.class.num_elements
63
- end
64
-
65
- end
66
-
67
- end
@@ -1,43 +0,0 @@
1
- module Hornetseye
2
-
3
- # Abstract class for describing scalar data types
4
- #
5
- # This class is for descriping scalar data types which are known to the Ruby
6
- # standard library. I.e. there is a descriptor for +Array#pack+ and
7
- # +String#unpack+.
8
- #
9
- # @see Array#pack
10
- # @see String#unpack
11
- #
12
- # @abstract
13
- class DescriptorType < Type
14
-
15
- class << self
16
-
17
- # Convert a Ruby object to a string containing the native representation
18
- #
19
- # @return [String] A string with the native representation of the value.
20
- #
21
- # @see Array#pack
22
- #
23
- # @private
24
- def pack( value )
25
- [ value ].pack descriptor
26
- end
27
-
28
- # Convert a string with the native representation to a Ruby object
29
- #
30
- # @return [Object] The corresponding Ruby object to the native value.
31
- #
32
- # @see String#unpack
33
- #
34
- # @private
35
- def unpack( value )
36
- value.unpack( descriptor ).first
37
- end
38
-
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,112 +0,0 @@
1
- module Hornetseye
2
-
3
- # Class for creating views on raw memory
4
- #
5
- # @see Storage
6
- # @see List
7
- # @private
8
- class Memory < Storage
9
-
10
- class << self
11
-
12
- # Create a +Memory+ object viewing a new +Malloc+ object
13
- #
14
- # @param [Integer] bytesize Number of bytes to allocate.
15
- # @return [Memory] The new +Memory+ object.
16
- #
17
- # @see Malloc
18
- # @private
19
- def alloc( bytesize )
20
- Memory.new Malloc.new( bytesize )
21
- end
22
-
23
- # Create a +Memory+ object viewing a new +Malloc+ object initialised with
24
- # the content of a string
25
- #
26
- # @param [String] str A Ruby string with data to write to memory.
27
- # object.
28
- # @return [Memory] The new +Memory+ object initialised with the data.
29
- #
30
- # @private
31
- def import( str )
32
- retval = alloc str.bytesize
33
- retval.import str
34
- retval
35
- end
36
-
37
- end
38
-
39
- # Create zero-offset view on a +Malloc+ object
40
- #
41
- # @param [Malloc] ptr A +Malloc+ object with the raw data.
42
- #
43
- # @private
44
- def initialize( ptr )
45
- super ptr
46
- end
47
-
48
- # Read an element from the memory
49
- #
50
- # @param [Type] typecode Information for converting native data type to
51
- # a Ruby object.
52
- # @return [Object] The element from the memory.
53
- #
54
- # @see #store
55
- # @see List#load
56
- # @private
57
- def load( typecode )
58
- typecode.unpack export( typecode.bytesize )
59
- end
60
-
61
- # Write an element to the memory
62
- #
63
- # @param [Type] typecode Information for converting Ruby object to native
64
- # data type.
65
- # @return [Object] Returns the parameter +value+.
66
- #
67
- # @see #load
68
- # @see List#store
69
- # @private
70
- def store( typecode, value )
71
- import typecode.pack( value )
72
- value
73
- end
74
-
75
- # Write multiple elements to memory
76
- #
77
- # @param [String] data A ruby string with data to write to memory.
78
- # @return [String] The parameter +data+.
79
- #
80
- # @see #export
81
- # @see List#import
82
- # @private
83
- def import( data )
84
- @data.write data
85
- end
86
-
87
- # Read multiple elements from memory
88
- #
89
- # @param [Integer] bytesize Number of bytes to read from memory.
90
- # @return [String] A Ruby string with the resulting data.
91
- #
92
- # @see #import
93
- # @see List#export
94
- # @private
95
- def export( bytesize )
96
- @data.read bytesize
97
- end
98
-
99
- # Create a new view with the specified offset
100
- #
101
- # @param [Integer] offset A non-negative offset.
102
- # @return [Memory] A new view for the specified part of the memory.
103
- #
104
- # @see List#+
105
- # @private
106
- def +( offset )
107
- Memory.new @data + offset
108
- end
109
-
110
- end
111
-
112
- end
@@ -1,52 +0,0 @@
1
- module Hornetseye
2
-
3
- # @private
4
- module SequenceOperation
5
-
6
- # @private
7
- def set( value = typecode.default )
8
- if value.is_a? Array
9
- for i in 0 ... num_elements
10
- assign i, i < value.size ? value[ i ] : typecode.default
11
- end
12
- else
13
- op( value ) { |x| set x }
14
- end
15
- value
16
- end
17
-
18
- # @private
19
- def get
20
- self
21
- end
22
-
23
- # @private
24
- def sel( *indices )
25
- if indices.empty?
26
- super *indices
27
- else
28
- unless ( 0 ... num_elements ).member? indices.last
29
- raise "Index must be in 0 ... #{num_elements} " +
30
- "(was #{indices.last.inspect})"
31
- end
32
- element_storage = @storage + indices.last * stride * typecode.bytesize
33
- element_type.wrap( element_storage ).sel *indices[ 0 ... -1 ]
34
- end
35
- end
36
-
37
- # @private
38
- def op( *args, &action )
39
- for i in 0 ... num_elements
40
- sub_args = args.collect do |arg|
41
- arg.is_a?( Sequence_ ) ? arg[ i ] : arg
42
- end
43
- sel( i ).op *sub_args, &action
44
- end
45
- self
46
- end
47
-
48
- end
49
-
50
- Sequence_.class_eval { include SequenceOperation }
51
-
52
- end
@@ -1,23 +0,0 @@
1
- module Hornetseye
2
-
3
- # Abstract class inherited by +Memory+ and +List+
4
- #
5
- # @see Memory
6
- # @see List
7
- #
8
- # @private
9
- # @abstract
10
- class Storage
11
-
12
- # Create storage object based on raw data or Ruby array
13
- #
14
- # @param [Malloc,Array] data Delegate object for storing the data.
15
- #
16
- # @private
17
- def initialize( data )
18
- @data = data
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,32 +0,0 @@
1
- module Hornetseye
2
-
3
- # @private
4
- module TypeOperation
5
-
6
- # @private
7
- def set( value = typecode.default )
8
- @storage.store self.class, value
9
- value
10
- end
11
-
12
- # @private
13
- def get
14
- @storage.load self.class
15
- end
16
-
17
- # @private
18
- def sel
19
- self
20
- end
21
-
22
- # @private
23
- def op( *args, &action )
24
- instance_exec *args, &action
25
- self
26
- end
27
-
28
- end
29
-
30
- Type.class_eval { include TypeOperation }
31
-
32
- end