-
Notifications
You must be signed in to change notification settings - Fork 209
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
Dev/depman gpufeat #517
base: master
Are you sure you want to change the base?
Dev/depman gpufeat #517
Changes from all commits
3210019
abb999e
5192f79
0d165dd
032193a
75207ce
1f539f1
219555b
8b53e6d
3380fa5
c12ed7e
ecdd72b
181abfa
703e923
5d7f750
849baae
6935a91
c1f94c2
eeaef0b
8d4c1df
37ea918
8e32e0c
1f5f243
20430e0
a3bb113
9528e4a
d170ace
6a508c4
f5812bd
976d1dd
2faf466
2c96419
ab73859
a379787
580ef32
2c35bb2
3d5aa45
260c3b7
23e4257
c6417f9
457ef7a
69e59e7
6977d67
bba6c00
533a750
20b1f16
dd23f25
3b59258
5e63074
6db86a3
42f6a75
aadc84b
edbdf37
0ec47bb
139f7f9
3223a27
c47df98
26cd5e9
e47fa35
d8f9e6d
1b9f32e
2751aa9
9896f82
64153ab
d86ef4e
c370598
a3ea5d0
30ca9ee
d0997b4
836a9f4
6646b73
cf74443
da72b63
b062d59
e0e401e
2a0a9af
05a1329
760687e
ad2c703
454331a
6e1cd20
8289d51
1573e1c
14edf7b
565e9ac
c97c204
4eb824f
070c576
1c73235
d53a306
1904df5
a9d3d9e
0dd4ed6
6007eb7
6d0cb1c
86378eb
5b36dd0
90ca97a
08de406
b236337
85e1e24
c86cb53
5d5146f
8640971
58d9810
d02d480
a39928c
cedd9ad
dcfdd9c
cc8c4d2
79045df
7bb1cc9
0e4b19d
f7e97df
0372b7c
3e7f0e0
3eff36e
fb9d37c
0ac9516
2326237
56a0e73
ca2e7bf
5fb1f28
8a6008a
9a364a7
1ad8e96
0f14d99
17beba0
5ec85fd
1386f0b
8bf48e5
69b5f3f
3bc04fa
1544927
495c031
8a41d10
26b4f94
707b404
93c4021
bef055e
bb4e67a
8241a1a
c8421ef
5a65b51
569d09f
1fb98c0
e62c8ab
773ba7d
7901010
f857d2f
ba28dd0
00b1e88
9250f44
916bf4c
f4b8ed8
ee181c2
67e4732
0504e2b
ee08701
974f800
5fe7b87
8793913
c40ad22
31e2a41
b00ab9b
462ae91
aede506
5ba3a83
ba4a398
19d7f46
b90bb8b
82d537e
58d463b
1546db1
0b7dc9f
7f72d09
f87982a
ce3f089
26f1621
0c046bb
ca7ab4a
52a1216
2d49231
f871e10
cc90767
5c66802
9103a7c
63ad9ae
b8c28aa
85f1a70
e7b8137
a771fd6
1d4723d
9db0dd4
68fd472
d10655a
5180b09
d1fe703
e9a0a68
c7a7676
9f095e1
8a67f27
23a2f91
283086c
b78fc6a
c7c715e
03f0fc3
50562b7
75ac2b0
1f13df5
0a8efbf
af5c1bc
30d64b2
167513d
66948c0
8ff98fa
5f02c49
95836a1
542416f
1cb9020
ff38bcc
4d493a9
4272d23
795e6d1
d2728e8
6cb44ab
e41ab49
ff94946
9c73438
581df16
993b9fe
a1b61ac
b57978e
2d8ca8b
e620baf
4e7c9b5
dcff47c
83f55f9
b193706
8e2999a
12914c4
db380ef
3ebea98
6faaa68
bb4b994
cb2b08a
d3684f5
f0b23f4
6d7df64
3462b97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import pandas as pd | ||
import numpy as np | ||
|
||
from inspect import getmodule | ||
import graphistry | ||
|
||
from .constants import DISTANCE, WEIGHT, BATCH | ||
|
@@ -422,7 +422,10 @@ def infer_self_graph(res, | |
assert ( | ||
emb.shape[0] == df.shape[0] | ||
), "minibatches emb and X must have same number of rows since h(df) = emb" | ||
df = df.assign(x=emb.x, y=emb.y) # add x and y to df for graphistry instance | ||
if emb.x is not None: | ||
df = df.assign(x=emb.x, y=emb.y) # add x and y to df for graphistry instance | ||
else: | ||
df = df.assign(x=emb[0], y=emb[1]) # if umap kwargs n_components > 2, take first 2 here | ||
else: # if umap has been fit, but only transforming over features, need to add x and y or breaks plot binds of res | ||
df['x'] = np.random.random(df.shape[0]) | ||
df['y'] = np.random.random(df.shape[0]) | ||
|
@@ -447,7 +450,14 @@ def infer_self_graph(res, | |
|
||
for i in range(X_new.shape[0]): | ||
diff = X_previously_fit - X_new.iloc[i, :] | ||
dist = np.linalg.norm(diff, axis=1) # Euclidean distance | ||
try: | ||
diff = np.array(diff, dtype = 'float') | ||
except TypeError: | ||
pass | ||
if 'pandas' in str(getmodule(diff)): | ||
dist = np.linalg.norm(diff, axis=1) # Euclidean distance | ||
else: | ||
dist = np.linalg.norm(diff.to_pandas(), axis=1) # Euclidean distance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, instead of try/catch, can we do value inspection? |
||
mdists.append(dist) | ||
|
||
m, std = np.mean(mdists), np.std(mdists) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lmeyerov I will back this out everywhere (not too pervasive in overhaul yet, 10 files including tests), but its pretty simple, works well, and gets rid of instances like in embed_utils where you end up using the lazy imports almost comically throughout, so i can put this into a seperate PR, only to be reunited one day far off _, torch, _, _, _, _, _, _ = lazy_embed_import_dep() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import importlib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this class benefits from a comment on its design and the problem it solves There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ex: maybe it does a fast & cached check of a package being in the path before actually importing, so there should be a testable and observable speedup? |
||
class DepManager: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move |
||
def __init__(self): | ||
self.pkgs = {} | ||
|
||
def __getattr__(self, pkg:str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead call this |
||
self._add_deps(pkg) | ||
try: | ||
return self.pkgs[pkg] | ||
except KeyError: | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of hiding the exception from the user, it's probably more informative and unsurprising to:
|
||
|
||
def _add_deps(self, pkg:str): | ||
try: | ||
pkg_val = importlib.import_module(pkg) | ||
self.pkgs[pkg] = pkg_val | ||
setattr(self, pkg, pkg_val) | ||
except: | ||
pass | ||
|
||
def import_from(self, pkg:str, name:str): | ||
try: | ||
module = __import__(pkg, fromlist=[name]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. importlib docs recommend using |
||
self.pkgs[name] = module | ||
except: | ||
pass | ||
|
||
|
||
deps = DepManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of try/catch, can we do value inspection?