Skip to content

Address built-in complex deprecation#344

Merged
9il merged 11 commits intolibmir:masterfrom
jmh530:change-complex-to-Complex
May 12, 2021
Merged

Address built-in complex deprecation#344
9il merged 11 commits intolibmir:masterfrom
jmh530:change-complex-to-Complex

Conversation

@jmh530
Copy link
Copy Markdown
Contributor

@jmh530 jmh530 commented May 2, 2021

This PR addresses the built-in complex deprecation. It currently does not pass CI because mir.math.sum. The offending line is below. In particular, hasElaborateAssign!T is true for Complex!U instead of false for the built-in types.

    static if (is(T == class) || is(T == interface) || hasElaborateAssign!T)
        static assert (summation == Summation.naive,
            "Classes, interfaces, and structures with "
            ~ "elaborate constructor support only naive summation.");

Not sure how you want to handle (either special case it or just rely on other summation techniques for Complex).

@9il
Copy link
Copy Markdown
Member

9il commented May 3, 2021

hasElaborateAssign!T && !isComplex!T may work

@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 3, 2021

@9il That works there, but it looks like I might need to look into fast, kahan, precise, and decimal to get std.complex's version working in each of those.

@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 3, 2021

And apparently kbn and kb2 too

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 3, 2021

Codecov Report

Merging #344 (4242516) into master (333701c) will decrease coverage by 0.02%.
The diff coverage is 80.95%.

❗ Current head 4242516 differs from pull request most recent head de95a5c. Consider uploading reports for the commit de95a5c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #344      +/-   ##
==========================================
- Coverage   92.13%   92.11%   -0.03%     
==========================================
  Files          63       63              
  Lines       15232    15248      +16     
==========================================
+ Hits        14034    14045      +11     
- Misses       1198     1203       +5     
Impacted Files Coverage Δ
source/mir/math/sum.d 96.07% <74.19%> (-0.34%) ⬇️
source/mir/math/stat.d 100.00% <100.00%> (ø)
source/mir/appender.d 86.27% <0.00%> (-0.27%) ⬇️
source/mir/series.d 94.12% <0.00%> (ø)
source/mir/bignum/fixed.d 94.24% <0.00%> (ø)
source/mir/bignum/low_level_view.d 93.50% <0.00%> (ø)
source/mir/serde.d 76.36% <0.00%> (+0.04%) ⬆️
source/mir/bignum/fp.d 97.79% <0.00%> (+0.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 333701c...de95a5c. Read the comment docs.

@jmh530 jmh530 changed the title WIP: Address built-in complex deprecation Address built-in complex deprecation May 3, 2021
@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 3, 2021

@9il Passing now. Rather than remove the builtin stuff, I just added support for std.complex. I figure at least until the deprecation period ends, it might make sense to maintain some of that functionality in case anyone's code depends on it. I also added a version for testing the builtin ones so that they can be skipped easily if needed.

I also added some deprecation notices for statType (though I wasn't seeing them when running dub test locally).

Comment thread source/mir/math/stat.d Outdated
} else static if (checkComplex) {
static if (is(T : cdouble)) {
alias statType = cdouble;
import std.complex: Complex;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this function be reworked with isComplex, realType, TemplateOf , and Unqual without referencing any complex types directly? Would be nice if we don't restrict a user to use Phobos complex type.

@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 10, 2021 via email

@9il
Copy link
Copy Markdown
Member

9il commented May 11, 2021

What you’re arguing is basically to convert the complex types to real, correct? I’d probably rather not do that. I’d rather just deprecate the built-in one and then drop support for complex here. The caller can always convert to real.

We can drop support of complex numbers if required right now. I mean that the function shouldn't restrict a user to use std.complex. It should work for arbitrary user-defined templates like MyComplex!T.

@jmh530 jmh530 force-pushed the change-complex-to-Complex branch from 4242516 to de95a5c Compare May 11, 2021 12:47
@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 11, 2021

@9il I made some tweaks so that it can handle any type that passes isComplex!T, but it won't handle the case where a type is implicitly convertible to a type that passes isComplex!T.

I'm getting some failures on CircleCI. The latest deals with some meson generated files that I'm not sure what's going on.

Comment thread source/mir/math/sum.d Outdated
is(F == cfloat) ||
is(F == cdouble) ||
is(F == Complex!float) ||
is(F == Complex!double) ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need to import Phobos here. It can be just isComplex!F && F.sizeof <= 16

Comment thread source/mir/math/sum.d Outdated
x = s_re + x.im * 1fi;
} else {
import std.complex: Complex;
s = Complex!float(x_re, s.im);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to import Phobos. Something like F(x_re, s.im) or T(x_re, s.im) should work.

Copy link
Copy Markdown
Member

@9il 9il May 12, 2021

Choose a reason for hiding this comment

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

The implementation shouldn't import std.complex, tests can do that

Comment thread source/mir/math/sum.d Outdated

static if (summation == Summation.pairwise)
static if (summation == Summation.pairwise) {
import std.complex: Complex;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the last one std.complex import

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jmh530 please remove this one import too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@9il Ah, sorry, fixed.

@jmh530
Copy link
Copy Markdown
Contributor Author

jmh530 commented May 12, 2021

@9il Updated.

@9il
Copy link
Copy Markdown
Member

9il commented May 12, 2021

Thank you!

@9il 9il merged commit ee774b7 into libmir:master May 12, 2021
@jmh530 jmh530 deleted the change-complex-to-Complex branch May 12, 2021 17:35
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