sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 450 forks source link

RealSet: Add option cache=False #34278

Open mkoeppe opened 2 years ago

mkoeppe commented 2 years ago

When receiving cache=False, this would use an implementation class that does not inherit from UniqueRepresentation to avoid persistence in memory.

Depends on #34277 Depends on #32181

CC: @yuan-zhou @tscrim

Component: basic arithmetic

Branch/Commit: u/mkoeppe/realset__add_option_cache_false @ d25aaac

Issue created by migration from https://trac.sagemath.org/ticket/34278

mkoeppe commented 2 years ago

Branch: u/mkoeppe/realset__add_option_cache_false

mkoeppe commented 2 years ago
comment:2

here's a beginning (untested)


Last 10 new commits:

ebd3b77Better pygments style
73e5aa3Make white logo transparent to match with furo
523b49aMerge branch 'u/klee/34252' of git://trac.sagemath.org/sage into t/32181/realset__faster_operations_by_scan_line__merging__techniques
a864fdcfix typo
3f6a0acrevive RealSet.normalize
79f2014revise the docstring of RealSet.is_connected
1ef7dd1remove unnecessary bool()
a856e5dMerge #32181
6998c22Merge #34277
cf5d8f1src/sage/sets/real_set.py (RealSet_base): New, not UniqueRepresentation
mkoeppe commented 2 years ago

Commit: cf5d8f1

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c97b9f7change RealSet(...) constructor to self.__class__(...)
42f4dd6Use self.__class__.__base__ in methods when constructing a new RealSet
6cf8c27Merge #34277
6ed8f48src/sage/sets/real_set.py (RealSet_base): New, not UniqueRepresentation
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from cf5d8f1 to 6ed8f48

mkoeppe commented 2 years ago
comment:4

Rebased on new version of #34277

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 6ed8f48 to 9085e2e

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

9085e2esrc/sage/sets/real_set.py: Use self.METHOD, cls.METHOD instead of RealSet.METHOD; use super()
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 9085e2e to 2c87c44

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

2c87c44src/sage/sets/real_set.py: Make normalize a @classmethod
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 2c87c44 to d6dd265

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

d6dd265src/sage/sets/real_set.py (RealSet_base.__init__): Check normalized
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from d6dd265 to 9f3d0f6

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

56c21b8src/sage/sets/real_set.py: Use self.METHOD, cls.METHOD instead of RealSet.METHOD; use super() (fixup)
9f3d0f6src/sage/sets/real_set.py (RealSet): Fix MRO
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

d25aaacWIP cache=False
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 9f3d0f6 to d25aaac

tscrim commented 2 years ago
comment:10

Can you give some more explanation why you want to do this? While this should not be an issue with coercion (equal-but-not-identical-parents are often a source of frustration there), it increases the overall code complexity.

mkoeppe commented 2 years ago
comment:11

When algorithms create lots of RealSets as intermediate objects, we don't want them to persist in memory for the remainder of the session

mkoeppe commented 2 years ago
comment:12

But now I realize the premise is wrong - CachedRepresentation/UniqueRepresentation use WeakCachedFunction, so it does not actually pin the objects into memory

tscrim commented 2 years ago
comment:13

Indeed, it is a weak cache. However, if this needs to be done in a tight loop, the extra overhead of checking and maintaining the cache might matter. To the profiler!