A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/andyferris/Indexing.jl below:

andyferris/Indexing.jl: Generalized indexing for Julia

Generalized indexing for Julia

This package defines functions for getting multiple indices out of dictionaries, tuples, etc, extending this ability beyond AbstractArray.

To acheive this, we introduce new functions and methods:

You can install Indexing via Julia's package manager:

julia> using Pkg

julia> Pkg.add("Indexing")

julia> using Indexing

julia> d = Dict(:a => "Alice", :b => "Bob", :c => "Charlie")
Dict{Symbol,String} with 3 entries:
  :a => "Alice"
  :b => "Bob"
  :c => "Charlie"

julia> getindices(d, [:a, :c]) # Preserves type/keys of index collection - an array of length 2
2-element Array{String,1}:
 "Alice"  
 "Charlie"

julia> getindices(d, (:a, :c)) # Preserves type/keys of index collection - a tuple of length 2
("Alice", "Charlie")

julia> getindices(d, Dict("Wife" => :a, "Husband" => :c)) # Preserves type/keys of index collection - a dictionary with keys "Wife" and "Husband"
Dict{String,String} with 2 entries:
  "Wife"    => "Alice"
  "Husband" => "Charlie"

Similarly, view works as a lazy version of getindices, and setindices! works by setting the same value to each specified index.

This package is a work-in-progress. To complete the package, we need to:

Perhaps these could be intergrated into future Julia syntax. One suggestion:

a[i]               --> getindex(a, i)       # scalar only
a.[inds]           --> getindices(a, inds)
a[i] = v           --> setindex!(a, v, i)   # scalar only
a.[inds] = v       --> setindices!(a, v, inds)
a[i] .= v          --> broadcast!(identity, a[i], v)
a.[inds] .= values --> broadcast!(identity, view(a, inds), values)

Note the lack of dotview and maybeview. The last two could support dot-fusion on the RHS. Also, the default for a.[inds] could potentially move to view.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4