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

im*Matrix is much slower than real scalar*Matrix #243

Closed
ViralBShah opened this issue Oct 29, 2011 · 6 comments
Closed

im*Matrix is much slower than real scalar*Matrix #243

ViralBShah opened this issue Oct 29, 2011 · 6 comments
Assignees
Labels
performance Must go faster

Comments

@ViralBShah
Copy link
Member

Multiplying a matrix with im is 10x slower than multiplying it by a real number.

julia> @time im*ones(2000,2000);
elapsed time: 1.40052605 seconds

julia> @time 2*ones(2000,2000);
elapsed time: 0.13868904 seconds

@ghost ghost assigned JeffBezanson Oct 29, 2011
@ViralBShah
Copy link
Member Author

Does this have anything to do with global variables in the REPL or something? Since I am not creating a matrix and using it, It seems that the type inference on globals is not an issue here, especially since the real scalar*Matrix does work fast.

@JeffBezanson
Copy link
Sponsor Member

Not that it changes this issue, but as a side note we should always use complex(r,i) and not r+im*i, and encourage others to do the same.

@JeffBezanson
Copy link
Sponsor Member

Adding this definition speeds it up by more than 2x:

*(z::ImaginaryUnit, w::Real) = complex(0, w)

So that much of the time is taken just by the extra operations in complex *.

@JeffBezanson
Copy link
Sponsor Member

Ok, and all the rest of the time is taken by the integer manipulations in the complex constructor:

function complex128(r::Float64, i::Float64)
    box(Complex128,
        or_int(shl_int(zext_int(Complex128,unbox64(i)),unbox32(64)),
               zext_int(Complex128,unbox64(r))))
end

@ViralBShah
Copy link
Member Author

We are now down to 5x slower.

julia> @time im*ones(2000,2000);
elapsed time: 0.59639478 seconds

@JeffBezanson
Copy link
Sponsor Member

Subsumed by #323.

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
* Add type assertion to `Symbol` method. Fix #242

* Remove comprehension type inference test
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
* Add Base.norm, normalize and normalize! for Histogram

* Add Base.float for Histogram and support for aux_weights on normalize

* Add tests for histogram norm and normalize

* Clarify description of histogram hormalization modes

* Add histogram normalization mode :none

* Better exceptions and small coding style improvements in hist norm code

Also removed some remnant code in hist norm tests.

* Add proper docstrings for histogram norm, normalize and normalize!

* Add tests for histogram normalize! and normalize with aux weights

* Add new field isdensity to Histogram, refactor histogram code

Enables consistent and idempotent behaviour of normalization, increases
histogram filling performance.

Changes:

* New Histogram field isdensity
* Support for isdensity in constructors, etc., includes refactoring
  of ctor code (removed duplicated code).
* Refactoring of histogram fill code:
    * Removed duplicated code
    * New functions binindex and binvolume
    * Significant performance gain for push!/append!
* Support for fit(Histogram{T}, ...)
* Better structure of histograms tests with test sets

* Remove _tuple_map from Histogram implementation

Better to add this to Base.

* Simplify implementation of _multi_getindex

* Fix float(h::Histogram)

* Handle h.isdensity
* Don't copy more than necessary (as requested by A. Noack)

* Change histogram norm to directly return integral value, not it's norm.

* Extend == and show for Histogram to handle new isdensity field

* Fix normalize! for Histogram

Don't set h.isdensity to true for mode == :none

* Improve numerical precision in implementation of Histogram norm/normalize

* Use _edge_binvolume in implementation of Histogram norm/normlalize

Also add optional result-type argument to binvolume

* Change implementation of float(::Histogram), remove _float_deepcopy

* Minor code pretty-up in push!(::Histogram)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

No branches or pull requests

2 participants