# \#structarrays

**URL:** https://discourse.julialang.org/tag/structarrays/1054.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [StructArray into KeyedArray](https://discourse.julialang.org/t/structarray-into-keyedarray/123305)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 6\
**Last updated:** [December 1, 2024, 7:41pm UTC](https://discourse.julialang.org/t/structarray-into-keyedarray/123305 "2024-12-01T19:41:09Z")

</div>

How do I turn a StructArray into a KeyedArray? ┌───────┬───────┬───────────┬──────────┬──────────┐ │ a │ b │ x │ y │ z │ │ Int64 │ Int64 │ Float64 │ Float64 │ Float64 │ ├───────┼───────…

---

## [StructArrays and ModellingToolkit](https://discourse.julialang.org/t/structarrays-and-modellingtoolkit/123253)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 12\
**Last updated:** [November 30, 2024, 8:50am UTC](https://discourse.julialang.org/t/structarrays-and-modellingtoolkit/123253 "2024-11-30T08:50:50Z")

</div>

StructArrays 0.6.18 works fine with the newest version of ModelingToolkit, but StructArrays 0.6.20 works only with a very old version of MTK. I find this counter-intuitive. Any idea why this is the case?

---

## [Narrow StructArray column types](https://discourse.julialang.org/t/narrow-structarray-column-types/118041)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 2\
**Last updated:** [August 11, 2024, 5:24pm UTC](https://discourse.julialang.org/t/narrow-structarray-column-types/118041 "2024-08-11T17:24:51Z")

</div>

I want to narrow these column types. I can do it one at a time manually but maybe there’s a better way. identity.(\_) didn’t work. julia\> StructArray(a=Vector{Any}(rand(5)), b=Vector{Any}(rand(5)) ) 5-element StructArray…

---

## [StructArrays and custom data layout](https://discourse.julialang.org/t/structarrays-and-custom-data-layout/34910)

<div class="topic-metadata">

**Author:** [@Kruxigt](https://discourse.julialang.org/u/Kruxigt)\
**Replies:** 0\
**Last updated:** [February 20, 2020, 3:33pm UTC](https://discourse.julialang.org/t/structarrays-and-custom-data-layout/34910 "2020-02-20T15:33:53Z")

</div>

Hello fine fellows! I’m trying to use StructArrays for a custom data layout. Basically, I would like the following to produce a StructArray that includes the parameters field: using StructArrays struct MyStruct data…

---

## [Select columns from StructArray](https://discourse.julialang.org/t/select-columns-from-structarray/117214)

<div class="topic-metadata">

**Author:** [@jar1](https://discourse.julialang.org/u/jar1)\
**Replies:** 2\
**Last updated:** [July 19, 2024, 6:46am UTC](https://discourse.julialang.org/t/select-columns-from-structarray/117214 "2024-07-19T06:46:31Z")

</div>

How can I choose columns from a StructArray? julia\> StructArray(a=\[1,2\], b=\[10,20\], c=\[100, 200\])\[(:a,:b)\] ERROR: ArgumentError: invalid index: (:a, :b) of type Tuple{Symbol, Symbol}

---

## [Sorting a StructArray variable faster and how to update values?](https://discourse.julialang.org/t/sorting-a-structarray-variable-faster-and-how-to-update-values/112621)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 6\
**Last updated:** [April 7, 2024, 1:06pm UTC](https://discourse.julialang.org/t/sorting-a-structarray-variable-faster-and-how-to-update-values/112621 "2024-04-07T13:06:16Z")

</div>

Hello! I have a runnable MWE here, put into a small module to easily redefine struct as needed: module ParticleSorting export sort\_particles\_by\_density using StructArrays using StaticArrays using BenchmarkTools using…

---

## [How to build typed StructArrays from NTuples](https://discourse.julialang.org/t/how-to-build-typed-structarrays-from-ntuples/112023)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 0\
**Last updated:** [March 23, 2024, 4:34pm UTC](https://discourse.julialang.org/t/how-to-build-typed-structarrays-from-ntuples/112023 "2024-03-23T16:34:52Z")

</div>

In the documentation of StructArrays, the Advanced techniques · StructArrays section describes how custom structs could be passed to a StructArray constructor by overloading component, createinstance and staticschema. H…

---

## [Filling a StructArray in a type-stable manner](https://discourse.julialang.org/t/filling-a-structarray-in-a-type-stable-manner/111319)

<div class="topic-metadata">

**Author:** [@peremato](https://discourse.julialang.org/u/peremato)\
**Replies:** 3\
**Last updated:** [March 7, 2024, 8:05pm UTC](https://discourse.julialang.org/t/filling-a-structarray-in-a-type-stable-manner/111319 "2024-03-07T20:05:11Z")

</div>

I am trying to create StructArray’s reading from a ROOT file with the UnROOT.jl package, which provides a NamedTuple interface, in a type-stable manner. The following code illustrates the problem: using StructArrays usi…

---

## [Access StaticArray fields in a StructArray](https://discourse.julialang.org/t/access-staticarray-fields-in-a-structarray/110249)

<div class="topic-metadata">

**Author:** [@sijo](https://discourse.julialang.org/u/sijo)\
**Replies:** 6\
**Last updated:** [February 16, 2024, 8:35am UTC](https://discourse.julialang.org/t/access-staticarray-fields-in-a-structarray/110249 "2024-02-16T08:35:05Z")

</div>

StaticArrays defines properties x, y, z on SVector{3}: using StaticArrays v = SA\[1,2,3\] v.x # returns 1 However these accessors don’t work on StructArrays: using StructArrays A = StructArray(\[v, 2v\]) A.x # gives ERR…

---

## [.. broadcast object property](https://discourse.julialang.org/t/broadcast-object-property/47104)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 41\
**Last updated:** [February 15, 2024, 8:21am UTC](https://discourse.julialang.org/t/broadcast-object-property/47104 "2024-02-15T08:21:52Z")

</div>

A few years back I requested … be used to broadcast object property over array of objects. If A.x is property x of object A. Then Array\_of\_A…x is an array of the x properties of the A objects. Was told … was al…

---

## [Reinterpreting vectors into vector of SVectors?](https://discourse.julialang.org/t/reinterpreting-vectors-into-vector-of-svectors/109864)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 5\
**Last updated:** [February 7, 2024, 1:04pm UTC](https://discourse.julialang.org/t/reinterpreting-vectors-into-vector-of-svectors/109864 "2024-02-07T13:04:59Z")

</div>

Hello! Suppose I have three vectors: N = 100 x = rand(N) y = rand(N) z = rand(N) Is there any way in which I can reinterpret this into a vector of svector without having to perform allocations? Kind regards

---

## [Using LoopVectorization with StructArrays](https://discourse.julialang.org/t/using-loopvectorization-with-structarrays/98154)

<div class="topic-metadata">

**Author:** [@DylanMMarques](https://discourse.julialang.org/u/DylanMMarques)\
**Replies:** 3\
**Last updated:** [May 6, 2023, 11:47am UTC](https://discourse.julialang.org/t/using-loopvectorization-with-structarrays/98154 "2023-05-06T11:47:21Z")

</div>

Hello, I am using LoopVectorization combined with StructArrays to vectorize some code that used structures. I have created a simple example of what I am trying to achive using the struct Point2D. using StructArrays, Lo…

---

## [Functions with static table-like inputs and outputs](https://discourse.julialang.org/t/functions-with-static-table-like-inputs-and-outputs/97471)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 5\
**Last updated:** [April 15, 2023, 10:09am UTC](https://discourse.julialang.org/t/functions-with-static-table-like-inputs-and-outputs/97471 "2023-04-15T10:09:13Z")

</div>

I often have to write functions that recalculate some arrays of structures (sorted by one of the fields) into other arrays of structures. I often had to do conversions from one array of structures into another to fit arg…

---

## [New to Julia and Formatting StructArrays for GPU use with mutable scalars](https://discourse.julialang.org/t/new-to-julia-and-formatting-structarrays-for-gpu-use-with-mutable-scalars/94243)

<div class="topic-metadata">

**Author:** [@David\_A](https://discourse.julialang.org/u/David_A)\
**Replies:** 2\
**Last updated:** [February 13, 2023, 11:30pm UTC](https://discourse.julialang.org/t/new-to-julia-and-formatting-structarrays-for-gpu-use-with-mutable-scalars/94243 "2023-02-13T23:30:46Z")

</div>

First, I apologize if the long rambling post is not in keeping with expectations here and would like to preemptively thank anyone with the patience to read part or all of this and provide any feedback/guidance. Backgrou…

---

## [\`rrule\` for \`StructArrays\`](https://discourse.julialang.org/t/rrule-for-structarrays/93820)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 1\
**Last updated:** [January 31, 2023, 3:07pm UTC](https://discourse.julialang.org/t/rrule-for-structarrays/93820 "2023-01-31T15:07:50Z")

</div>

Hi! I am trying to write the correct rrule for StructArray. However I struggle quite a lot with some of the errors returned by test\_rrule. Here is what I got so far: ProjectTo(::StructArray{T}) where {T} = ProjectTo{S…

---

## [How do you get all the first elements of a tuple in a struct array?](https://discourse.julialang.org/t/how-do-you-get-all-the-first-elements-of-a-tuple-in-a-struct-array/89897)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 4\
**Last updated:** [November 8, 2022, 9:51am UTC](https://discourse.julialang.org/t/how-do-you-get-all-the-first-elements-of-a-tuple-in-a-struct-array/89897 "2022-11-08T09:51:24Z")

</div>

adata = collect(1:10) bdata = collect(31:40) tmp2=StructArray((adata,bdata)) How can I get the numbers 1:10 as if they were an array from the StructArray?

---

## [Understanding type instability related to StructArrays](https://discourse.julialang.org/t/understanding-type-instability-related-to-structarrays/89413)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 1\
**Last updated:** [October 28, 2022, 1:39am UTC](https://discourse.julialang.org/t/understanding-type-instability-related-to-structarrays/89413 "2022-10-28T01:39:41Z")

</div>

A minimun example in REPL: julia\> using StructArrays julia\> mutable struct Foo foo::Int end julia\> mutable struct Bar bar::StructArray{Foo} end julia\> bar = Bar(StructArray(\[Foo(1)…

---

## [Want to contiguously access underlying data of a struct array where the struct is a pair of static arrays](https://discourse.julialang.org/t/want-to-contiguously-access-underlying-data-of-a-struct-array-where-the-struct-is-a-pair-of-static-arrays/89012)

<div class="topic-metadata">

**Author:** [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Replies:** 0\
**Last updated:** [October 20, 2022, 2:25pm UTC](https://discourse.julialang.org/t/want-to-contiguously-access-underlying-data-of-a-struct-array-where-the-struct-is-a-pair-of-static-arrays/89012 "2022-10-20T14:25:03Z")

</div>

using StaticArrays, TensorCast const Point2d{T \<: AbstractFloat} = SVector{2,T} struct PointCspond{T \<: AbstractFloat} first::Point2d{T} second::Point2d{T} end function point\_csponds(u₁,u₂) @cast u₁\[j\]{i:2…

---

## [Difference between StructArrays and TypedTables](https://discourse.julialang.org/t/difference-between-structarrays-and-typedtables/82207)

<div class="topic-metadata">

**Author:** [@lewis](https://discourse.julialang.org/u/lewis)\
**Replies:** 4\
**Last updated:** [June 5, 2022, 5:29pm UTC](https://discourse.julialang.org/t/difference-between-structarrays-and-typedtables/82207 "2022-06-05T17:29:35Z")

</div>

Curious if anyone sees any major differences in practical usage for these packages. StructArrays can use struct of arrays or array of structs approach. TypedTables uses namedtuple of arrays and constructs the array of …

---

## [Add a property to a StructArray](https://discourse.julialang.org/t/add-a-property-to-a-structarray/74450)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 7\
**Last updated:** [June 5, 2022, 2:01pm UTC](https://discourse.julialang.org/t/add-a-property-to-a-structarray/74450 "2022-06-05T14:01:49Z")

</div>

Is it possible to add a property to a StructArray? The following code fails: julia\> using KiteUtils, StructArrays julia\> syslog=demo\_syslog(7) julia\> function Base.getproperty(st::StructArray{SysState}, sym::Symbol) …

---

## [Swapping components of structure "nominally"](https://discourse.julialang.org/t/swapping-components-of-structure-nominally/78768)

<div class="topic-metadata">

**Author:** [@jinml](https://discourse.julialang.org/u/jinml)\
**Replies:** 1\
**Last updated:** [March 30, 2022, 11:58pm UTC](https://discourse.julialang.org/t/swapping-components-of-structure-nominally/78768 "2022-03-30T23:58:13Z")

</div>

I defined the following struture struct AB{T} A::T B::T end with two components of the same numerical type. Sometimes I need to swap the two such that A=-B and B=A. Is there a way to avoid actual swapping the value an…

---

## [StructArrays (for Complex arrays) and DifferentialEquations not working together](https://discourse.julialang.org/t/structarrays-for-complex-arrays-and-differentialequations-not-working-together/78274)

<div class="topic-metadata">

**Author:** [@Elyco](https://discourse.julialang.org/u/Elyco)\
**Replies:** 4\
**Last updated:** [March 22, 2022, 7:12pm UTC](https://discourse.julialang.org/t/structarrays-for-complex-arrays-and-differentialequations-not-working-together/78274 "2022-03-22T19:12:01Z")

</div>

Hi everyone, I’m trying to solve some differential equations. But I can’t make it works together with StructArrays.jl :frowning: From the stacktrace I understand that when the differential equation package tries to se…

---

## [Converting a vector of static arrays](https://discourse.julialang.org/t/converting-a-vector-of-static-arrays/74448)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [January 12, 2022, 12:49am UTC](https://discourse.julialang.org/t/converting-a-vector-of-static-arrays/74448 "2022-01-12T00:49:00Z")

</div>

I have the following data structure: using KiteUtils syslog=demo\_syslog(7) syslog.Z Output: 201-element Vector{StaticArrays.MVector{7, Float32}}: \[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0\] \[0.0, 0.0007690057, 0.0030974336,…

---

## [StructArrays Memory Layout](https://discourse.julialang.org/t/structarrays-memory-layout/65105)

<div class="topic-metadata">

**Author:** [@mdtisdall](https://discourse.julialang.org/u/mdtisdall)\
**Replies:** 14\
**Last updated:** [July 29, 2021, 6:22pm UTC](https://discourse.julialang.org/t/structarrays-memory-layout/65105 "2021-07-29T18:22:44Z")

</div>

I’m trying to understand the memory layout of a StructArray I’m constructing in my code. Specifically, it looks to me like the memory layout is still an array of structs, rather than a struct of arrays. I’m very new to J…

---

## [Mutating fields in StructArrays](https://discourse.julialang.org/t/mutating-fields-in-structarrays/60106)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 11\
**Last updated:** [April 27, 2021, 8:20pm UTC](https://discourse.julialang.org/t/mutating-fields-in-structarrays/60106 "2021-04-27T20:20:18Z")

</div>

I am starting to use StructArrays in a package, and the benefits clearly outweigh the costs. However, there is one thing that I have, for the moment, to let go, which is the mutation of fields using the most natural synt…

---

## [Error broadcasting string getproperty using StructArrays](https://discourse.julialang.org/t/error-broadcasting-string-getproperty-using-structarrays/60109)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 4\
**Last updated:** [April 27, 2021, 2:42pm UTC](https://discourse.julialang.org/t/error-broadcasting-string-getproperty-using-structarrays/60109 "2021-04-27T14:42:33Z")

</div>

Another issue with my migration to StructArrays. There is one problem I don’t understand when trying to broadcast a function that gets a property and this property, specifically, is of type String. For example: julia\> s…

---

## [StructArrays creating a lot of allocations compared to arrays](https://discourse.julialang.org/t/structarrays-creating-a-lot-of-allocations-compared-to-arrays/54377)

<div class="topic-metadata">

**Author:** [@MrRobot](https://discourse.julialang.org/u/MrRobot)\
**Replies:** 2\
**Last updated:** [February 1, 2021, 3:28pm UTC](https://discourse.julialang.org/t/structarrays-creating-a-lot-of-allocations-compared-to-arrays/54377 "2021-02-01T15:28:21Z")

</div>

I am converting a molecular dynamics code from passing arrays, to instead holding information in StructArray’s. Unfortunately, the code is now 20 times slower. Below I have two identical MWE, one doing the force calcula…

---

## [Understanding and avoiding allocations with StructArrays](https://discourse.julialang.org/t/understanding-and-avoiding-allocations-with-structarrays/46880)

<div class="topic-metadata">

**Author:** [@touste](https://discourse.julialang.org/u/touste)\
**Replies:** 16\
**Last updated:** [September 25, 2020, 9:42am UTC](https://discourse.julialang.org/t/understanding-and-avoiding-allocations-with-structarrays/46880 "2020-09-25T09:42:15Z")

</div>

Hi all, I’m working on a piece of code where I have triangles which are made of points. Each point has a number of properties such as position, velocity, force… In some part of the code I need to calculate the force fo…

---

## [Multiple dispatch on StructArrays](https://discourse.julialang.org/t/multiple-dispatch-on-structarrays/43810)

<div class="topic-metadata">

**Author:** [@ozmaden](https://discourse.julialang.org/u/ozmaden)\
**Replies:** 7\
**Last updated:** [July 28, 2020, 7:15pm UTC](https://discourse.julialang.org/t/multiple-dispatch-on-structarrays/43810 "2020-07-28T19:15:21Z")

</div>

Hi everyone. I am working with the StructArrays.jl package and trying to program a function to react differently for different types of arrays inside of a StructArray. Specifically I want to differentiate between Array …

---

## [Zygote and StructArrays](https://discourse.julialang.org/t/zygote-and-structarrays/35537)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 6\
**Last updated:** [June 7, 2020, 11:50pm UTC](https://discourse.julialang.org/t/zygote-and-structarrays/35537 "2020-06-07T23:50:27Z")

</div>

It seems Flux.@functor does not get along with StructArrays? using StructArrays, Flux struct A{SA} s::SA end struct Point x::Float64 y::Float64 end Flux.@functor A Flux.@functor Point a = A(StructArray((Point(i,2…

[Next page](https://discourse.julialang.org/tag/structarrays/1054.md?match_all_tags=true&page=1&tags%5B%5D=structarrays)
