nmatrix-rowcol 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/nmatrix-rowcol.rb +1 -0
- data/lib/nmatrix/rowcol.rb +52 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adb07aba9974439bfbe03de5609355105e2473e1
|
4
|
+
data.tar.gz: c91141da6d5fa98fbe3541bb088d090ded95e20d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 211d255dad0081315ef9300f1a7068e610a43cca8a6d69cee97b2d56f6fe7337b86f33bc0784c0ea9f10edae43c5f62a856551b1a9742c852599f4a20784b89f
|
7
|
+
data.tar.gz: 03a6f15dfa550cc9631f09b0a480d1f35fcf9d8f75aae89087da08c51986b4554d04a4ef17fb5c11c985704e65a02fdd81c94db20a1b75676cfaf34726810a79
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'nmatrix/rowcol'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'nmatrix/nmatrix'
|
2
|
+
|
3
|
+
class NMatrix
|
4
|
+
|
5
|
+
alias_method :internal_row, :row
|
6
|
+
|
7
|
+
def row(row_number, get_by = :copy)
|
8
|
+
if row_numbers = get_row_or_col_index_array(row_number)
|
9
|
+
out = NMatrix.new [row_numbers.length, cols], default_value, dtype: dtype, stype: stype
|
10
|
+
|
11
|
+
row_numbers.each_with_index do |rownum, i|
|
12
|
+
out[i, 0..-1] = self[rownum, 0..-1]
|
13
|
+
end
|
14
|
+
|
15
|
+
out
|
16
|
+
else
|
17
|
+
internal_row(row_number, get_by)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :internal_column, :column
|
22
|
+
|
23
|
+
def column(col_number, get_by = :copy)
|
24
|
+
if col_numbers = get_row_or_col_index_array(col_number)
|
25
|
+
out = NMatrix.new [rows, col_numbers.length], default_value, dtype: dtype, stype: stype
|
26
|
+
|
27
|
+
col_numbers.each_with_index do |colnum, i|
|
28
|
+
out[0..-1, i] = self[0..-1, colnum]
|
29
|
+
end
|
30
|
+
|
31
|
+
out
|
32
|
+
else
|
33
|
+
internal_column(col_number, get_by)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
alias :col :column
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get_row_or_col_index_array arg
|
42
|
+
return unless arg.is_a?(Array) || arg.is_a?(NMatrix)
|
43
|
+
out = arg.to_a.flatten
|
44
|
+
out = booleans_to_indexes(out) unless out.first.is_a?(Integer)
|
45
|
+
out
|
46
|
+
end
|
47
|
+
|
48
|
+
def booleans_to_indexes row_numbers
|
49
|
+
row_numbers.map.with_index {|v, i| i if v}.compact
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nmatrix-rowcol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Geoff Buesing
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nmatrix
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: gbuesing@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/nmatrix-rowcol.rb
|
34
|
+
- lib/nmatrix/rowcol.rb
|
35
|
+
homepage: https://github.com/gbuesing/nmatrix-rowcol
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.4.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Arbitrary row/col selection for NMatrix
|
59
|
+
test_files: []
|
60
|
+
has_rdoc:
|