Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a3a6fb

Browse files
committed
Auto-generated commit
1 parent473e1fa commit6a3a6fb

File tree

7 files changed

+77
-144
lines changed

7 files changed

+77
-144
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<sectionclass="release"id="unreleased">
66

7-
##Unreleased (2025-09-18)
7+
##Unreleased (2025-09-19)
88

99
<sectionclass="bug-fixes">
1010

@@ -22,6 +22,7 @@
2222

2323
<details>
2424

25+
-[`29bbe63`](https://github.com/stdlib-js/stdlib/commit/29bbe6352ed375283da50d7363cc537b72736765) -**refactor:** allow non-string dtypes and delegate to`ndarray/base/assign` for copying ndarray views_(by Athan Reines)_
2526
-[`ab2e77b`](https://github.com/stdlib-js/stdlib/commit/ab2e77bb82f0c6e7854e3279429a1ec8c6ff5603) -**docs:** update type_(by Athan Reines)_
2627
-[`c4cc264`](https://github.com/stdlib-js/stdlib/commit/c4cc264996ce9f4241476c857c4c985fb6612c84) -**docs:** update markup_(by Athan Reines)_
2728
-[`77867ac`](https://github.com/stdlib-js/stdlib/commit/77867ac1767a186023f633dea30ddf860962aaed) -**docs:** remove trailing whitespace_(by Philipp Burckhardt)_

‎dist/index.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎dist/index.js.map‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎lib/cast_buffer.js‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
// MODULES //
2222

23+
varisEqualDataType=require('@stdlib/ndarray-base-assert-is-equal-data-type');
2324
varbufferCtors=require('@stdlib/ndarray-base-buffer-ctors');
2425
varallocUnsafe=require('@stdlib/buffer-alloc-unsafe');
26+
varresolveGetter=require('@stdlib/array-base-resolve-getter');
27+
varresolveSetter=require('@stdlib/array-base-resolve-setter');
2528

2629

2730
// MAIN //
@@ -32,34 +35,40 @@ var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );
3235
*@private
3336
*@param {(Array|TypedArray|Buffer)} buffer - input buffer
3437
*@param {NonNegativeInteger} len - number of elements to cast
35-
*@param {string} dtype - data type
38+
*@param {*} dtype - data type
3639
*@returns {(Array|TypedArray|Buffer)} output buffer
3740
*
3841
*@example
3942
* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' );
4043
* // returns <Float64Array>[ 1.0, 2.0, 3.0 ]
4144
*/
4245
functioncastBuffer(buffer,len,dtype){
46+
varbget;
47+
varoset;
4348
varctor;
4449
varout;
4550
vari;
4651

47-
ctor=bufferCtors(dtype);
48-
if(dtype==='generic'){
52+
bget=resolveGetter(buffer);
53+
if(isEqualDataType(dtype,'generic')){
4954
out=[];
5055
for(i=0;i<len;i++){
51-
out.push(buffer[i]);
56+
out.push(bget(buffer,i));
5257
}
53-
}elseif(dtype==='binary'){
58+
returnout;
59+
}
60+
if(isEqualDataType(dtype,'binary')){
5461
out=allocUnsafe(len);
5562
for(i=0;i<len;i++){
56-
out[i]=buffer[i];
57-
}
58-
}else{
59-
out=newctor(len);
60-
for(i=0;i<len;i++){
61-
out[i]=buffer[i];// TODO: wrap and use accessors here and above
63+
out[i]=bget(buffer,i);
6264
}
65+
returnout;
66+
}
67+
ctor=bufferCtors(dtype);
68+
out=newctor(len);
69+
oset=resolveSetter(out);
70+
for(i=0;i<len;i++){
71+
oset(out,i,bget(buffer,i));
6372
}
6473
returnout;
6574
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp