numo-narray 0.9.0.5 → 0.9.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,6 +43,56 @@ module Numo
43
43
  reverse(0)
44
44
  end
45
45
 
46
+ # Multi-dimensional array indexing.
47
+ # Same as [] for one-dimensional NArray.
48
+ # Similar to numpy's tuple indexing, i.e., a[[1,2,..],[3,4,..]]
49
+ # (This method will be rewritten in C)
50
+ # @return [Numo::NArray] one-dimensional view of self.
51
+ # @example
52
+ # p x = Numo::DFloat.new(3,3,3).seq
53
+ # # Numo::DFloat#shape=[3,3,3]
54
+ # # [[[0, 1, 2],
55
+ # # [3, 4, 5],
56
+ # # [6, 7, 8]],
57
+ # # [[9, 10, 11],
58
+ # # [12, 13, 14],
59
+ # # [15, 16, 17]],
60
+ # # [[18, 19, 20],
61
+ # # [21, 22, 23],
62
+ # # [24, 25, 26]]]
63
+ #
64
+ # p x.at([0,1,2],[0,1,2],[-1,-2,-3])
65
+ # # Numo::DFloat(view)#shape=[3]
66
+ # # [2, 13, 24]
67
+ def at(*indices)
68
+ if indices.size != ndim
69
+ raise DimensionError, "argument length does not match dimension size"
70
+ end
71
+ idx = nil
72
+ stride = 1
73
+ (indices.size-1).downto(0) do |i|
74
+ ix = Int64.cast(indices[i])
75
+ if ix.ndim != 1
76
+ raise DimensionError, "index array is not one-dimensional"
77
+ end
78
+ ix[ix < 0] += shape[i]
79
+ if ((ix < 0) & (ix >= shape[i])).any?
80
+ raise IndexError, "index array is out of range"
81
+ end
82
+ if idx
83
+ if idx.size != ix.size
84
+ raise ShapeError, "index array sizes mismatch"
85
+ end
86
+ idx += ix * stride
87
+ stride *= shape[i]
88
+ else
89
+ idx = ix
90
+ stride = shape[i]
91
+ end
92
+ end
93
+ self[idx]
94
+ end
95
+
46
96
  # Rotate in the plane specified by axes.
47
97
  # @example
48
98
  # p a = Numo::Int32.new(2,2).seq
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-narray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.5
4
+ version: 0.9.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -225,6 +225,7 @@ files:
225
225
  - ext/numo/narray/numo/types/int64.h
226
226
  - ext/numo/narray/numo/types/int8.h
227
227
  - ext/numo/narray/numo/types/int_macro.h
228
+ - ext/numo/narray/numo/types/real_accum.h
228
229
  - ext/numo/narray/numo/types/robj_macro.h
229
230
  - ext/numo/narray/numo/types/robject.h
230
231
  - ext/numo/narray/numo/types/scomplex.h
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  version: '0'
267
268
  requirements: []
268
269
  rubyforge_project:
269
- rubygems_version: 2.6.8
270
+ rubygems_version: 2.6.11
270
271
  signing_key:
271
272
  specification_version: 4
272
273
  summary: alpha release of Numo::NArray - New NArray class library in Ruby/Numo (NUmerical