From 2cdb2dc2968f1e84ce01635ba8d5aa5dd11ecbb8 Mon Sep 17 00:00:00 2001 From: shove Date: Tue, 21 Nov 2023 11:09:01 +0800 Subject: [PATCH] set nil as the initial value of the struct reference type fields (#192) --- gm/basicgm.v | 4 ++-- ml/data.v | 4 ++-- ml/kmeans.v | 6 +++--- ml/knn.v | 2 +- ml/linreg.v | 6 +++--- ml/workspace.v | 2 +- vcl/buffer.c.v | 2 +- vcl/bytes.c.v | 2 +- vcl/image.c.v | 2 +- vcl/kernel.c.v | 6 +++--- vcl/vector.c.v | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gm/basicgm.v b/gm/basicgm.v index 452ada2c2..f1d83aec9 100644 --- a/gm/basicgm.v +++ b/gm/basicgm.v @@ -15,8 +15,8 @@ pub mut: @[heap] pub struct Segment { pub: - a &Point - b &Point + a &Point = unsafe { nil } + b &Point = unsafe { nil } } // Point.new creates a new point diff --git a/ml/data.v b/ml/data.v index c142a86e1..273d3c47b 100644 --- a/ml/data.v +++ b/ml/data.v @@ -25,8 +25,8 @@ pub mut: observable util.Observable = util.Observable{} nb_samples int // number of data points (samples). number of rows in x and y nb_features int // number of features. number of columns in x - x &la.Matrix[T] // [nb_samples][nb_features] x values - y []T // [nb_samples] y values [optional] + x &la.Matrix[T] = unsafe { nil } // [nb_samples][nb_features] x values + y []T // [nb_samples] y values [optional] } // Data.new returns a new object to hold ML data diff --git a/ml/kmeans.v b/ml/kmeans.v index f40c13b6f..379e8f7aa 100644 --- a/ml/kmeans.v +++ b/ml/kmeans.v @@ -10,10 +10,10 @@ import vsl.plot pub struct Kmeans { mut: name string // name of this "observer" - data &Data[f64] // x data - stat &Stat[f64] // statistics about x (data) + data &Data[f64] = unsafe { nil } // x data + stat &Stat[f64] = unsafe { nil } // statistics about x (data) nb_classes int // expected number of classes - bins &gm.Bins // "bins" to speed up searching for data points given their coordinates (2D or 3D only at the moment) + bins &gm.Bins = unsafe { nil } // "bins" to speed up searching for data points given their coordinates (2D or 3D only at the moment) nb_iter int // number of iterations pub mut: classes []int // [nb_samples] indices of classes of each sample diff --git a/ml/knn.v b/ml/knn.v index a2f7f9e52..6d95a0375 100644 --- a/ml/knn.v +++ b/ml/knn.v @@ -9,7 +9,7 @@ import vsl.plot pub struct KNN { mut: name string // name of this "observer" - data &Data[f64] + data &Data[f64] = unsafe { nil } weights map[f64]f64 // weights[class] = weight pub mut: neighbors []Neighbor diff --git a/ml/linreg.v b/ml/linreg.v index a3b953e0d..65b0ae9e3 100644 --- a/ml/linreg.v +++ b/ml/linreg.v @@ -10,12 +10,12 @@ pub struct LinReg { mut: // main name string // name of this "observer" - data &Data[f64] // x-y data + data &Data[f64] = unsafe { nil } // x-y data // workspace e []f64 // vector e = b⋅o + x⋅theta - y [nb_samples] pub mut: - stat &Stat[f64] // statistics - params &ParamsReg[f64] + stat &Stat[f64] = unsafe { nil } // statistics + params &ParamsReg[f64] = unsafe { nil } } // LinReg.new returns a new LinReg object diff --git a/ml/workspace.v b/ml/workspace.v index a260f54b2..52810d4bd 100644 --- a/ml/workspace.v +++ b/ml/workspace.v @@ -11,7 +11,7 @@ import vsl.la @[heap] pub struct Stat[T] { pub mut: - data &Data[T] // data + data &Data[T] = unsafe { nil } // data name string // name of this object min_x []T // [n_features] min x values max_x []T // [n_features] max x values diff --git a/vcl/buffer.c.v b/vcl/buffer.c.v index 4c8584635..b096d60c0 100644 --- a/vcl/buffer.c.v +++ b/vcl/buffer.c.v @@ -3,7 +3,7 @@ module vcl // Buffer memory buffer on the device struct Buffer { size int - device &Device + device &Device = unsafe { nil } mut: memobj ClMem } diff --git a/vcl/bytes.c.v b/vcl/bytes.c.v index 0200607f2..84876c485 100644 --- a/vcl/bytes.c.v +++ b/vcl/bytes.c.v @@ -2,7 +2,7 @@ module vcl // Bytes is a memory buffer on the device that holds []byte pub struct Bytes { - buf &Buffer + buf &Buffer = unsafe { nil } } // bytes allocates new memory buffer with specified size on device diff --git a/vcl/image.c.v b/vcl/image.c.v index 41784e9d8..8efa51007 100644 --- a/vcl/image.c.v +++ b/vcl/image.c.v @@ -21,7 +21,7 @@ pub interface IImage { // Image memory buffer on the device with image data pub struct Image { format ClImageFormat - desc &ClImageDesc + desc &ClImageDesc = unsafe { nil } img_data voidptr mut: buf &Buffer diff --git a/vcl/kernel.c.v b/vcl/kernel.c.v index df57ec373..f87a1d604 100644 --- a/vcl/kernel.c.v +++ b/vcl/kernel.c.v @@ -46,7 +46,7 @@ fn UnsupportedArgumentTypeError.new(index int, value ArgumentType) IError { // Kernel represent a single kernel pub struct Kernel { - d &Device + d &Device = unsafe { nil } k ClKernel } @@ -61,7 +61,7 @@ pub fn (k &Kernel) global(global_work_sizes ...int) KernelWithGlobal { // KernelWithGlobal is a kernel with the global size set // to run the kernel it must also set the local size pub struct KernelWithGlobal { - kernel &Kernel + kernel &Kernel = unsafe { nil } global_work_sizes []int } @@ -77,7 +77,7 @@ pub fn (kg KernelWithGlobal) local(local_work_sizes ...int) KernelCall { // KernelCall is a kernel with global and local work sizes set // and it's ready to be run pub struct KernelCall { - kernel &Kernel + kernel &Kernel = unsafe { nil } global_work_sizes []int local_work_sizes []int } diff --git a/vcl/vector.c.v b/vcl/vector.c.v index 19c521087..c0a91abf1 100644 --- a/vcl/vector.c.v +++ b/vcl/vector.c.v @@ -3,7 +3,7 @@ module vcl // Vector is a memory buffer on device that holds []T pub struct Vector[T] { mut: - buf &Buffer + buf &Buffer = unsafe { nil } } // vector allocates new vector buffer with specified length