Skip to content

Conversation

@Li-Xiang-Ideal
Copy link
Contributor

CHANGES

@Li-Xiang-Ideal
Copy link
Contributor Author

A note on my absence and SparseArray:

I want to apologize for being silent for the past two years. Back in 2024, I underestimated the complexity of enhancing SparseArray, and honestly, my research workload became quite heavy, so I had to put open-source contributions on hold.

However, as part of my research, I’ve been working on a C++ based sparse tensor project SparseRREF during this time. Through this, I’ve gained more experience in implementing sparse tensor calculations. I remember @rocky once mentioned that "we are not experts in how to implement sparse arrays." While I'm not an expert yet, I definitely feel more confident about implementing sparse arrays now!

I can't promise a strict timeline yet, but I do plan to pick up the unfinished SparseArray work with my new experience when my schedule permits.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes issue #1690 where Map does not automatically map a function over Association values, and adds operator forms for several functional programming functions.

Changes:

  • Modified Map to detect when the expression is an Association and apply the function to values only (preserving keys in Rule elements)
  • Added operator form support for Apply, Map, MapIndexed, and MapThread using transformation rules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +182 to +184
if is_association and level.has_form("Rule", 2):
return Expression(
SymbolRule,
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The implementation only handles Rule but not RuleDelayed. Associations can contain both Rule and RuleDelayed elements (as seen in the codebase convention at mathics/builtin/list/associations.py:63, 91, 112, 153, 223, 324). The condition should be level.has_form(("Rule", "RuleDelayed"), 2) to handle both cases, and when creating the new expression, preserve the original head type using level.get_head() instead of always using SymbolRule.

Suggested change
if is_association and level.has_form("Rule", 2):
return Expression(
SymbolRule,
if is_association and level.has_form(("Rule", "RuleDelayed"), 2):
return Expression(
level.get_head(),

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

This was a good idea. We can include it in another round.

Copy link
Member

@rocky rocky left a comment

Choose a reason for hiding this comment

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

LGTM

@rocky rocky merged commit e2570e7 into master Feb 12, 2026
21 checks passed
@rocky rocky deleted the fix_map branch February 12, 2026 10:28
@rocky
Copy link
Member

rocky commented Feb 12, 2026

A note on my absence and SparseArray:

I want to apologize for being silent for the past two years.

No apology needed. This kind of thing happens a lot in open-source projects. We are grateful for any time you can devote here.

Back in 2024, I underestimated the complexity of enhancing SparseArray, and honestly, my research workload became quite heavy, so I had to put open-source contributions on hold.

However, as part of my research, I’ve been working on a C++ based sparse tensor project SparseRREF during this time. Through this, I’ve gained more experience in implementing sparse tensor calculations. I remember @rocky once mentioned that "we are not experts in how to implement sparse arrays." While I'm not an expert yet, I definitely feel more confident about implementing sparse arrays now!

Recent work by @bdlucas1 on better-performing plotting has revealed a few things.

See this discussion.

I can't promise a strict timeline yet, but I do plan to pick up the unfinished SparseArray work with my new experience when my schedule permits.

Again, no problem. This is perfectly understandable. Again, we are grateful for any time you can devote here.

@mmatera
Copy link
Contributor

mmatera commented Feb 12, 2026

A note on my absence and SparseArray:

I want to apologize for being silent for the past two years. Back in 2024, I underestimated the complexity of enhancing SparseArray, and honestly, my research workload became quite heavy, so I had to put open-source contributions on hold.

@Li-Xiang-Ideal, I also have been interested in making progress on that stuff for a much longer time, and the same happened to me, so let's keep faith.

However, as part of my research, I’ve been working on a C++ based sparse tensor project SparseRREF during this time. Through this, I’ve gained more experience in implementing sparse tensor calculations. I remember @rocky once mentioned that "we are not experts in how to implement sparse arrays." While I'm not an expert yet, I definitely feel more confident about implementing sparse arrays now!

I can't promise a strict timeline yet, but I do plan to pick up the unfinished SparseArray work with my new experience when my schedule permits.

If you want, I started this repo https://github.com/Mathics3/Mathics3-Module-sparse, to start building SparseArray functions as a separate module. I cannot promise to make many contributions there until July, but if at some point you are up for that, I can try to help you start implementing some basic Builtins there.

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.

Map does not automatically map a function over Association values

3 participants