narray_miss 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1010,8 +1010,9 @@ go back to ((<Index>))
1010
1010
  return (({NArray})) as data.
1011
1011
  --- NArrayMiss#get_array
1012
1012
  return (({NArray})) as data.
1013
- --- NArrayMiss#valid?
1014
- return (({Array})) whose elements are true or false corresponding to valid or invalid of elements, respectively.
1013
+ --- NArrayMiss#valid?(index)
1014
+ return (({Array})) whose elements are true or false,
1015
+ or (({True}))/(({False})) corresponding to validity of the specified element(s) by the ((|index|))
1015
1016
  --- NArrayMiss#all_valid?
1016
1017
  return true if all elements are valid, else false.
1017
1018
  --- NArrayMiss#none_valid?
@@ -1090,16 +1091,23 @@ go back to ((<Index>))
1090
1091
  @array.dup
1091
1092
  end
1092
1093
 
1093
- def valid?
1094
- where = self.get_mask!.where2
1095
- tf = Array.new(self.total)
1096
- for i in where[0]
1097
- tf[i] = true
1098
- end
1099
- for i in where[1]
1100
- tf[i] = false
1094
+ def valid?(*arg)
1095
+ if arg.any?
1096
+ # For the subset specified by the argument(s) (in the same way as for []).
1097
+ # Returns true or false if a single value is specified.
1098
+ # Otherwise, returns an Array of true of false
1099
+ mask = @mask[*arg]
1100
+ if mask.is_a?(Numeric)
1101
+ return mask == 1 # true if mask (==1); false if not
1102
+ end
1103
+ else
1104
+ # no argument
1105
+ mask = @mask
1101
1106
  end
1102
- tf
1107
+ ary = mask.to_a
1108
+ ary.flatten!
1109
+ ary.map!{|i| i==1} # true if element == 1; false if not
1110
+ return ary
1103
1111
  end
1104
1112
  def all_valid?
1105
1113
  @mask.all?
@@ -1,3 +1,3 @@
1
1
  class NArrayMiss
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -34,6 +34,15 @@ NArrayMiss.dfloat(4,4):
34
34
  =end
35
35
  end
36
36
 
37
+ def test_valid?
38
+ assert_equal([true,true,true,true,false,true,true,true,false,false,false,true,false,false,false,false], @int.valid?)
39
+ assert_equal([true,true,true,true], @int.valid?(true,0))
40
+ assert_equal([false,true,true,true], @int.valid?(true,1))
41
+ assert_equal([true,true,true,false], @int.valid?(3,true))
42
+ assert_equal(true, @int.valid?[7])
43
+ assert_equal(false, @int.valid?[10])
44
+ end
45
+
37
46
  def test_add
38
47
  ary = NArrayMiss.float(@n,@n)
39
48
  ary[true,0] = [0, 2, 4, 6]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: narray_miss
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seiya Nishizawa
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-01 00:00:00 Z
18
+ date: 2011-12-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: narray
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements: []
80
80
 
81
81
  rubyforge_project: narray_miss
82
- rubygems_version: 1.8.10
82
+ rubygems_version: 1.8.11
83
83
  signing_key:
84
84
  specification_version: 3
85
85
  summary: Additional class with processing of missing value to NArray