# \#views

**URL:** https://discourse.julialang.org/tag/views/651.md

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

---

## [Combining reshape and view sometimes allocates](https://discourse.julialang.org/t/combining-reshape-and-view-sometimes-allocates/135725)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 2\
**Last updated:** [February 20, 2026, 2:31am UTC](https://discourse.julialang.org/t/combining-reshape-and-view-sometimes-allocates/135725 "2026-02-20T02:31:05Z")

</div>

I have some complicated code that uses a combination of reshape() and view(), and in my complicated code both reshape() and view() allocates. Trying to reduce my code to an MRE, I came up with this: function profile\_all…

---

## [InvalidIRError when running AcceleratedKernels.sum on a GPU SubArray (CuArray view)](https://discourse.julialang.org/t/invalidirerror-when-running-acceleratedkernels-sum-on-a-gpu-subarray-cuarray-view/133994)

<div class="topic-metadata">

**Author:** [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Replies:** 2\
**Last updated:** [November 20, 2025, 9:20am UTC](https://discourse.julialang.org/t/invalidirerror-when-running-acceleratedkernels-sum-on-a-gpu-subarray-cuarray-view/133994 "2025-11-20T09:20:41Z")

</div>

I’m running into an issue when trying to use AcceleratedKernels.sum on a GPU SubArray (a view into a CuArray). Calling AK.sum on the full array works fine, but calling it on the view throws an InvalidIRError. Question …

---

## [Is it safe to broadcast \`setindex!\` with views of the same array?](https://discourse.julialang.org/t/is-it-safe-to-broadcast-setindex-with-views-of-the-same-array/133620)

<div class="topic-metadata">

**Author:** [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Replies:** 4\
**Last updated:** [November 3, 2025, 4:53pm UTC](https://discourse.julialang.org/t/is-it-safe-to-broadcast-setindex-with-views-of-the-same-array/133620 "2025-11-03T16:53:25Z")

</div>

I tried to find out looking here and through the documentation, but I couldn’t find a concrete answer so far: Is it safe to re-order array elements in-place using a view into the same array, like so: julia\> A = rand(10…

---

## [Assigning to a view of an array](https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869)

<div class="topic-metadata">

**Author:** [@DanimirD](https://discourse.julialang.org/u/DanimirD)\
**Replies:** 37\
**Last updated:** [October 6, 2025, 11:55am UTC](https://discourse.julialang.org/t/assigning-to-a-view-of-an-array/132869 "2025-10-06T11:55:24Z")

</div>

The purpose of creating a view from an array is to avoid a copy. However, a view cannot be assigned to. julia\> X = rand(3,3) 3×3 Matrix{Float64}: 0.135318 0.958828 0.0860895 0.715183 0.136236 0.542946 0.513489 0.9…

---

## [Mapping over multidimensional array with eachslice](https://discourse.julialang.org/t/mapping-over-multidimensional-array-with-eachslice/131880)

<div class="topic-metadata">

**Author:** [@Geegee](https://discourse.julialang.org/u/Geegee)\
**Replies:** 5\
**Last updated:** [August 27, 2025, 4:55pm UTC](https://discourse.julialang.org/t/mapping-over-multidimensional-array-with-eachslice/131880 "2025-08-27T16:55:10Z")

</div>

I have a data opject Array{Float64, 3} where I want to map 2nd and 3rd dimension a function that accepts some static arguments and takes a Vector{Float64} from the data object. I tried to do this with eachslice(data, …

---

## [Can views function on diag?](https://discourse.julialang.org/t/can-views-function-on-diag/128943)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 3\
**Last updated:** [May 13, 2025, 3:54am UTC](https://discourse.julialang.org/t/can-views-function-on-diag/128943 "2025-05-13T03:54:18Z")

</div>

Diagonal vector is a central vector that can be sliced from a Matrix, can it be viewed? julia\> using LinearAlgebra julia\> A = rand(-9:9, 2, 2) 2×2 Matrix{Int64}: -1 6 6 -9 julia\> @views d = diag(A) 2-element Vec…

---

## [Slicing a Vector into a Matrix using views](https://discourse.julialang.org/t/slicing-a-vector-into-a-matrix-using-views/126918)

<div class="topic-metadata">

**Author:** [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)\
**Replies:** 13\
**Last updated:** [March 16, 2025, 11:06am UTC](https://discourse.julialang.org/t/slicing-a-vector-into-a-matrix-using-views/126918 "2025-03-16T11:06:07Z")

</div>

Hi, I loaded data from a simple file input.txt: 1 2 3 4 5 6 7 8 9 into a vector with: data = CSV.File("input.txt", ntasks=1, header=false).Column1 So it’s equivalent to: julia\> data = \[1,2,3,4,5,6,7,8,9\] 9…

---

## [In-place mapslices?](https://discourse.julialang.org/t/in-place-mapslices/126415)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 5\
**Last updated:** [March 1, 2025, 4:46pm UTC](https://discourse.julialang.org/t/in-place-mapslices/126415 "2025-03-01T16:46:43Z")

</div>

I want to apply a function that operates on a vector, to each column of a matrix. So, I use mapslices(). But, how to modify the matrix in-place? The following is a failed attempt: function f!(xs) a = xs\[1\] @. xs = …

---

## [Custom array type that defaults to views when sliced?](https://discourse.julialang.org/t/custom-array-type-that-defaults-to-views-when-sliced/125158)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 6\
**Last updated:** [January 24, 2025, 7:31pm UTC](https://discourse.julialang.org/t/custom-array-type-that-defaults-to-views-when-sliced/125158 "2025-01-24T19:31:38Z")

</div>

I’m thinking about making a custom array type that defaults to creating a view when sliced. Is this a bad idea? Would it break things (if so, what things)? For clarity, this question is definitely not to resurrect the d…

---

## [\[ANN\] RollingWindowArrays.jl - flexible and efficient rolling window operations](https://discourse.julialang.org/t/ann-rollingwindowarrays-jl-flexible-and-efficient-rolling-window-operations/122682)

<div class="topic-metadata">

**Author:** [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Replies:** 4\
**Last updated:** [December 25, 2024, 4:08pm UTC](https://discourse.julialang.org/t/ann-rollingwindowarrays-jl-flexible-and-efficient-rolling-window-operations/122682 "2024-12-25T16:08:59Z")

</div>

Wanted to announce RollingWindowArrays.jl, a small package I have been working on for rolling winow operations on arrays, in case anyone finds it useful: julia\> x = rand(6) 6-element Vector{Float64}: 0.2026703034775777…

---

## [A question about SubString](https://discourse.julialang.org/t/a-question-about-substring/123838)

<div class="topic-metadata">

**Author:** [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Replies:** 8\
**Last updated:** [December 15, 2024, 8:21am UTC](https://discourse.julialang.org/t/a-question-about-substring/123838 "2024-12-15T08:21:55Z")

</div>

Hello, What is the difference between SubString and Indexing? I did: julia\> str = "Where the mind is without fear" "Where the mind is without fear" julia\> SubString(str, 1, 5) "Where" julia\> str\[1:5\] "Where" The res…

---

## [UDPSocket sends short datagram using reinterpret](https://discourse.julialang.org/t/udpsocket-sends-short-datagram-using-reinterpret/122640)

<div class="topic-metadata">

**Author:** [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Replies:** 1\
**Last updated:** [November 14, 2024, 4:33pm UTC](https://discourse.julialang.org/t/udpsocket-sends-short-datagram-using-reinterpret/122640 "2024-11-14T16:33:55Z")

</div>

Is this a bug? Common use case for UDPSocket: I have a struct that isbits. I want to msg = reinterpret(UInt8, \[myobj\]) and transmit this via a UDP datagram to be read on another Julia process, where I’ll just recv the d…

---

## [How can I change the Pluto notebook theme?](https://discourse.julialang.org/t/how-can-i-change-the-pluto-notebook-theme/122333)

<div class="topic-metadata">

**Author:** [@selinguler94](https://discourse.julialang.org/u/selinguler94)\
**Replies:** 3\
**Last updated:** [November 7, 2024, 8:52am UTC](https://discourse.julialang.org/t/how-can-i-change-the-pluto-notebook-theme/122333 "2024-11-07T08:52:53Z")

</div>

I genuinely failed to change the theme and I need help.

---

## [Avoid allocations in retrieving array parts](https://discourse.julialang.org/t/avoid-allocations-in-retrieving-array-parts/121908)

<div class="topic-metadata">

**Author:** [@JTHesse](https://discourse.julialang.org/u/JTHesse)\
**Replies:** 2\
**Last updated:** [October 29, 2024, 9:32am UTC](https://discourse.julialang.org/t/avoid-allocations-in-retrieving-array-parts/121908 "2024-10-29T09:32:11Z")

</div>

Hello, I’m trying to reduce memory allocations and increase efficiency of our software. Most of the allocations will occur while retrieving part of an array. As you can see below, the retrieval is allocating much more…

---

## [Proving that copyto! is allocation-free on a view, using AllocCheck](https://discourse.julialang.org/t/proving-that-copyto-is-allocation-free-on-a-view-using-alloccheck/121318)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 7\
**Last updated:** [October 15, 2024, 3:21pm UTC](https://discourse.julialang.org/t/proving-that-copyto-is-allocation-free-on-a-view-using-alloccheck/121318 "2024-10-15T15:21:11Z")

</div>

Hi there, I wanted to add allocation checks to the DifferentiationInterface.jl test suite, but the code for my in-place jacobian! involves copying a vector into a matrix column. Unfortunately, AllocCheck.jl cannot guara…

---

## [Pushing elements into a view](https://discourse.julialang.org/t/pushing-elements-into-a-view/119733)

<div class="topic-metadata">

**Author:** [@fmor](https://discourse.julialang.org/u/fmor)\
**Replies:** 4\
**Last updated:** [September 23, 2024, 9:29am UTC](https://discourse.julialang.org/t/pushing-elements-into-a-view/119733 "2024-09-23T09:29:19Z")

</div>

I’m working on a clustering model, and to compute cluster weights I have to compare the cohesions of the current cluster k to the one of cluster k plus unit j (respectively old (o) and new (n) in the code). To do so I t…

---

## [Question on performance of views](https://discourse.julialang.org/t/question-on-performance-of-views/119292)

<div class="topic-metadata">

**Author:** [@xvries](https://discourse.julialang.org/u/xvries)\
**Replies:** 4\
**Last updated:** [September 12, 2024, 5:20pm UTC](https://discourse.julialang.org/t/question-on-performance-of-views/119292 "2024-09-12T17:20:12Z")

</div>

In some of our code we use views based on integer indexing (we need to remove some colums from our matrices). I noticed that these views have very poor performance in multiplication. a = rand(1000, 1000) @btime a\*a # 1…

---

## [How to concatenate matrices views without copying memory?](https://discourse.julialang.org/t/how-to-concatenate-matrices-views-without-copying-memory/118760)

<div class="topic-metadata">

**Author:** [@Blumenkranz](https://discourse.julialang.org/u/Blumenkranz)\
**Replies:** 3\
**Last updated:** [August 29, 2024, 1:08pm UTC](https://discourse.julialang.org/t/how-to-concatenate-matrices-views-without-copying-memory/118760 "2024-08-29T13:08:21Z")

</div>

Using vcat to catenate views leads to memory allocation which is contrary to the original intent of @views. CatViews.jl can address the issue to some extent, but it is only applicable to vectors. I wonder if there is a w…

---

## [Broadcasting on views](https://discourse.julialang.org/t/broadcasting-on-views/118459)

<div class="topic-metadata">

**Author:** [@pratikvn](https://discourse.julialang.org/u/pratikvn)\
**Replies:** 2\
**Last updated:** [August 22, 2024, 11:22am UTC](https://discourse.julialang.org/t/broadcasting-on-views/118459 "2024-08-22T11:22:45Z")

</div>

Hello, I would like to perform a broadcast operation on views with indices stored in a struct. I am not sure how exactly to acheive this with Julia syntax. Essentially I have a struct like so: struct Foo id::Inte…

---

## [Scalar Indexing error when performing mul!(A, B, C) with A a view of a Matrix](https://discourse.julialang.org/t/scalar-indexing-error-when-performing-mul-a-b-c-with-a-a-view-of-a-matrix/115439)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 3\
**Last updated:** [June 11, 2024, 4:49pm UTC](https://discourse.julialang.org/t/scalar-indexing-error-when-performing-mul-a-b-c-with-a-a-view-of-a-matrix/115439 "2024-06-11T16:49:53Z")

</div>

Hello, I paste also here the issue raised here. Describe the bug The in-place multiplication mul!(A, B, C) fails when A is a vector view of a matrix. To reproduce The Minimal Working Example (MWE) for this bug: us…

---

## [Copy or view, issue](https://discourse.julialang.org/t/copy-or-view-issue/110395)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 1\
**Last updated:** [February 19, 2024, 10:56am UTC](https://discourse.julialang.org/t/copy-or-view-issue/110395 "2024-02-19T10:56:19Z")

</div>

Following Noteworthy Differences from other Languages · The Julia Language which says that: Julia arrays are not copied when assigned to another variable. After A = B, changing elements of B will modify A as well. To a…

---

## [Distributed: Passing views of an array for read access to workers (using pmap)](https://discourse.julialang.org/t/distributed-passing-views-of-an-array-for-read-access-to-workers-using-pmap/109379)

<div class="topic-metadata">

**Author:** [@james](https://discourse.julialang.org/u/james)\
**Replies:** 8\
**Last updated:** [January 31, 2024, 9:42am UTC](https://discourse.julialang.org/t/distributed-passing-views-of-an-array-for-read-access-to-workers-using-pmap/109379 "2024-01-31T09:42:42Z")

</div>

I have a large array and want multiple workers to have read access to that array in parallel. Each worker works on a disjoint interval of the array. My plan was to create a view of each of the sections of the array, and…

---

## [@view : No bound checkings?](https://discourse.julialang.org/t/view-no-bound-checkings/108068)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 13\
**Last updated:** [December 27, 2023, 9:04am UTC](https://discourse.julialang.org/t/view-no-bound-checkings/108068 "2023-12-27T09:04:01Z")

</div>

I am trying the following code. v = Vector{Int8}(1:10) w = @view v\[3:8\] deleteat!(v, 3:8) println(v) w\[4\] = 42 println(w) The result is this: Int8\[1, 2, 9, 10\] Int8\[9, 10, 0, 42, 7, 8\] My question is about the second…

---

## [Can I create a reference to a section of a matrix without copying its elements?](https://discourse.julialang.org/t/can-i-create-a-reference-to-a-section-of-a-matrix-without-copying-its-elements/106813)

<div class="topic-metadata">

**Author:** [@Bottom](https://discourse.julialang.org/u/Bottom)\
**Replies:** 3\
**Last updated:** [November 27, 2023, 8:01pm UTC](https://discourse.julialang.org/t/can-i-create-a-reference-to-a-section-of-a-matrix-without-copying-its-elements/106813 "2023-11-27T20:01:24Z")

</div>

In my code I have some 3D matrices M\[m,i,j\] where I iterate much less frequent over the first index (m: timestep) than over the other two (i,j: spatial discretization). I would like to have an alias for M\[m, :, :\] so I c…

---

## [Is it possible to cut a vector into 2 pieces without allocations?](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 11\
**Last updated:** [November 27, 2023, 10:25am UTC](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749 "2023-11-27T10:25:36Z")

</div>

Let’s say I have toy data m, n = 10^3, 10^6; x1 = \[rand(-1:0.001:1,s) for j=1:n for s in rand(1:m,1)\] len = \[rand(1:length(x)) for x in x1\] I wish to split each vector x1\[j\] into x1\[j\]\[1:len\[j\]\] and x1\[j\]\[len\[j\]:end…

---

## [Loading views from serialized file disconnects memory link](https://discourse.julialang.org/t/loading-views-from-serialized-file-disconnects-memory-link/102335)

<div class="topic-metadata">

**Author:** [@mwhisena](https://discourse.julialang.org/u/mwhisena)\
**Replies:** 0\
**Last updated:** [July 31, 2023, 9:31pm UTC](https://discourse.julialang.org/t/loading-views-from-serialized-file-disconnects-memory-link/102335 "2023-07-31T21:31:10Z")

</div>

I have a large matrix of data that I wish to create hundreds of views from. These views help me with setindexing and actually using my data in the program. This works perfectly for me, especially if I want to deepcopy to…

---

## [Error with @views and a function](https://discourse.julialang.org/t/error-with-views-and-a-function/102284)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 3\
**Last updated:** [July 31, 2023, 6:08am UTC](https://discourse.julialang.org/t/error-with-views-and-a-function/102284 "2023-07-31T06:08:15Z")

</div>

I’m getting this strange error when trying to use views with a function. Here is a MWE: x = Array{Float64}(undef, 3, 3, 3) y = similar(x) @views function fun(x, y, t) y\[:, :, t\], x\[:, :, t\] = rand(3, 3) return …

---

## [What happens to a view when the parent array is reassigned?](https://discourse.julialang.org/t/what-happens-to-a-view-when-the-parent-array-is-reassigned/101487)

<div class="topic-metadata">

**Author:** [@Jad\_Zeitouni](https://discourse.julialang.org/u/Jad_Zeitouni)\
**Replies:** 1\
**Last updated:** [July 11, 2023, 4:11pm UTC](https://discourse.julialang.org/t/what-happens-to-a-view-when-the-parent-array-is-reassigned/101487 "2023-07-11T16:11:29Z")

</div>

Let’s say I have an array x and a create a view y. I then reassign x to another array at some point. I can see that y still points to the original array, so that I don’t actually clear memory by reassigning x. Is the onl…

---

## [Making a view of a combination of array indexes and scalars, creating an array to send to a function](https://discourse.julialang.org/t/making-a-view-of-a-combination-of-array-indexes-and-scalars-creating-an-array-to-send-to-a-function/99332)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 7\
**Last updated:** [May 25, 2023, 3:24pm UTC](https://discourse.julialang.org/t/making-a-view-of-a-combination-of-array-indexes-and-scalars-creating-an-array-to-send-to-a-function/99332 "2023-05-25T15:24:47Z")

</div>

I have a combination of scalar values, and values stored in vectors. Is there a good way to create a view of these and send to other functions, rather than allocating it all to a new array? I am performance de-bugging a…

---

## [SQL-like "trigger" for arrays within a struct](https://discourse.julialang.org/t/sql-like-trigger-for-arrays-within-a-struct/99177)

<div class="topic-metadata">

**Author:** [@jwright11](https://discourse.julialang.org/u/jwright11)\
**Replies:** 3\
**Last updated:** [May 22, 2023, 1:52pm UTC](https://discourse.julialang.org/t/sql-like-trigger-for-arrays-within-a-struct/99177 "2023-05-22T13:52:17Z")

</div>

Is there such a thing as a SQL-like “trigger” for arrays within a struct in Julia? I have an immutable struct, foo, that stores lots of pieces of information which get consumed by other functions. Two of the elements of…

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