topologicpy 0.8.98__py3-none-any.whl → 0.8.99__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
topologicpy/ANN.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Aperture.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/BVH.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/CSG.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Cell.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Cluster.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Color.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Context.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/DGL.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Dictionary.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
@@ -1250,6 +1250,97 @@ class Dictionary():
1250
1250
 
1251
1251
  return Dictionary.ByMergedDictionaries(dictionaryA, dictionaryB)
1252
1252
 
1253
+
1254
+ @staticmethod
1255
+ def OneHotEncode(d, keys, categoriesByKey, silent=False):
1256
+ """
1257
+ One-hot encodes multiple categorical dictionary values in one pass. See https://en.wikipedia.org/wiki/One-hot
1258
+
1259
+ Parameters
1260
+ ----------
1261
+ d : topologic_core.Dictionary
1262
+ The input dictionary.
1263
+ keys : list
1264
+ List of dictionary keys to one-hot encode.
1265
+ categoriesByKey : dict
1266
+ A dictionary mapping each key (str) to an ordered list of categories (list).
1267
+ Example:
1268
+ {
1269
+ "room_type": ["Kitchen","Bedroom","WC"],
1270
+ "zone": ["Public","Private"]
1271
+ }
1272
+ silent : bool , optional
1273
+ If True, suppress warnings. Default is False.
1274
+
1275
+ Returns
1276
+ -------
1277
+ topologic_core.Dictionary
1278
+ A new dictionary where each original key in `keys` is removed (if present)
1279
+ and replaced with one-hot encoded keys:
1280
+ "<key>_0", "<key>_1", ...
1281
+ """
1282
+
1283
+ from topologicpy.Dictionary import Dictionary
1284
+ from topologicpy.Topology import Topology
1285
+
1286
+ if not Topology.IsInstance(d, "Dictionary"):
1287
+ if not silent:
1288
+ print("Dictionary.OneHotEncode - Error: Input is not a valid Dictionary.")
1289
+ return None
1290
+
1291
+ if keys is None:
1292
+ if not silent:
1293
+ print("Dictionary.OneHotEncode - Error: keys is None.")
1294
+ return None
1295
+
1296
+ keys = list(keys)
1297
+ if len(keys) == 0:
1298
+ return d
1299
+
1300
+ if not isinstance(categoriesByKey, dict):
1301
+ if not silent:
1302
+ print("Dictionary.OneHotEncode - Error: categoriesByKey must be a dict mapping key -> categories.")
1303
+ return None
1304
+
1305
+ # Read original dictionary once
1306
+ orig_keys = Dictionary.Keys(d)
1307
+ orig_vals = [Dictionary.ValueAtKey(d, k) for k in orig_keys]
1308
+
1309
+ # Build a quick index for deletions/updates
1310
+ orig_index = {k: i for i, k in enumerate(orig_keys)}
1311
+
1312
+ # Determine which keys to remove and capture their values
1313
+ values_by_key = {}
1314
+ for k in keys:
1315
+ if k in orig_index:
1316
+ values_by_key[k] = orig_vals[orig_index[k]]
1317
+ else:
1318
+ values_by_key[k] = None
1319
+
1320
+ # Remove requested keys (preserving order of remaining items)
1321
+ remove_set = set(keys)
1322
+ out_keys = []
1323
+ out_vals = []
1324
+ for k, v in zip(orig_keys, orig_vals):
1325
+ if k not in remove_set:
1326
+ out_keys.append(k)
1327
+ out_vals.append(v)
1328
+
1329
+ # Append one-hot encodings for each key in `keys`
1330
+ for k in keys:
1331
+ cats = categoriesByKey.get(k, None)
1332
+ if not isinstance(cats, (list, tuple)) or len(cats) == 0:
1333
+ if not silent:
1334
+ print(f"Dictionary.OneHotEncodeBatch - Warning: No categories provided for key '{k}'. Skipping.")
1335
+ continue
1336
+
1337
+ value = values_by_key.get(k, None)
1338
+ for i, cat in enumerate(cats):
1339
+ out_keys.append(f"{k}_{i}")
1340
+ out_vals.append(1 if value == cat else 0)
1341
+
1342
+ return Dictionary.ByKeysValues(out_keys, out_vals)
1343
+
1253
1344
  @staticmethod
1254
1345
  def PythonDictionary(dictionary, silent: bool = False):
1255
1346
  """
topologicpy/Edge.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under
topologicpy/Face.py CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2025
1
+ # Copyright (C) 2026
2
2
  # Wassim Jabi <wassim.jabi@gmail.com>
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify it under