forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable_utils.ts
More file actions
30 lines (28 loc) · 823 Bytes
/
variable_utils.ts
File metadata and controls
30 lines (28 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @license
* Copyright 2018 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
import {LayerVariable} from '../variables';
/**
* Count the elements in an Array of LayerVariables.
*
* @param weights: The LayerVariables of which the constituent numbers are to
* be counted.
* @returns A count of the elements in all the LayerVariables
*/
export function countParamsInWeights(weights: LayerVariable[]): number {
let count = 0;
for (const weight of weights) {
if (weight.shape.length === 0) {
count += 1;
} else {
count += weight.shape.reduce((a, b) => a * b);
}
}
return count;
}