Skip to content

npzwrite with a numpy-like signature#41

Merged
fhs merged 4 commits into
fhs:masterfrom
jishnub:npzwritekwargs
Nov 16, 2020
Merged

npzwrite with a numpy-like signature#41
fhs merged 4 commits into
fhs:masterfrom
jishnub:npzwritekwargs

Conversation

@jishnub

@jishnub jishnub commented Nov 14, 2020

Copy link
Copy Markdown
Contributor

This PR adds a method to npzwrite that follows the signature of np.savez, so now this is allowed

julia> npzwrite("temp.npz", 3, 45, x = ones(3), y = zeros(2,2))

julia> npzread("temp.npz")
Dict{String,Any} with 4 entries:
  "arr_1" => 45
  "arr_0" => 3
  "x"     => [1.0, 1.0, 1.0]
  "y"     => [0.0 0.0; 0.0 0.0]

@codecov-io

codecov-io commented Nov 14, 2020

Copy link
Copy Markdown

Codecov Report

Merging #41 (8f31d4a) into master (a714e9d) will increase coverage by 0.01%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   85.27%   85.29%   +0.01%     
==========================================
  Files           1        1              
  Lines         163      170       +7     
==========================================
+ Hits          139      145       +6     
- Misses         24       25       +1     
Impacted Files Coverage Δ
src/NPZ.jl 85.29% <91.66%> (+0.01%) ⬆️

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 a714e9d...8f31d4a. Read the comment docs.

@jishnub

jishnub commented Nov 15, 2020

Copy link
Copy Markdown
Contributor Author

7aef79a reduces allocations in writing arrays by avoiding a copy.

On master:

julia> a = zeros(1_000, 1_000)

julia> @btime npzwrite("temp.npz", $a);
  808.917 ms (33 allocations: 7.63 MiB)

after this PR:

julia> @btime npzwrite("temp.npz", $a);
  808.263 ms (31 allocations: 1.64 KiB)

This might be useful in working with large arrays.

@jishnub jishnub changed the title npzwrite with numpy-like signature npzwrite with a numpy-like signature Nov 15, 2020

@fhs fhs left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@fhs fhs merged commit 9a66947 into fhs:master Nov 16, 2020
@jishnub jishnub deleted the npzwritekwargs branch November 16, 2020 14:19
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