Skip to content

Commit

Permalink
set nil as the initial value of the struct reference type fields (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 authored Nov 21, 2023
1 parent f49719c commit 2cdb2dc
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions gm/basicgm.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ml/data.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ml/kmeans.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ml/knn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ml/linreg.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ml/workspace.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vcl/buffer.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion vcl/bytes.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vcl/image.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions vcl/kernel.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion vcl/vector.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2cdb2dc

Please sign in to comment.