Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/docs/literals/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@



### to_m()

Check notice on line 168 in docs/docs/literals/array.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/array.md#L168

Expected: 1; Actual: 0; Below
> Returns `MATRIX|ERROR`

Converts a nested array (2D array) to a Matrix object.


<CodeBlockSimple input='[[1, 2], [3, 4]].to_m()

Check notice on line 174 in docs/docs/literals/array.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/array.md#L174

Element: CodeBlockSimple
' output='2x2 matrix
┌ ┐
│ 1.0 2.0 │
│ 3.0 4.0 │
└ ┘
' />


### uniq()
> Returns `ARRAY|ERROR`

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/literals/hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ true

## Literal Specific Methods

### get(INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL, INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL)
> Returns `INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL`
### get(INTEGER|STRING|BOOLEAN|ARRAY|HASH|MATRIX|FLOAT|ERROR|NIL, INTEGER|STRING|BOOLEAN|ARRAY|HASH|MATRIX|FLOAT|ERROR|NIL)
> Returns `INTEGER|STRING|BOOLEAN|ARRAY|HASH|MATRIX|FLOAT|ERROR|NIL`

Returns the value of the given key or the default

Expand Down
303 changes: 303 additions & 0 deletions docs/docs/literals/matrix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
import CodeBlockSimple from '@site/components/CodeBlockSimple'

Check notice on line 1 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L1

First line in a file should be a top-level heading

# Matrix

Check notice on line 3 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L3

Expected: [None]; Actual: # Matrix

A matrix is a 2-dimensional array of numbers used for linear algebra operations.
Matrices are created by calling the to_m() method on nested arrays.

Matrix supports mathematical operations:
- Matrix multiplication: `m1 * m2`

Check notice on line 9 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L9

Lists should be surrounded by blank lines
- Element-wise addition: `m1 + m2`
- Element-wise subtraction: `m1 - m2`

Matrix indexing:
- `m[i]` returns row i as an array

Check notice on line 14 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L14

Lists should be surrounded by blank lines
- `m[i][j]` returns the element at row i, column j
- Negative indices are supported: `m[-1]` returns the last row


Check notice on line 18 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L18

Expected: 1; Actual: 2

```js
m1 = [[1, 2], [3, 4]].to_m()
m2 = [[5, 6], [7, 8]].to_m()

result = m1 * m2
sum = m1 + m2
diff = m2 - m1

puts(result)

// should output
2x2 matrix
┌ ┐
│ 19.0 22.0 │
│ 43.0 50.0 │
└ ┘

```

## Literal Specific Methods

### col(INTEGER)

Check notice on line 41 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L41

Expected: 1; Actual: 0; Below
> Returns `ARRAY|ERROR`

Returns the specified column as an array (0-indexed).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()

Check notice on line 47 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L47

Element: CodeBlockSimple
m.col(1)
' output='[2.0, 5.0]
' />


### cols()

Check notice on line 53 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L53

Expected: 1; Actual: 0; Below
> Returns `INTEGER`

Returns the number of columns in the matrix.


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.cols()
' output='3
' />


### get(INTEGER, INTEGER)

Check notice on line 65 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L65

Expected: 1; Actual: 0; Below
> Returns `FLOAT|ERROR`

Returns the element at the specified row and column (0-indexed).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.get(0, 2)
' output='3.0
' />


### row(INTEGER)

Check notice on line 77 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L77

Expected: 1; Actual: 0; Below
> Returns `ARRAY|ERROR`

Returns the specified row as an array (0-indexed).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.row(0)
' output='[1.0, 2.0, 3.0]
' />


### rows()

Check notice on line 89 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L89

Expected: 1; Actual: 0; Below
> Returns `INTEGER`

Returns the number of rows in the matrix.


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.rows()
' output='2
' />


### set(INTEGER, INTEGER, FLOAT|INTEGER)

Check notice on line 101 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L101

Expected: 1; Actual: 0; Below
> Returns `NIL|ERROR`

Sets the element at the specified row and column (0-indexed).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.set(0, 2, 99)
m
' output='2x3 matrix
┌ ┐
│ 1.0 2.0 3.0 │
│ 4.0 5.0 6.0 │
└ ┘
nil
2x3 matrix
┌ ┐
│ 1.0 2.0 99.0 │
│ 4.0 5.0 6.0 │
└ ┘
' />


### shape()

Check notice on line 124 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L124

Expected: 1; Actual: 0; Below
> Returns `ARRAY`

Returns an array containing the dimensions [rows, cols] of the matrix.


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.shape()
' output='[2, 3]
' />


### size()

Check notice on line 136 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L136

Expected: 1; Actual: 0; Below
> Returns `INTEGER`

