|
| 1 | +# Classes |
| 2 | +class Matrix |
| 3 | + VERSION : String |
| 4 | + SELECTORS : {:all=>true, :diagonal=>true, :off_diagonal=>true, :lower=>true, :strict_lower=>true, :strict_upper=>true, :upper=>true} |
| 5 | + include CoercionHelper |
| 6 | + include Enumerable |
| 7 | + include ExceptionForMatrix |
| 8 | + extend ConversionHelper |
| 9 | + attr_reader rows : (Array[(Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Rational | String)?] | Array[(Integer | String)?] | Array[Integer] | Array[String?] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Integer | String)?] | Array[(Array[(Integer | String)?] | Array[Vector?] | Integer | String)?] | Array[(Array[(Integer | String)?] | Array[nil] | Integer | String)?] | Array[(Array[(Integer | String)?] | Integer | String)?] | Array[(Array[(Integer | String)?] | String)?] | Array[Array[Integer]] | Array[Array[untyped]] | String)? |
| 10 | + attr_reader column_count : (Complex | Float | Integer | Matrix | Range | Rational)? |
| 11 | + def self.[] : (*Vector) -> Matrix |
| 12 | + def self.rows : (Array[Array[Vector] | Vector], ?bool) -> Matrix |
| 13 | + def self.columns : (untyped) -> Matrix |
| 14 | + def self.build : (Integer, ?(Complex | Float | Integer | Matrix | Range | Rational)?) ?{ (Integer, Integer) -> ((Complex | Float | Matrix | Numeric | Vector)?) } -> (Enumerator[untyped] | Matrix) |
| 15 | + def self.diagonal : (*Array[Integer] | Array[untyped]) -> Matrix |
| 16 | + def self.scalar : ((Complex | Float | Integer | Matrix | Range | Rational)?, Integer) -> Matrix |
| 17 | + def self.identity : ((Complex | Float | Integer | Matrix | Range | Rational)?) -> Matrix |
| 18 | + def self.zero : (untyped, ?untyped) -> Matrix |
| 19 | + def self.row_vector : (Vector) -> Matrix |
| 20 | + def self.column_vector : (Vector) -> Matrix |
| 21 | + def self.empty : (?(Complex | Float | Integer | Matrix | Range | Rational)?, ?Integer) -> Matrix |
| 22 | + def self.vstack : (Matrix, *untyped) -> Matrix |
| 23 | + def self.hstack : (Matrix, *untyped) -> Matrix |
| 24 | + def self.combine : (*Matrix) ?{ (Array[nil]) -> untyped } -> (Enumerator[untyped] | Matrix) |
| 25 | + def combine : (*untyped) ?{ (Array[nil]) -> untyped } -> (Enumerator[untyped] | Matrix) |
| 26 | + def initialize : ((Array[(Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Rational | String)?] | Array[(Integer | String)?] | Array[Integer] | Array[String?] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Integer | String)?] | Array[(Array[(Integer | String)?] | Array[Vector?] | Integer | String)?] | Array[(Array[(Integer | String)?] | Array[nil] | Integer | String)?] | Array[(Array[(Integer | String)?] | Integer | String)?] | Array[(Array[(Integer | String)?] | String)?] | Array[Array[Integer]] | Array[Array[untyped]] | String)?, ?(Complex | Float | Integer | Matrix | Range | Rational)?) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 27 | + def new_matrix : (Array[(Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[Complex | Float | Integer | Rational] | Array[Integer] | Enumerator[untyped] | Integer | Matrix | String | Vector)?] | Array[Array[untyped]], ?(Complex | Float | Integer | Matrix | Range | Rational)?) -> Matrix |
| 28 | + def [] : (Integer?, Integer?) -> nil |
| 29 | + def []= : (untyped, untyped, untyped) -> (Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Rational | String)?] | Array[(Integer | String)?] | Array[String?] | Array[untyped] | Enumerable[untyped, untyped] | Enumerator[untyped] | Matrix | Range | Vector) |
| 30 | + def check_range : (untyped, :column | :row) -> Range? |
| 31 | + def check_int : (untyped, :column | :row) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 32 | + def set_value : ((Complex | Float | Integer | Matrix | Range | Rational)?, (Complex | Float | Integer | Matrix | Range | Rational)?, untyped) -> untyped |
| 33 | + def set_row_and_col_range : (Range, Range, untyped) -> (Enumerable[untyped, untyped] | Range) |
| 34 | + def set_row_range : (Range, (Complex | Float | Integer | Matrix | Range | Rational)?, untyped) -> (Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Rational | String)?] | Array[(Integer | String)?] | Array[String?] | Enumerator[untyped] | Matrix | Vector) |
| 35 | + def set_column_vector : (Range, (Complex | Float | Integer | Matrix | Range | Rational)?, untyped) -> untyped |
| 36 | + def set_col_range : ((Complex | Float | Integer | Matrix | Range | Rational)?, Range, untyped) -> Array[untyped] |
| 37 | + def row_count : -> Integer |
| 38 | + def row : (Integer?) -> ((Matrix | Vector)?) |
| 39 | + def column : (Integer?) -> ((Matrix | Vector)?) |
| 40 | + def collect : (?:all) ?{ (?(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) } -> (Enumerator[untyped] | Matrix) |
| 41 | + def collect! : (?:all) ?{ (?(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) } -> (Enumerator[untyped] | Matrix) |
| 42 | + def freeze : -> Matrix |
| 43 | + def each : (?:all | :off_diagonal | :strict_lower | :strict_upper) ?{ ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> untyped } -> (Enumerator[untyped] | Matrix) |
| 44 | + def each_with_index : (?:all | :strict_upper | :upper) ?{ ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?, Integer, ?Integer) -> ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector | true)?) } -> (Enumerator[untyped] | Matrix) |
| 45 | + def index : (*untyped) -> ((Enumerator[untyped] | [Integer, Integer])?) |
| 46 | + def minor : (*untyped) -> Matrix? |
| 47 | + def first_minor : (Integer?, Integer?) -> Matrix |
| 48 | + def cofactor : (Integer?, Integer?) -> ((Complex | Float | Matrix | Numeric | Vector)?) |
| 49 | + def adjugate : -> (Enumerator[untyped] | Matrix) |
| 50 | + def laplace_expansion : (?row: Integer?, ?column: nil) -> untyped |
| 51 | + def diagonal? : -> bool |
| 52 | + def empty? : -> bool |
| 53 | + def hermitian? : -> bool |
| 54 | + def lower_triangular? : -> bool |
| 55 | + def normal? : -> bool |
| 56 | + def orthogonal? : -> bool |
| 57 | + def permutation? : -> bool |
| 58 | + def real? : -> bool |
| 59 | + def regular? : -> bool |
| 60 | + def singular? : -> bool |
| 61 | + def square? : -> bool |
| 62 | + def symmetric? : -> bool |
| 63 | + def antisymmetric? : -> bool |
| 64 | + def unitary? : -> bool |
| 65 | + def upper_triangular? : -> bool |
| 66 | + def zero? : -> bool |
| 67 | + def == : ((Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Range | Rational | String | Vector)?) -> bool |
| 68 | + def eql? : (untyped) -> bool |
| 69 | + def initialize_copy : (untyped) -> Array[String]? |
| 70 | + def hash : -> Integer |
| 71 | + def * : ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Matrix | Vector)?) |
| 72 | + def + : ((Array[Vector] | Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Range | Rational | String | Vector)?) -> Matrix |
| 73 | + def - : ((Array[Vector] | Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> Matrix |
| 74 | + def / : (untyped) -> ((Matrix | Vector)?) |
| 75 | + def hadamard_product : (untyped) -> (Enumerator[untyped] | Matrix) |
| 76 | + def inverse : -> untyped |
| 77 | + def inverse_from : (untyped) -> Matrix |
| 78 | + def ** : (untyped) -> Matrix? |
| 79 | + def +@ : -> Matrix |
| 80 | + def -@ : -> (Enumerator[untyped] | Matrix) |
| 81 | + def abs : -> (Enumerator[untyped] | Matrix) |
| 82 | + def determinant : -> (Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector) |
| 83 | + def determinant_bareiss : -> Integer |
| 84 | + def determinant_e : -> (Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector) |
| 85 | + def hstack : (*untyped) -> Matrix |
| 86 | + def rank : -> Integer |
| 87 | + def rank_e : -> Integer |
| 88 | + def round : (?Integer) -> Array[untyped] |
| 89 | + def trace : -> (Complex | Float | Integer | Rational) |
| 90 | + def transpose : -> Matrix |
| 91 | + def vstack : (*untyped) -> Matrix |
| 92 | + def eigensystem : -> untyped |
| 93 | + def lup : -> untyped |
| 94 | + def conjugate : -> (Enumerator[untyped] | Matrix) |
| 95 | + def adjoint : -> Matrix |
| 96 | + def imaginary : -> (Enumerator[untyped] | Matrix) |
| 97 | + def real : -> (Enumerator[untyped] | Matrix) |
| 98 | + def rect : -> ([Enumerator[untyped] | Matrix, untyped]) |
| 99 | + def coerce : (untyped) -> [Scalar, Matrix] |
| 100 | + def row_vectors : -> (Array[(Matrix | Vector)?]) |
| 101 | + def column_vectors : -> (Array[(Matrix | Vector)?]) |
| 102 | + def to_matrix : -> Matrix |
| 103 | + def to_a : -> Array[String?] |
| 104 | + def elements_to_f : -> Array[untyped] |
| 105 | + def elements_to_i : -> Array[untyped] |
| 106 | + def elements_to_r : -> Array[untyped] |
| 107 | + def to_s : -> String |
| 108 | + def inspect : -> String |
| 109 | + |
| 110 | + module ConversionHelper |
| 111 | + def convert_to_array : ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[String?] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?, ?bool) -> ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[String?])?) |
| 112 | + end |
| 113 | + |
| 114 | + module CoercionHelper |
| 115 | + def apply_through_coercion : ((Array[Vector] | Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Numeric | Range | Rational | String)?, Symbol?) -> untyped |
| 116 | + def self.coerce_to : ((Complex | Float | Integer | Matrix | Range | Rational)?, Integer.class | Matrix.class, :to_int | :to_matrix) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 117 | + def self.coerce_to_int : ((Complex | Float | Integer | Matrix | Range | Rational)?) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 118 | + def self.coerce_to_matrix : (Matrix) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 119 | + def self.check_range : ((Complex | Float | Integer | Matrix | Range | Rational)?, (Complex | Float | Integer | Matrix | Range | Rational)?, :column | :row | :vector) -> Range |
| 120 | + def self.check_int : ((Complex | Float | Integer | Matrix | Range | Rational)?, (Complex | Float | Integer | Matrix | Range | Rational)?, :column | :index | :row) -> ((Complex | Float | Integer | Matrix | Range | Rational)?) |
| 121 | + end |
| 122 | + |
| 123 | + class Scalar < Numeric |
| 124 | + include CoercionHelper |
| 125 | + include ExceptionForMatrix |
| 126 | + @value : untyped |
| 127 | + def initialize : (untyped) -> untyped |
| 128 | + def + : (untyped) -> Scalar |
| 129 | + def - : (untyped) -> Scalar |
| 130 | + def * : (untyped) -> Scalar |
| 131 | + def / : (untyped) -> Scalar |
| 132 | + def ** : (untyped) -> Scalar |
| 133 | + end |
| 134 | +end |
| 135 | + |
| 136 | +module ExceptionForMatrix |
| 137 | + class ErrDimensionMismatch < StandardError |
| 138 | + def initialize : (?nil) -> void |
| 139 | + end |
| 140 | + |
| 141 | + class ErrNotRegular < StandardError |
| 142 | + def initialize : (?nil) -> void |
| 143 | + end |
| 144 | + |
| 145 | + class ErrOperationNotDefined < StandardError |
| 146 | + def initialize : (untyped) -> void |
| 147 | + end |
| 148 | + |
| 149 | + class ErrOperationNotImplemented < StandardError |
| 150 | + def initialize : (untyped) -> void |
| 151 | + end |
| 152 | +end |
| 153 | + |
| 154 | +class Vector |
| 155 | + include Enumerable |
| 156 | + include ExceptionForMatrix |
| 157 | + include Matrix::CoercionHelper |
| 158 | + extend Matrix::ConversionHelper |
| 159 | + attr_reader elements : (Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[String?])? |
| 160 | + def self.[] : (*(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> Vector |
| 161 | + def self.elements : (Array[(Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[String?] | Enumerator[untyped], ?bool) -> Vector |
| 162 | + def self.basis : (size: Integer, index: Integer) -> Vector |
| 163 | + def self.zero : (untyped) -> Vector |
| 164 | + def initialize : ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[String?])?) -> ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[String?])?) |
| 165 | + def [] : (Integer) -> ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) |
| 166 | + def []= : ((Complex | Float | Integer | Matrix | Range | Rational)?, (Array[Vector] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[untyped] | Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[untyped] | Complex | Float | Integer | Numeric | Rational | String)?] | Array[Array[untyped] | Complex | Float | Integer | Numeric | Rational | String] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) |
| 167 | + def set_value : ((Complex | Float | Integer | Matrix | Range | Rational)?, (Array[Vector] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[Vector] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) |
| 168 | + def set_range : (Range, (Array[Vector] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[(Array[Vector] | Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Array[untyped] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?] | Array[(Integer | String)?] | Array[Array[untyped] | Complex | Float | Integer | Numeric | Rational | String] | Array[untyped])?) |
| 169 | + def round : (?Integer) -> Array[untyped] |
| 170 | + def size : -> Integer |
| 171 | + def each : ?{ ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> untyped } -> (Enumerator[untyped] | Vector) |
| 172 | + def each2 : (untyped) ?{ ((Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?, untyped) -> (Complex | Float | Integer | Rational) } -> (Enumerator[untyped] | Vector) |
| 173 | + def collect2 : (Vector) ?{ ((Complex | Float | Integer | Matrix | Rational | String | Vector)?, (Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> (Complex | Float | Integer | Matrix | Rational | String | Vector) } -> (Array[Complex | Float | Integer | Matrix | Rational | String | Vector] | Array[untyped] | Enumerator[untyped]) |
| 174 | + def self.independent? : (*Vector) -> bool |
| 175 | + def independent? : (*untyped) -> bool |
| 176 | + def zero? : -> bool |
| 177 | + def freeze : -> Vector |
| 178 | + def initialize_copy : (untyped) -> ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?])?) |
| 179 | + def == : (Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector) -> bool |
| 180 | + def eql? : (untyped) -> bool |
| 181 | + def hash : -> Integer |
| 182 | + def * : ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Matrix | Vector)?) |
| 183 | + def + : ((Array[Vector] | Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> (Matrix | Vector) |
| 184 | + def - : ((Array[Vector] | Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> (Matrix | Vector) |
| 185 | + def / : (Float) -> Vector |
| 186 | + def +@ : -> Vector |
| 187 | + def -@ : -> (Enumerator[untyped] | Vector) |
| 188 | + def inner_product : (untyped) -> (Complex | Float | Integer | Rational) |
| 189 | + def cross_product : (*untyped) -> Vector |
| 190 | + def collect : { ((Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) -> ((Array[Vector] | Complex | Float | Integer | Matrix | Numeric | Rational | String | Vector)?) } -> (Enumerator[untyped] | Vector) |
| 191 | + def collect! : -> (Enumerator[untyped] | Vector) |
| 192 | + def magnitude : -> Float |
| 193 | + def map2 : (untyped) -> (Enumerator[untyped] | Vector) |
| 194 | + def normalize : -> Vector |
| 195 | + def angle_with : (untyped) -> (Float | Integer) |
| 196 | + def covector : -> Matrix |
| 197 | + def to_a : -> ((Array[(Array[Vector] | Complex | Enumerator[untyped] | Float | Integer | Matrix | Numeric | Rational | String | Vector)?] | Array[(Complex | Float | Integer | Matrix | Rational | String | Vector)?])?) |
| 198 | + def to_matrix : -> Matrix |
| 199 | + def elements_to_f : -> Array[untyped] |
| 200 | + def elements_to_i : -> Array[untyped] |
| 201 | + def elements_to_r : -> Array[untyped] |
| 202 | + def coerce : (untyped) -> [Matrix::Scalar, Vector] |
| 203 | + def to_s : -> String |
| 204 | + def inspect : -> String |
| 205 | + |
| 206 | + class ZeroVectorError < StandardError |
| 207 | + end |
| 208 | +end |
0 commit comments