disco icon indicating copy to clipboard operation
disco copied to clipboard

Create a `weights_math` module to collect the Weights-related functionality that is scattered across the project

Open Grim-bot opened this issue 3 years ago • 5 comments

Situation:

Weights is a simple typedef. Since Weights is an array of tf.Tensor, even things as simple as adding together two compatible Weights objects are not trivial. So far, everyone has implemented whatever functionality they needed right where they needed it, leading to code duplication and time wasted as the same operation is implemented in several places and devs don't know where to search for existing implementations of the functionality they need.

Updated proposal (cf. comments):

Write a file weights_math.ts instead of a Weights class.

Proposed solution:

Turn Weights into a proper class, defined in the new file discojs/src/weights.ts. Go through the files listed below (and possibly others) to collect all the existing functionality and refactor it into methods of the Weights class.

Where to find existing implementations of functionalities for the Weights type:

  • discojs/src/serialization.ts
  • discojs/src/aggregation.ts
  • discojs/src/secret_shares.ts

Grim-bot avatar Jun 09 '22 14:06 Grim-bot

As discussed, for this it's easier (and enough) to make a file called say, weights_arithmetic.ts, and in there add these sorts of functions, e.g. sum(a: Weights, b: Weights): Weights

Nacho114 avatar Jun 10 '22 13:06 Nacho114

Agreed. What you suggest is easier because a Weights class couldn't have a [] operator, which means that we would have to go through the entire codebase and change all the lines where an object of type Weights is indexed with square brackets.

Grim-bot avatar Jun 10 '22 13:06 Grim-bot

I like your original suggestion of calling it weights_math.ts better because it's shorter. Wdyt ?

Grim-bot avatar Jun 10 '22 13:06 Grim-bot

Yeah, short is good, and it’s also clear

Nacho114 avatar Jun 10 '22 14:06 Nacho114

Agreed. What you suggest is easier because a Weights class couldn't have a [] operator, which means that we would have to go through the entire codebase and change all the lines where an object of type Weights is indexed with square brackets.

actually, it should be possible to implement an index signature for an hypothetic Weights class https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures

s314cy avatar Jun 15 '22 08:06 s314cy