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

WIP: positional matrix obj rep #5217

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fingolfin
Copy link
Member

The plan for this PR is to provide two incomplete representations for vector obj and matrix obj, on which many other implementations (such as the existing plist matrix obj) can be based; this is meant to reduce work for new implementation, reduce code duplication, and provide some uniformity.

Part of the work is to take constants like BDPOS and give them a better name. While doing this, I tried to reorder them, but discovered this isn't easy because their values are implicitly used in a Objectify calls (at least 70 are relevant for this). Since they also represent further code duplication, I plan to put them into a few helper functions, to reduce the number to 4 or so (one each for matrix vs. vector, and for plist rep vs. zmodnz rep). But then @ThomasBreuer pointed out the extra overhead this indirection causes... While I am not overly worried about this (in the worst case I can rewrite these as kernel functions), that made us think about the general impact of objection creation overhead for matrix obj vs. old-style matrices... So my work plan for this PR right now is this:

  1. benchmark matrix and vector creation times; add the code for this into the repo somewhere; then act on the result. The idea is to compare at least these:

    • old style
    • plistrep
    • compressed
    • other??
  2. factor out Objectify calls

  3. really switch to the new constants (possibly not reordered for now)

@fingolfin
Copy link
Member Author

I think I will rename IsPlistMatrixRep to IsRowPlistMatrixRep or so, as it currently stores its data as a list of IsPlistVectorRep row vectors. But in PR #2973 (which is essentially abandoned) I rewrote it to internally store everything as a classic plist-of-plists which made it possible to directly use kernel functions for addition, multiplication etc. which made it a lot faster; also not having extra row list objects removes a lot of overhead (both in memory use and speed). But this is a big change, and I think in retrospect it was a mistake in PR #2973 to try and rewrite the existing code to fit into that model. Which is a big part why I never finished it.

Hence the idea to rename it to IsRowPlistMatrixRep and then add a new IsPlistMatrixRep using the new ideas, written from scratch, as yet another "new" implementation of matrixobj...

Thoughts on this, anyone? @wucas @ThomasBreuer @ChrisJefferson

(Note: this won't be in this PR, I need to get that finished first; but the above notion came up precisely while digging through the code and trying to figure out how to adapt it to use IsPositionalMatrixRep)

@fingolfin fingolfin force-pushed the mh/IsPositionalMatrixObjRep branch 2 times, most recently from 309f60e to dfdeb63 Compare December 8, 2022 11:06
Copy link
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

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

The idea to provide a generic implementation of vector and matrix objects via positional objects is nice.
I have inserted a few comments.

Eventually the new representations should become documented, and then the files lib/matobjnz.g* can be changed in the same way as lib/matobjplist.g*.
(Doing this now would create conflicts with pull request #5254.)

res![VEC_DATA_POS] := ShallowCopy(v![VEC_DATA_POS]);
res := Objectify(TypeObj(v), res);

# 'ShallowCopy' MUST return a mutable object if such an object exists at all!
Copy link
Contributor

Choose a reason for hiding this comment

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

My interpretation of ShallowCopy is that it returns its argument if this is not copyable.
We could restrict the method installation to IsPositionalVectorRep and IsCopyable.
And perhaps we should add an explicit reference to IsCopyable to the documentation of ShallowCopy.

return res;
end );

# StructuralCopy works automatically
Copy link
Contributor

Choose a reason for hiding this comment

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

StructuralCopy is not an operation, so we cannot do anything for it here.

res![MAT_DATA_POS] := ShallowCopy(m![MAT_DATA_POS]);
res := Objectify(TypeObj(m), res);

# 'ShallowCopy' MUST return a mutable object if such an object exists at all!
Copy link
Contributor

Choose a reason for hiding this comment

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

see the comment about ShallowCopy for IsPositionalVectorRep


# TODO: document this
DeclareRepresentation( "IsPositionalVectorRep",
IsVectorObj and IsPositionalObjectRep
Copy link
Contributor

Choose a reason for hiding this comment

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

and IsCopyable if we adopt the idea to make this explicit


# TODO: document this
DeclareRepresentation( "IsPositionalMatrixRep",
IsMatrixObj and IsPositionalObjectRep
Copy link
Contributor

Choose a reason for hiding this comment

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

and IsCopyable if we adopt the idea to make this explicit

FIXME: actually the "generic" ShallowCopy method is wrong, as it
e.g. doesn't reset IsZero etc -- if we want to keep this, we need
something like a helper to produce a "basic" typeobj for the
given basedomain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants