Skip to content

Additional QuantityArray constructions #178

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ julia> ustrip(ua"degC", 295.15u"K")
22.0
```

### Arrays
### [Arrays](@id home_arrays)

For working with an array of quantities that have the same dimensions,
you can use a `QuantityArray`:
Expand Down Expand Up @@ -364,6 +364,22 @@ julia> @btime $f.(qa) setup=(xa = randn(100000) .* u"km/s"; qa = QuantityArray(x

So we can see the `QuantityArray` version saves on both time and memory.

By default, DynamicQuantities will create a `QuantityArray` from an `AbstractArray`, similarly to how a `Quantity` is created from a scalar in the [Usage](@ref) examples:

```@repl quantity-array
using DynamicQuantities # hide

x = [0.3, 0.4, 0.5]u"km/s"

y = (42:45) * u"kg"
```

This can be overridden to produce a vector of `Quantity`s by explicitly broadcasting the unit:

```@repl quantity-array
z = [0.3, 0.4, 0.5] .* u"km/s"
```

### Unitful

DynamicQuantities allows you to convert back and forth from Unitful.jl:
Expand Down
3 changes: 3 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ the same dimension) by passing an array and a single quantity:

```julia
x = QuantityArray(randn(32), u"km/s")
# or x = randn(32)u"km/s"
```

or, by passing an array of individual quantities:
Expand Down Expand Up @@ -281,6 +282,8 @@ f_square(v) = v^2 * 1.5 - v^2
println("Applying function to y_q: ", sum(f_square.(y_q)))
```

See [Home > Arrays](@ref home_arrays) for more.

### Fill

We can also make `QuantityArray` using `fill`:
Expand Down
Loading