Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typegen #28

Merged
merged 92 commits into from
Apr 4, 2023
Merged

Typegen #28

merged 92 commits into from
Apr 4, 2023

Conversation

chelouche9
Copy link
Contributor

No description provided.

@chelouche9
Copy link
Contributor Author

@xenova this is only the utils.js file. It will take some time lol.
I also think we might add a prettier and linter so people won't override all file like me 😝.

src/utils.js Outdated
.map((x, i) => [i, x]) // Get indices ([index, score])
.sort((a, b) => b[1] - a[1]) // Sort by log probabilities
items = Array.from(items)
.map((x, i) => [i, x]) // Get indices ([index, score])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have the comments aligned and it might be best to focus on JSDoc only in one PR, otherwise it becomes hard to judge

src/utils.js Outdated
/**
* Creates a new instance of the Callable class.
*
* @constructor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@constructor not needed

src/utils.js Outdated
* This method should be implemented in subclasses to provide the
* functionality of the callable object.
*
* @method _call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@method _call not needed

src/utils.js Outdated
* @method _call
* @throws {Error} Must implement _call method in subclass
*/
_call(...args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args param is not in jsdoc

src/utils.js Outdated
function isIntegralNumber(x) {
return Number.isInteger(x) || typeof x === 'bigint'
return Number.isInteger(x) || typeof x === "bigint";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother replacing every ' with "?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my prettier. Forgot to disable it.

@kungfooman
Copy link
Contributor

There are a few cases of @class and @constructor which aren't needed (basically artifacts of ES5 style function-based OOP), otherwise this is looking very good 👍

I will close my PR so we don't have to mess around with two PR's. Thank you for the great work and time!

@xenova
Copy link
Owner

xenova commented Mar 21, 2023

I just resolved a conflict coming from main. Let me know when you want me to review and test fully 👍

src/tensor_utils.js Outdated Show resolved Hide resolved
@chelouche9
Copy link
Contributor Author

I just resolved a conflict coming from main. Let me know when you want me to review and test fully 👍

@xenova I have left only 3 files. Hopefully in two days.

@xenova
Copy link
Owner

xenova commented Mar 21, 2023

I just resolved a conflict coming from main. Let me know when you want me to review and test fully 👍

@xenova I have left only 3 files. Hopefully in two days.

Sweet! No rush :)

@chelouche9 chelouche9 force-pushed the typegen branch 2 times, most recently from 8679602 to e3ddccf Compare March 23, 2023 20:08
@chelouche9
Copy link
Contributor Author

chelouche9 commented Mar 23, 2023

@xenova The PR is ready, all files have JSdoc now :)

But I have to say it is far from perfect. From now we need to make incremental changes and fixes.
There are a lot of types and code adjustments to make. We can do them in small steps after it's merged.

@xenova
Copy link
Owner

xenova commented Mar 23, 2023

Nice! 🎉 I'm almost done adding a few more models/tasks to main, then I'll review, merge, and finally add any missing docs.

@biw
Copy link

biw commented Mar 23, 2023

Just a general question for you @xenova, do you prefer to keep the source in JavaScript vs. moving some things over to TypeScript?

@xenova
Copy link
Owner

xenova commented Mar 23, 2023

Just a general question for you @xenova, do you prefer to keep the source in JavaScript vs. moving some things over to TypeScript?

Not too sure 👀 ... JS has been easier (and faster) to develop in since I don't have much experience with TS.

But I'm pretty sure that eventually, the project will transition to TS.

@kungfooman
Copy link
Contributor

But I'm pretty sure that eventually, the project will transition to TS.

I hope not. TS is useful powering a language server, but actually writing TS is ugly once the types become a bit more complicated. And you lose the ability to load code directly as ES6 modules in the browser via <script type="module">.

I would urge caution with regards to those who seem overly enthusiastic about TS, as their enthusiasm is often just following "that shiny new thing", while being disconnected from pragmatism.

Simple job for you, @biw, to make things clear, translate this to TypeScript:

/**
 * @example
 * forInMap({a: 11, b: 22}, (k, v) => v); // [11, 22]
 * @param {Record<KEY, VAL>} o - The object.
 * @param {(key: string, value: VAL) => RET} lambda - The function that operates on the key/value pairs.
 * @template {string | number | symbol} KEY  - The key.
 * @template VAL - Type of the value given to `lambda`.
 * @template RET - Type of the return value of `lambda`.
 * @returns {RET[]}
 */
function forInMap(o, lambda) {
  return Object.keys(o).map(key => lambda(key, o[key]));
}

src/processors.js Outdated Show resolved Hide resolved
@kungfooman
Copy link
Contributor

@xenova The PR is ready, all files have JSdoc now :)