Returns the total number of elements in the matrix (rows * cols).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.size()
' output='6
' />


### t()

Check notice on line 148 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L148

Expected: 1; Actual: 0; Below
> Returns `MATRIX`

Alias for transpose(). Returns the transposed matrix.


<CodeBlockSimple input='m = [[1, 2], [3, 4]].to_m()

Check notice on line 154 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L154

Element: CodeBlockSimple
m.t()
' output='2x2 matrix
┌ ┐
│ 1.0 3.0 │
│ 2.0 4.0 │
└ ┘
' />


### to_a()

Check notice on line 164 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L164

Expected: 1; Actual: 0; Below
> Returns `ARRAY`

Converts the matrix back to a nested array representation.


<CodeBlockSimple input='m = [[1, 2], [3, 4]].to_m()
m.to_a()
' output='[[1.0, 2.0], [3.0, 4.0]]
' />


### transpose()

Check notice on line 176 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L176

Expected: 1; Actual: 0; Below
> Returns `MATRIX`

Returns the transposed matrix (rows and columns swapped).


<CodeBlockSimple input='m = [[1, 2, 3], [4, 5, 6]].to_m()
m.transpose()
' output='3x2 matrix
┌ ┐
│ 1.0 4.0 │
│ 2.0 5.0 │
│ 3.0 6.0 │
└ ┘
' />



## Generic Literal Methods

### methods()

Check notice on line 196 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L196

Expected: 1; Actual: 0; Below
> Returns `ARRAY`

Returns an array of all supported methods names.


<CodeBlockSimple input='"test".methods()

Check notice on line 202 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L202

Element: CodeBlockSimple
' output='["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "strip", "downcase"]

Check notice on line 203 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L203

Expected: 80; Actual: 162
' />


### to_f()

Check notice on line 207 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L207

Expected: 1; Actual: 0; Below
> Returns `FLOAT`

If possible converts an object to its float representation. If not 0.0 is returned.


<CodeBlockSimple input='1.to_f()

Check notice on line 213 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L213

Element: CodeBlockSimple
"1.4".to_f()
nil.to_f()
' output='1.0
1.4
0.0
' />


### to_i(INTEGER)

Check notice on line 222 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L222

Expected: 1; Actual: 0; Below
> Returns `INTEGER`

If possible converts an object to its integer representation. If not 0 is returned.


<CodeBlockSimple input='true.to_i()

Check notice on line 228 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L228

Element: CodeBlockSimple
false.to_i()
1234.to_i()
"4".to_i()
"10011010010"to_i(2)
"2322".to_i(8)
"0x2322".to_i()
' output='1
0
1234
4
1234
1234
1234
' />


### to_json()

Check notice on line 245 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L245

Expected: 1; Actual: 0; Below
> Returns `STRING|ERROR`

Returns the object as json notation.


<CodeBlockSimple input='a = {"test": 1234}

Check notice on line 251 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L251

Element: CodeBlockSimple
a.to_json()
' output='{"test": 1234}
"{\"test\":1234}"
' />


### to_s(INTEGER)

Check notice on line 258 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L258

Expected: 1; Actual: 0; Below
> Returns `STRING`

If possible converts an object to its string representation. If not empty string is returned.

Check notice on line 261 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L261

Expected: 80; Actual: 93


<CodeBlockSimple input='true.to_s()

Check notice on line 264 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L264

Element: CodeBlockSimple
1234.to_s()
1234.to_s(2)
1234.to_s(8)
1234.to_s(10)
"test".to_s()
1.4.to_s()
' output='"true"
"1234"
"10011010010"
"2322"
"1234"
"test"
"1.4"
' />


### type()

Check notice on line 281 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L281

Expected: 1; Actual: 0; Below
> Returns `STRING`

Returns the type of the object.


<CodeBlockSimple input='"test".type()

Check notice on line 287 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L287

Element: CodeBlockSimple
' output='"STRING"
' />


### wat()

Check notice on line 292 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L292

Expected: 1; Actual: 0; Below
> Returns `STRING`

Returns the supported methods with usage information.


<CodeBlockSimple input='true.wat()

Check notice on line 298 in docs/docs/literals/matrix.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docs/docs/literals/matrix.md#L298

Element: CodeBlockSimple
' output='"BOOLEAN supports the following methods:
to_s()"
' />


10 changes: 10 additions & 0 deletions docs/literals/array.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ methods:
[1, 2, 3]
nil
[1, 2, 3, "a"]
to_m:
description: "Converts a nested array (2D array) to a Matrix object."
input: |
[[1, 2], [3, 4]].to_m()
output: |
2x2 matrix
┌ ┐
│ 1.0 2.0 │
│ 3.0 4.0 │
└ ┘
Loading