vlang / vsl

V library to develop Artificial Intelligence and High-Performance Scientific Computations
https://vlang.github.io/vsl
MIT License
340 stars 46 forks source link

add to vcl empty vectors, buffers ... #154

Closed MatejMagat305 closed 1 year ago

MatejMagat305 commented 1 year ago

Describe the feature

as I mension in isues https://github.com/vlang/v/issues/17401 I got some warning of code, so maybe it would be good add empty for types for delay init,

Use Case

it give error in future:

planet.v:56:20: warning: reference field `vsl.vcl.Kernel.d` must be initialized
   54 | 
   55 | fn simulate(shared planets Planets) {
   56 |     mut kernel := vcl.Kernel{}
      |                       ~~~~~~~~
   57 |     mut cl_vector1 := vcl.Vector[Planet]{}
   58 |     mut cl_vector2 := vcl.Vector[Planet]{}
planet.v:57:24: warning: reference field `vsl.vcl.Vector[Planet].buf` must be initialized
   55 | fn simulate(shared planets Planets) {
   56 |     mut kernel := vcl.Kernel{}
   57 |     mut cl_vector1 := vcl.Vector[Planet]{}
      |                           ~~~~~~~~~~~~~~~~
   58 |     mut cl_vector2 := vcl.Vector[Planet]{}
   59 |     lock planets {
planet.v:58:24: warning: reference field `vsl.vcl.Vector[Planet].buf` must be initialized
   56 |     mut kernel := vcl.Kernel{}
   57 |     mut cl_vector1 := vcl.Vector[Planet]{}
   58 |     mut cl_vector2 := vcl.Vector[Planet]{}
      |                           ~~~~~~~~~~~~~~~~
   59 |     lock planets {
   60 |         unsafe {
planet.v:61:11: warning: cannot assign a reference to a value (this will be an error soon) left=vsl.vcl.Kernel false right=vsl.vcl.Kernel true ptr=true
   59 |     lock planets {
   60 |         unsafe {
   61 |             kernel = planets.kernel
      |                    ^
   62 |             cl_vector1 = planets.cl_vector1
   63 |             cl_vector2 = planets.cl_vector2
planet.v:62:15: warning: cannot assign a reference to a value (this will be an error soon) left=vsl.vcl.Vector[Planet] false right=vsl.vcl.Vector[Planet] true ptr=true
   60 |         unsafe {
   61 |             kernel = planets.kernel
   62 |             cl_vector1 = planets.cl_vector1
      |                        ^
   63 |             cl_vector2 = planets.cl_vector2
   64 |         }
planet.v:63:15: warning: cannot assign a reference to a value (this will be an error soon) left=vsl.vcl.Vector[Planet] false right=vsl.vcl.Vector[Planet] true ptr=true
   61 |             kernel = planets.kernel
   62 |             cl_vector1 = planets.cl_vector1
   63 |             cl_vector2 = planets.cl_vector2
      |                        ^
   64 |         }
   65 |     }

Proposed Solution

add options vcl.empty_......

Other Information

No response

Acknowledgements

Version used

V 0.3.3 b1ed1d3.acd9034

Environment details (OS name and version, etc.)

OS: linux, Pop!_OS 22.04 LTS Processor: 32 cpus, 64bit, little endian, AMD Ryzen 9 5950X 16-Core Processor CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

getwd: /home/matejmag/CLionProjects/own_struct_vcl vmodules: /home/matejmag/.vmodules vroot: /home/matejmag/v vexe: /home/matejmag/v/v vexe mtime: 2023-02-23 18:05:35 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 b1ed1d3.acd9034

Git version: git version 2.34.1 Git vroot status: weekly.2023.08-14-gacd90348 .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

ulises-jeremias commented 1 year ago

@MatejMagat305 this is a wrong usage of the library. we should never instantiate a kernel or vector without the device. The entrypoint of VCL is to always get a device and create the entities from there.

This won't be supported since the proper usage is to always do

device.vector[Planet]()