|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +/* eslint-disable new-cap, array-element-newline, comma-spacing */ |
| 20 | + |
| 21 | +'use strict'; |
| 22 | + |
| 23 | +var S = require( '@stdlib/slice/ctor' ); |
| 24 | +var E = require( '@stdlib/slice/multi' ); |
| 25 | +var ndzeros = require( '@stdlib/ndarray/zeros' ); |
| 26 | +var toArray = require( '@stdlib/ndarray/to-array' ); |
| 27 | +var FancyArray = require( './../lib' ); |
| 28 | + |
| 29 | +// Define an output array: |
| 30 | +var buffer = [ |
| 31 | + 1, 2, |
| 32 | + |
| 33 | + 3, 4, // 0,0,{0,1} |
| 34 | + 5, 6, // 0,1,{0,1} |
| 35 | + 7, 8, // 0,2,{0,1} |
| 36 | + |
| 37 | + 9, 10, // 1,0,{0,1} |
| 38 | + 11, 12, // 1,1,{0,1} |
| 39 | + 13, 14, // 1,2,{0,1} |
| 40 | + |
| 41 | + 15, 16, |
| 42 | + 17, 18, |
| 43 | + 19, 20 |
| 44 | +]; |
| 45 | +var shape = [ 2, 3, 2 ]; |
| 46 | +var strides = [ 6, 2, 1 ]; |
| 47 | +var offset = 2; |
| 48 | + |
| 49 | +var y = new FancyArray( 'generic', buffer, shape, strides, offset, 'row-major' ); |
| 50 | +// returns <FancyArray> |
| 51 | + |
| 52 | +// Create an alias for `undefined` for more concise slicing expressions: |
| 53 | +var _ = void 0; |
| 54 | + |
| 55 | +// Create a multi-dimensional slice: |
| 56 | +var s = E( 1, S(0,_,2), _ ); |
| 57 | +// returns <MultiSlice> |
| 58 | + |
| 59 | +// Update the first and third rows of the second matrix: |
| 60 | +y[ s ] = 100; |
| 61 | +console.log( toArray( y ) ); |
| 62 | +/* => |
| 63 | + [ |
| 64 | + [ |
| 65 | + [ 3, 4 ], |
| 66 | + [ 5, 6 ], |
| 67 | + [ 7, 8 ] |
| 68 | + ], |
| 69 | + [ |
| 70 | + [ 100, 100 ], |
| 71 | + [ 11, 12 ], |
| 72 | + [ 100, 100 ] |
| 73 | + ] |
| 74 | + ] |
| 75 | +*/ |
| 76 | + |
| 77 | +// Create a vector of zeros: |
| 78 | +var x = ndzeros( [ 2 ] ); |
| 79 | +// returns <ndarray> |
| 80 | + |
| 81 | +// Update all elements in the first matrix: |
| 82 | +y[ '0,:,:' ] = x; |
| 83 | +console.log( toArray( y ) ); |
| 84 | +/* => |
| 85 | + [ |
| 86 | + [ |
| 87 | + [ 0, 0 ], |
| 88 | + [ 0, 0 ], |
| 89 | + [ 0, 0 ] |
| 90 | + ], |
| 91 | + [ |
| 92 | + [ 100, 100 ], |
| 93 | + [ 11, 12 ], |
| 94 | + [ 100, 100 ] |
| 95 | + ] |
| 96 | + ] |
| 97 | +*/ |
0 commit comments