doc/Vector.md in red_amber-0.1.6 vs doc/Vector.md in red_amber-0.1.7

- old
+ new

@@ -36,15 +36,16 @@ ### `values`, `to_a`, `entries` ### `indices`, `indexes`, `indeces` - Return indices in an Array + Return indices in an Array. ### `to_ary` - Vector has `#to_ary`. It implicitly converts a Vector to an Array when required. + It implicitly converts a Vector to an Array when required. + ```ruby [1, 2] + Vector.new([3, 4]) # => [1, 2, 3, 4] @@ -58,29 +59,25 @@ ### `boolean?`, `numeric?`, `string?`, `temporal?` ### `type_class` -### [ ] `each` (not impremented yet) +### `each` -### [ ] `chunked?` (not impremented yet) + If block is not given, returns Enumerator. -### [ ] `n_chunks` (not impremented yet) - -### [ ] `each_chunk` (not impremented yet) - ### `n_nils`, `n_nans` - `n_nulls` is an alias of `n_nils` ### `has_nil?` Returns `true` if self has any `nil`. Otherwise returns `false`. ### `inspect(limit: 80)` - - `limit` sets size limit to display long array. + - `limit` sets size limit to display a long array. ```ruby vector = RedAmber::Vector.new((1..50).to_a) # => #<RedAmber::Vector(:uint8, size=50):0x000000000000f528> @@ -165,22 +162,22 @@ #=> #<RedAmber::Vector(:double, size=6):0x000000000000f910> [1.0, NaN, -Infinity, Infinity, nil, 0.0] double.count #=> 5 -double.count(opts: {mode: :only_valid}) #=> 5, default -double.count(opts: {mode: :only_null}) #=> 1 -double.count(opts: {mode: :all}) #=> 6 +double.count(mode: :only_valid) #=> 5, default +double.count(mode: :only_null) #=> 1 +double.count(mode: :all) #=> 6 boolean = RedAmber::Vector.new([true, true, nil]) #=> #<RedAmber::Vector(:boolean, size=3):0x000000000000f924> [true, true, nil] boolean.all #=> true -boolean.all(opts: {skip_nulls: true}) #=> true -boolean.all(opts: {skip_nulls: false}) #=> false +boolean.all(skip_nulls: true) #=> true +boolean.all(skip_nulls: false) #=> false ``` ### Unary element-wise: `vector.func => vector` ![unary element-wise](doc/image/../../image/vector/unary_element_wise.png) @@ -210,10 +207,41 @@ | ✓ `sin` | | ✓ | | | | | ✓`sort_indexes`| ✓ | ✓ | ✓ |:order|alias `sort_indices`| | ✓ `tan` | | ✓ | | | | | ✓ `trunc` | | ✓ | | | | +Examples of options for `#round`; + +- `:n-digits` The number of digits to show. +- `round_mode` Specify rounding mode. + +```ruby +double = RedAmber::Vector.new([15.15, 2.5, 3.5, -4.5, -5.5]) +# => [15.15, 2.5, 3.5, -4.5, -5.5] +double.round +# => [15.0, 2.0, 4.0, -4.0, -6.0] +double.round(mode: :half_to_even) +# => Default. Same as double.round +double.round(mode: :towards_infinity) +# => [16.0, 3.0, 4.0, -5.0, -6.0] +double.round(mode: :half_up) +# => [15.0, 3.0, 4.0, -4.0, -5.0] +double.round(mode: :half_towards_zero) +# => [15.0, 2.0, 3.0, -4.0, -5.0] +double.round(mode: :half_towards_infinity) +# => [15.0, 3.0, 4.0, -5.0, -6.0] +double.round(mode: :half_to_odd) +# => [15.0, 3.0, 3.0, -5.0, -5.0] + +double.round(n_digits: 0) +# => Default. Same as double.round +double.round(n_digits: 1) +# => [15.2, 2.5, 3.5, -4.5, -5.5] +double.round(n_digits: -1) +# => [20.0, 0.0, 0.0, -0.0, -10.0] +``` + ### Binary element-wise: `vector.func(vector) => vector` ![binary element-wise](doc/image/../../image/vector/binary_element_wise.png) | Method |Boolean|Numeric|String|Options|Remarks| @@ -284,10 +312,35 @@ ### [ ] (temporal functions) ### [ ] (conditional functions) ### [ ] (index functions) ### [ ] (other functions) -## Coerce (not impremented) +## Coerce + +```ruby +vector = RedAmber::Vector.new(1,2,3) +# => +#<RedAmber::Vector(:uint8, size=3):0x00000000000decc4> +[1, 2, 3] + +# Vector's `#*` method +vector * -1 +# => +#<RedAmber::Vector(:int16, size=3):0x00000000000e3698> +[-1, -2, -3] + +# coerced calculation +-1 * vector +# => +#<RedAmber::Vector(:int16, size=3):0x00000000000ea4ac> +[-1, -2, -3] + +# `@-` operator +-vector +# => +#<RedAmber::Vector(:uint8, size=3):0x00000000000ee7b4> +[255, 254, 253] +``` ## Update vector's value ### `replace(specifier, replacer)` => vector - Accepts Scalar, Range of Integer, Vector, Array, Arrow::Array as a specifier