| Title: | Helper Functions for the XLA Ecosystem |
|---|---|
| Description: | Helper functions for the XLA ecosystem. |
| Authors: | Sebastian Fischer [aut, cre] (ORCID: <https://orcid.org/0000-0002-9609-3197>), Daniel Falbel [aut] (ORCID: <https://orcid.org/0009-0006-0143-2392>) |
| Maintainer: | Sebastian Fischer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-06-01 17:05:53 UTC |
| Source: | https://github.com/r-xla/xlamisc |
Helper functions for the XLA ecosystem.
Maintainer: Sebastian Fischer [email protected] (ORCID)
Authors:
Daniel Falbel [email protected] (ORCID)
Operates on a named list of bibentry() entries and formats them for
documentation with roxygen2.
format_bib() is intended to be called in the @references section and
formats the complete entry using tools::toRd().
cite_bib() returns a short inline citation in the format
"LastName (Year)".
format_bib(..., bibentries = NULL) cite_bib(..., bibentries = NULL)format_bib(..., bibentries = NULL) cite_bib(..., bibentries = NULL)
... |
( |
bibentries |
(named |
(character(1)).
bibentries = list(R = citation()) format_bib("R") cite_bib("R")bibentries = list(R = citation()) format_bib("R") cite_bib("R")
Get the "dimension" of an R array or vector.
get_dims(data)get_dims(data)
data |
( |
(integer())
An implementation of a least-recently-used cache built on top of utils::hashtab.
Therefore, arbitrary keys can be used, as opposed to the implementation in cachemem,
which relies on environments.
This LRU cache is implemented as a combination of a hashmap and a doubly linked list. The hashmap is used for lookups and the doubly linked list is used to maintain the ordering of most recently used to least recently used items. Whenever an element is added or accessed, it is moved to the front of the list.
capacity(integer(1))
The maximum capacity of the cache.
size(integer(1))
The number of items currently stored.
new()
Initialize a new LRU cache with a given capacity.
LRUCache$new(capacity)
capacity(integer(1))
Number of items the cache holds.
get()
Get the value for key and mark it as most-recently-used.
LRUCache$get(key, default = NULL)
key(any)
Key.
default(any)
Default value returned by get() when key is not present.
set()
Set the value for key, updating recency and evicting LRU as needed.
LRUCache$set(key, value)
key(any)
Key.
value(any)
Value
has()
Check whether a given key exists in the cache.
LRUCache$has(key)
key(any)
Key.
remove()
Remove key from the cache, returning the value if it was present or NULL otherwise.
LRUCache$remove(key)
key(any)
Key.
clear()
Clear all entries from the cache.
LRUCache$clear()
keys_mru_to_lru()
Return keys ordered from most-recently-used to least-recently-used.
LRUCache$keys_mru_to_lru()
clone()
The objects of this class are cloneable with this method.
LRUCache$clone(deep = FALSE)
deepWhether to make a deep clone.
Returns a constructor for a typed list. The constructor checks that
items is a list and runs the optional validator, but does not
iterate items to validate per-element class – this makes it cheap
enough to call from hot paths like IR construction. Trust the
caller to pass items of the right class; downstream consumers will
fail with their own (clearer) error if not.
new_list_of(class_name, item_class, validator = NULL)new_list_of(class_name, item_class, validator = NULL)
class_name |
The name of the class |
item_class |
The class of the items in the list. Documentation only – not enforced at construction. |
validator |
A validator function. Receives |
A list-of-class_name constructor.
Like seq_len and seq_along but starts at 0.
seq_len0(n) seq_along0(x)seq_len0(n) seq_along0(x)
n |
( |
x |
( |
(integer())
Formats a shape vector as a string like (2,3,4).
NA values are replaced with ?.
shapevec_repr(shape)shapevec_repr(shape)
shape |
( |
(character(1))
The formatted shape string.
Applies shapevec_repr() to multiple shapes and combines them.
shapevec_reprs(...)shapevec_reprs(...)
... |
Shape vectors to format. |
(character(1))
The formatted shapes, separated by ", ".
Remove elements from a vector by index. Also works for empty indices.
without(x, indices)without(x, indices)
x |
( |
indices |
( |
(vector)
The vector with the elements removed.