You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
copilot-language: Support modifying values in arrays #36
Currently there is no way to construct an array from stream carrying scalars. Having a feature like this (and a similar one for structs) would indeed help a lot, and is worth looking into.
Update: @InnovativeInventor has implemented 'set' or 'update' for arrays, which allows us to implement this. We'll be discussing integrating this into Copilot in the upcoming future.
Update: similar requests have come up recently related to structs. We are looking into porting the solution that @InnovativeInventor prepared to work for structs and adding both to Copilot. Stay tuned.
changed the title [-]Defining Stream (Array 2 Double) from 2 Stream Double[/-][+]`copilot-language`: Support modifying values in arrays[/+]on Jul 8, 2024
The solution proposed produces the expected result. Details:
The following Dockerfile installs copilot and runs a file with struct update operations, which it then links and compares against its expected output, printing the message "Success" if the output matches the expectation:
--- Dockerfile
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install --yes libz-dev
RUN apt-get install --yes git
RUN apt-get install --yes wget
RUN mkdir -p $HOME/.ghcup/bin
RUN wget https://downloads.haskell.org/~ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 -O $HOME/.ghcup/bin/ghcup
RUN chmod a+x $HOME/.ghcup/bin/ghcup
ENV PATH=$PATH:/root/.ghcup/bin/
ENV PATH=$PATH:/root/.cabal/bin/
RUN apt-get install --yes curl
RUN apt-get install --yes gcc g++ make libgmp3-dev
RUN apt-get install --yes pkg-config
SHELL ["/bin/bash", "-c"]
RUN ghcup install ghc 9.4
RUN ghcup install cabal 3.2
RUN ghcup set ghc 9.4.8
RUN cabal update
ADD Arrays.hs /tmp/Arrays.hs
ADD main.c /tmp/main.c
ADD expected /tmp/expected
CMD git clone $REPO \
&& cd $NAME \
&& git checkout $COMMIT \
&& cabal v1-sandbox init \
&& cabal v1-install alex happy \
&& cabal v1-install copilot**/ \
&& cabal v1-exec -- runhaskell /tmp/Arrays.hs \
&& mv /tmp/main.c . \
&& gcc main.c arrays.c -o main \
&& ./main > actual \
&& diff actual /tmp/expected \
&& echo Success
--- Arrays.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main (main) where
import Copilot.Compile.C99
import Data.Type.Equality as DE
import Language.Copilot
-- Sample values
arr :: Stream (Array 2 Float)
arr = [ array [1.0, 2.5]
, array [2.5, 1.0]
]
++ arr
arr1 = (arr !! 1 =$ (+1)) !! 0 =$ (+100)
arr2 = arr1 !! 1 =$ ([0.0] ++)
spec :: Spec
spec = do
trigger "arrays" true [arg arr2]
main :: IO ()
main = do
spec' <- reify spec compile "arrays" spec'
--- main.c
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include "arrays.h"#include "arrays_types.h"
void arrays( float* arrays_arg0
) {
printf("%f %f\n"
, arrays_arg0[0]
, arrays_arg0[1]);
}
int main() {
step();
step();
step();
step();
}
--- expected
101.000000 0.000000
102.500000 3.500000
101.000000 2.000000
102.500000 3.500000
Command (substitute variables based on new path after merge):
Implementation is documented. Details:
New operations and modules are documented.
Change history is clear.
Commit messages are clear.
Changelogs are updated.
Examples are updated. Details:
Examples updated and new examples included.
Required version bumps are evaluated. Details:
Bump needed (the definitions of both Op3 have changed; a function has been hidden, a function has been deprecated, and operations have moved modules).
Activity
fdedden commentedon Jul 9, 2019
Currently there is no way to construct an array from stream carrying scalars. Having a feature like this (and a similar one for structs) would indeed help a lot, and is worth looking into.
ivanperez-keera commentedon Jul 10, 2019
I wouldn't know how to go about it. I'm thinking about kinds and arities, but I'm not sure we could make it work.
ivanperez-keera commentedon Jul 8, 2023
Update: Someone is working on a feature atm that would allow us to implement this.
ivanperez-keera commentedon Aug 6, 2023
Update: @InnovativeInventor has implemented 'set' or 'update' for arrays, which allows us to implement this. We'll be discussing integrating this into Copilot in the upcoming future.
ivanperez-keera commentedon Dec 12, 2023
Update: similar requests have come up recently related to structs. We are looking into porting the solution that @InnovativeInventor prepared to work for structs and adding both to Copilot. Stay tuned.
ivanperez-keera commentedon Jul 7, 2024
For awareness, we have an open issue #520 that we intend to merge today on updating fields of structs.
ivanperez-keera commentedon Jul 8, 2024
Description
Copilot currently supports reading values from streams of arrays, but not changing them.
We'd like to be able to modify an array by adjusting the value at a specific position.
Type
Additional context
None.
Requester
Method to check presence of bug
Not applicable (not a bug).
Expected result
Copilot provides a mechanism to update specific values in arrays in an stream of arrays.
Desired result
Copilot provides a mechanism to update specific values in arrays in an stream of arrays.
Proposed solution
Extend
copilot-languageto provide operations to modify values of arrays in streams.Extend
copilot-core,copilot-c99and other libraries accordingly.Further notes
None.
[-]Defining Stream (Array 2 Double) from 2 Stream Double[/-][+]`copilot-language`: Support modifying values in arrays[/+]ivanperez-keera commentedon Jul 8, 2024
Change Manager: Confirmed that the issue exists.
293 remaining items
copilot-c99: Document changes in CHANGELOG. Refs Copilot-Language#36.
copilot-interpreter: Document changes in CHANGELOG. Refs Copilot-Lang…
copilot-prettyprinter: Document changes in CHANGELOG. Refs Copilot-La…
copilot-libraries: Document changes in CHANGELOG. Refs Copilot-Langua…
copilot-theorem: Document changes in CHANGELOG. Refs Copilot-Language#36
copilot: Document changes in CHANGELOG. Refs Copilot-Language#36.
copilot-language: Rename operator. Refs Copilot-Language#36.
copilot-prettyprinter: Update pretty printer access to use the symbol…
copilot: Update array example to use new syntax. Refs Copilot-Languag…
copilot-libraries: Rename function to avoid name clash. Refs Copilot-…
copilot-core: Introduce new kind of array element update operator. Refs
copilot-core: Introduce operations to update arrays. Refs Copilot-Lan…
ivanperez-keera commentedon Sep 6, 2024
Implementor: Solution implemetned, review requested.
ivanperez-keera commentedon Sep 6, 2024
Change Manager: Verified that:
The code proposed compiles and passes all tests. Details:
Build log: https://app.travis-ci.com/github/Copilot-Language/copilot/builds/272213129
The solution proposed produces the expected result. Details:
The following Dockerfile installs
copilotand runs a file with struct update operations, which it then links and compares against its expected output, printing the message "Success" if the output matches the expectation:Command (substitute variables based on new path after merge):
New operations and modules are documented.
Examples updated and new examples included.
Bump needed (the definitions of both
Op3have changed; a function has been hidden, a function has been deprecated, and operations have moved modules).ivanperez-keera commentedon Sep 6, 2024
Change Manager: Implementation ready to be merged.