Skip to content

Introduce AbstractZeros and AbstractOnes #299

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

Merged
merged 5 commits into from
Oct 18, 2023

Conversation

mtfishman
Copy link
Contributor

This introduces AbstactZeros and AbstractOnes as proposed in #298.

For now, it just replaces function signatures that were specialized to Zeros and Ones with AbstactZeros and AbstractOnes. I'm currently testing out what it is like to define custom AbstractZeros and AbstractOnes subtypes and have those types preserved through operations, which would require deeper changes. Perhaps that could make use of ArrayLayouts.jl.

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #299 (84300ad) into master (fef31cd) will increase coverage by 0.00%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #299   +/-   ##
=======================================
  Coverage   99.88%   99.88%           
=======================================
  Files           7        7           
  Lines         871      900   +29     
=======================================
+ Hits          870      899   +29     
  Misses          1        1           
Files Coverage Δ
src/FillArrays.jl 100.00% <100.00%> (ø)
src/fillalgebra.jl 100.00% <100.00%> (ø)
src/fillbroadcast.jl 100.00% <100.00%> (ø)
src/oneelement.jl 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mtfishman mtfishman marked this pull request as ready for review October 5, 2023 12:43
@mtfishman
Copy link
Contributor Author

mtfishman commented Oct 5, 2023

@dlfivefifty in the latest I did some minimal refactoring of the matrix multiplication, broadcasting, and kron code to factor out some functions which create the output fill array based on information about the element type and axes, which default to simple Zeros, Ones, and Fill constructor calls. It's not based on ArrayLayouts.jl as I suggested in my first comment, I realized that didn't make much sense here.

The output can be customized for new AbstractZeros and AbstractOnes subtypes by overloading functions:

mult_fill(a, b, val, ax) = Fill(val, ax)
mult_zeros(a, b, elt, ax) = Zeros{elt}(ax)
mult_ones(a, b, elt, ax) = Ones{elt}(ax)

broadcasted_fill(f, a, val, ax) = Fill(val, ax)
broadcasted_fill(f, a, b, val, ax) = Fill(val, ax)
broadcasted_zeros(f, a, elt, ax) = Zeros{elt}(ax)
broadcasted_zeros(f, a, b, elt, ax) = Zeros{elt}(ax)
broadcasted_ones(f, a, elt, ax) = Ones{elt}(ax)
broadcasted_ones(f, a, b, elt, ax) = Ones{elt}(ax)

kron_fill(a, b, val, ax) = Fill(val, ax)
kron_zeros(a, b, elt, ax) = Zeros{elt}(ax)
kron_ones(a, b, elt, ax) = Ones{elt}(ax)

on a and b. Besides that, the code logic was mostly left intact. The biggest refactor was in the matrix multiplication code, curious what you think about that part.

I definitely understand that exposing an interface that is meant to be overloaded by end users is a big commitment for a package like this, open to suggestions about that.

@dlfivefifty
Copy link
Member

The fact that the IntegrationTest's pass means this change is "safe" (or lets say "safe enough").

Remember you will likely be the only "end user" of this functionality.... so arguably its fine to add this functionality without advertising it....

I looked through and I don't think I have any comments about it but hopefully someone else will review it.

@mtfishman
Copy link
Contributor Author

Makes sense to keep this as a private interface for now.

@mtfishman
Copy link
Contributor Author

I guess this is waiting on a second review? Would be nice to get this merged so we can start using it in some code we are developing in ITensors.jl.

@dlfivefifty
Copy link
Member

Can you bump the minor version number?

@mtfishman
Copy link
Contributor Author

Can you bump the minor version number?

Done.

@dlfivefifty dlfivefifty merged commit 7036a50 into JuliaArrays:master Oct 18, 2023
@mtfishman mtfishman deleted the abstractzeros branch October 18, 2023 14:56
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.

3 participants