Project

General

Profile

Actions

Feature #10445

closed

[PATCH 3/3] Extend Matrix#[]

Added by gogotanaka (Kazuki Tanaka) over 9 years ago. Updated over 3 years ago.

Status:
Rejected
Target version:
-
[ruby-core:65985]

Description

I've made patches which Matrix#[] returns new vector if either arguments is range,
and returns new matrix, if both arguments are range.

Like below.

# matrix[row, column]          -> obj        or nil
# matrix[row, col_range]       -> new_vector or nil
# matrix[row_range, column]    -> new_vector or nil
# matrix[row_range, col_range] -> new_matrix or nil

Matrix.diagonal(9, 5, -3)[1, 1]
  => 5

Matrix.diagonal(9, 5, -3)[1, 0..1]
  => Vector[0, 5]

Matrix.diagonal(9, 5, -3)[0..1, 0]
  => Vector[9, 0]

Matrix.diagonal(9, 5, -3)[0..1, 0..1]
  => Matrix[[9, 0], [0, 5]]

I'm not sure matrix[row, col_range] should return vector or matrix
But from my view, it's fine.

I'm not in a hurry. Take your time.


Files

add_test.patch (1.05 KB) add_test.patch gogotanaka (Kazuki Tanaka), 10/29/2014 08:26 AM
implement_matrix.rb.patch (1.96 KB) implement_matrix.rb.patch gogotanaka (Kazuki Tanaka), 10/29/2014 08:26 AM
update_NEWS.patch (825 Bytes) update_NEWS.patch gogotanaka (Kazuki Tanaka), 10/29/2014 08:27 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0