@@ -3162,8 +3162,23 @@ view.TensorSidebar = class extends view.ObjectSidebar {
3162
3162
if ( value . type ) {
3163
3163
const item = new view . ValueView ( this . _view , value , '' ) ;
3164
3164
this . add ( 'type' , item ) ;
3165
- item . toggle ( ) ;
3165
+ // item.toggle();
3166
+ }
3167
+
3168
+ /*
3169
+ // TODO
3170
+ if (value.initializer) {
3171
+ const tensor = new view.Tensor(value.initializer);
3172
+ if (!tensor.empty) {
3173
+ this.addHeader('Metrics');
3174
+ const metrics = tensor.metrics;
3175
+ for (const metric of metrics) {
3176
+ const value = metric.type === 'percentage' ? `${(metric.value * 100).toFixed(1)}%` : metric.value;
3177
+ this.addProperty(metric.name, [value]);
3178
+ }
3179
+ }
3166
3180
}
3181
+ */
3167
3182
}
3168
3183
} ;
3169
3184
@@ -4119,12 +4134,31 @@ view.Tensor = class {
4119
4134
}
4120
4135
4121
4136
get metrics ( ) {
4122
- const metrics = Array . from ( this . _tensor . metrics || [ ] ) ;
4123
- const keys = new Set ( metrics . map ( ( metrics ) => metrics . name ) ) ;
4124
- if ( ! keys . has ( 'sparisity' ) ) {
4125
- // metrics.push(new view.Argument('sparisity', 0, 'float32'));
4137
+ if ( ! this . _metrics ) {
4138
+ const data = this . value ;
4139
+ this . _metrics = Array . from ( this . _tensor . metrics || [ ] ) ;
4140
+ const keys = new Set ( this . _metrics . map ( ( metrics ) => metrics . name ) ) ;
4141
+ if ( ! keys . has ( 'sparsity' ) ) {
4142
+ let zeros = 0 ;
4143
+ let parameters = 0 ;
4144
+ const stack = [ data ] ;
4145
+ while ( stack . length > 0 ) {
4146
+ const data = stack . pop ( ) ;
4147
+ if ( Array . isArray ( data ) ) {
4148
+ for ( const element of data ) {
4149
+ stack . push ( element ) ;
4150
+ }
4151
+ } else {
4152
+ zeros += data === 0 || data === 0n || data === '' ;
4153
+ parameters += 1 ;
4154
+ }
4155
+ }
4156
+ const value = parameters > 0 ? zeros / parameters : 0 ;
4157
+ const argument = new view . Argument ( 'sparsity' , value , 'percentage' ) ;
4158
+ this . _metrics . push ( argument ) ;
4159
+ }
4126
4160
}
4127
- return metrics ;
4161
+ return this . _metrics ;
4128
4162
}
4129
4163
} ;
4130
4164
0 commit comments