File: testindexset.rb

package info (click to toggle)
ruby-narray 0.6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: ansic: 4,498; ruby: 1,329; python: 91; makefile: 7
file content (55 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'narray'

a = NArray.float(3,3).indgen!

print "a #=> "; p a

print "\na[[]] = []  # Do nothing \na #=> ";
a[[]] = []; p a

print "\na[1,1] = 0  # 1-element replace\na #=> ";
b=a.dup; b[1,1] = 0
p b

print "\na[0..-1, 1] = 0  # Range replace\na #=> ";
b=a.dup; b[0..-1, 1] = 0
p b

print "\na[1,2..0] = [100,101,102]  # Array replace\na #=> ";
b=a.dup; b[1,2..0] = [100,101,102]
p b

print "\na[0,1] = [100,101,102]  # Specifing Starting point \na #=> ";
b=a.dup; b[0,1] = [100,101,102]
p b

print "\na[1,0] = [[100],[101],[102]]  # Specifing Starting point \na #=> ";
b=a.dup; b[1,0] = [[100],[101],[102]]
p b

print "\na[true,1] = [100,101,102]  # `true' means entire range\na #=> ";
b=a.dup; b[true,1] = [100,101,102]
p b

print "\na[true,true] = [[100,101,102]] \na #=> ";
b=a.dup; b[true,true] = [[100,101,102]]
p b


print "\nFollowing will fail ...\n"

print "\na[true,1] = [[100,101,102]] \na #=> ";
b=a.dup; b[true,1] = [[100,101,102]]
p b

print "\na[true,1] = [[100],[101],[102]] \na #=> ";
b=a.dup; b[true,1] = [[100],[101],[102]]
p b

print "\na[true,true] = [100,101,102] \na #=> ";
b=a.dup; b[true,true] = [100,101,102]
p b

print "\na[1,0] = [100,101,102] \na #=> ";
b=a.dup; b[1,0] = [100,101,102]
p b