Great work 👍

I looked over it and src/utils.js received way more changes than necessary. I see the value of a linter, but maybe we have to keep it separate? It looks like it moved methods up and down etc.

@chelouche9
Copy link
Contributor Author

@kungfooman thanks for the feedback. The linter is turned off. I think it happened when resolving conflicts. I will have a look and fix :)

@chelouche9
Copy link
Contributor Author

@xenova just checking what is missing to merge this :)

@biw
Copy link

biw commented Mar 29, 2023

I hope not. TS is useful powering a language server, but actually writing TS is ugly once the types become a bit more complicated. And you lose the ability to load code directly as ES6 modules in the browser via <script type="module">.

Since there's already a build pipeline with webpack, this isn't an issue. 😄

I would urge caution with regards to those who seem overly enthusiastic about TS, as their enthusiasm is often just following "that shiny new thing", while being disconnected from pragmatism.

As someone who's been shipping typescript code in production for over four years, my intentions are not to chase the new shiny thing. Just trying to help out if the need is there. Not trying to force anyone to use anything 😄

Simple job for you, @biw, to make things clear, translate this to TypeScript:

/**
 * @example
 * forInMap({a: 11, b: 22}, (k, v) => v); // [11, 22]
 * @param {Record<KEY, VAL>} o - The object.
 * @param {(key: string, value: VAL) => RET} lambda - The function that operates on the key/value pairs.
 * @template {string | number | symbol} KEY  - The key.
 * @template VAL - Type of the value given to `lambda`.
 * @template RET - Type of the return value of `lambda`.
 * @returns {RET[]}
 */
function forInMap(o, lambda) {
  return Object.keys(o).map(key => lambda(key, o[key]));
}

Here you go!

function forInMap2<V, K extends Record<string | number | symbol, V>, Ret>(
  o: K,
  lambda: (key: keyof K, value: K[typeof key]) => Ret,
) {
  return Object.keys(o).map((key) => lambda(key, o[key as keyof K]))
}

Not trying to start a flame war, I just wanted to be helpful if @xenova had an interest in using TypeScript.

@xenova
Copy link
Owner

xenova commented Mar 29, 2023

@xenova just checking what is missing to merge this :)

Hi! No need to do anything on your side - I will get to fully reviewing (and merging) by the end of the week (hopefully lol).

@xenova
Copy link
Owner

xenova commented Mar 29, 2023

Not trying to start a flame war, I just wanted to be helpful if @xenova had an interest in using TypeScript.

Haha no worries! 🤣 I'm definitely open to learning new tech, so, we shall see ;) For now, as you'd expect, I'll continue developing in JS, otherwise, I'd probably not be able to keep up with all the craziness in the AI space right now 😄

@xenova
Copy link
Owner

xenova commented Apr 4, 2023

@chelouche9 I'm almost done with my pass over everything (it's taking so long haha). I tried to push, but I apparently don't have write access to your branch. Could you add me as a collaborator?

@chelouche9
Copy link
Contributor Author

@xenova now you have permissions.

@xenova
Copy link
Owner

xenova commented Apr 4, 2023

@xenova now you have permissions.

Thanks! I've pushed my changes. You and @kungfooman can do a quick skim over everything if you'd like... and then I'll merge into main 🔥

Also, I assume we have to run the build command each time before release? If so, then you're probably right that it's a good idea to remove dist from the repo. Perhaps @kungfooman can give some advice in that regard.

@chelouche9
Copy link
Contributor Author

Thanks! I've pushed my changes. You and @kungfooman can do a quick skim over everything if you'd like... and then I'll merge into main 🔥

I see you added some changes to the code except for jsdoc. For the annotation part looks good to me :)

@xenova xenova merged commit 0a77a4e into xenova:main Apr 4, 2023
@kungfooman
Copy link
Contributor

Also, I assume we have to run the build command each time before release? If so, then you're probably right that it's a good idea to remove dist from the repo. Perhaps @kungfooman can give some advice in that regard.

The only reason I like to commit build artifacts is to be able to see potential regressions, e.g. while rewriting a documentation system to keep track of the changes in the generated documentation files.

In such cases I just create a throw-away repo and commit as many files I want.

But I don't like all these artifact files in the "main repo", since I don't like large repositories. Cloning just takes longer and longer and it will probably also decrease the amount of contributors over time.

It's likely to result in merge conflicts aswell and I prefer not to spend time resolving merge conflicts in build artifacts.

I also like to use the file-search in VSCode and I don't want to put "dist" in "Exclude dirs" all the time, to filter for the SSOF (single source of truth) e.g. finding some specific types to improve.

TLDR: my suggestion is to remove /dist/ from repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants