Skip to content

Commit f4bd413

Browse files
committed
Update example
1 parent eca7a4e commit f4bd413

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lib/node_modules/@stdlib/strided/common/examples/addon/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ addon.node: $(addon_objects)
231231
# make run
232232
#/
233233
run: addon.node
234-
$(QUIET) $(NODE) -e "var add = require( '$(this_dir)/addon.node' ).add; var x = new Float64Array( [0, 1, 2, 3, 4] ); var y = new Float64Array( [5, 6, 7, 8, 9] ); var z = new Float64Array( x.length ); add( 5, x, 1, y, 1, z, 1 ); console.log( z );"
234+
$(QUIET) $(NODE) -e "var add = require( '$(this_dir)/addon.node' ).add; var x = new Float64Array( [ 0, 1, 2, 3, 4 ] ); var y = new Float64Array( [ 5, 6, 7, 8, 9 ] ); var z = new Float64Array( x.length ); add( 5, x, 1, y, 1, z, 1 ); console.log( z );"
235235

236236
.PHONY: run
237237

lib/node_modules/@stdlib/strided/common/examples/addon/addon.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,57 +93,59 @@ namespace addon_strided_add {
9393
return;
9494
}
9595
// Retrieve the number of elements:
96-
dims[ 0 ] = (int64_t)( info[ 0 ]->IntegerValue() );
96+
dims[ 0 ] = static_cast<int64_t>( info[ 0 ]->IntegerValue() );
9797

9898
// Retrieve the strides:
99-
strides[ 0 ] = (int64_t)( info[ 2 ]->IntegerValue() );
100-
strides[ 1 ] = (int64_t)( info[ 4 ]->IntegerValue() );
101-
strides[ 2 ] = (int64_t)( info[ 6 ]->IntegerValue() );
102-
103-
// We assume we are given typed arrays:
104-
TypedArrayContents<uint8_t> X( info[ 1 ] );
105-
TypedArrayContents<uint8_t> Y( info[ 3 ] );
106-
TypedArrayContents<uint8_t> Z( info[ 5 ] );
99+
strides[ 0 ] = static_cast<int64_t>( info[ 2 ]->IntegerValue() );
100+
strides[ 1 ] = static_cast<int64_t>( info[ 4 ]->IntegerValue() );
101+
strides[ 2 ] = static_cast<int64_t>( info[ 6 ]->IntegerValue() );
107102

108103
// Convert the strides from units of elements to units of bytes...
109104
if ( info[ 1 ]->IsFloat64Array() ) {
110-
byteLength = (uint64_t)( info[ 1 ].As<Float64Array>()->ByteLength() ); // total bytes in view
105+
len = static_cast<int64_t>( info[ 1 ].As<Float64Array>()->Length() ); // number of view elements
106+
byteLength = static_cast<int64_t>( info[ 1 ].As<Float64Array>()->ByteLength() ); // total bytes in view
111107
} else {
112108
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
109+
len = 0;
113110
byteLength = 0;
114111
}
115-
len = (uint64_t)( X.length() ); // number of view elements
116-
bytesPerElement = (uint8_t)( byteLength / len ); // should evenly divide
112+
bytesPerElement = static_cast<uint8_t>( byteLength / len ); // should evenly divide
117113
strides[ 0 ] *= bytesPerElement; // stride in units of bytes
118114

119115
if ( info[ 3 ]->IsFloat64Array() ) {
120-
byteLength = (uint64_t)( info[ 3 ].As<Float64Array>()->ByteLength() );
116+
len = static_cast<int64_t>( info[ 3 ].As<Float64Array>()->Length() );
117+
byteLength = static_cast<int64_t>( info[ 3 ].As<Float64Array>()->ByteLength() );
121118
} else {
122119
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
120+
len = 0;
123121
byteLength = 0;
124122
}
125-
len = (uint64_t)( Y.length() );
126-
bytesPerElement = (uint8_t)( byteLength / len );
123+
bytesPerElement = static_cast<uint8_t>( byteLength / len );
127124
strides[ 1 ] *= bytesPerElement;
128125

129126
if ( info[ 5 ]->IsFloat64Array() ) {
130-
byteLength = (uint64_t)( info[ 5 ].As<Float64Array>()->ByteLength() );
127+
len = static_cast<int64_t>( info[ 5 ].As<Float64Array>()->Length() );
128+
byteLength = static_cast<int64_t>( info[ 5 ].As<Float64Array>()->ByteLength() );
131129
} else {
132130
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
131+
len = 0;
133132
byteLength = 0;
134133
}
135-
len = (uint64_t)( Z.length() );
136-
bytesPerElement = (uint8_t)( byteLength / len );
134+
bytesPerElement = static_cast<uint8_t>( byteLength / len );
137135
strides[ 2 ] *= bytesPerElement;
138136

137+
// Get the underlying byte arrays:
138+
TypedArrayContents<uint8_t> X( info[ 1 ] );
139+
TypedArrayContents<uint8_t> Y( info[ 3 ] );
140+
TypedArrayContents<uint8_t> Z( info[ 5 ] );
141+
139142
// Add the arrays to our array of array pointers:
140143
arrays[ 0 ] = *X;
141144
arrays[ 1 ] = *Y;
142145
arrays[ 2 ] = *Z;
143146

144147
// Perform addition:
145-
void *f = (void *)add;
146-
stdlib_strided_dd_d( arrays, dims, strides, f );
148+
stdlib_strided_dd_d( arrays, dims, strides, (void *)add );
147149
}
148150

149151
NAN_MODULE_INIT( Init ) {

0 commit comments

Comments
 (0)