diff --git a/ds/array/index.html b/ds/array/index.html index 374652d..aa9b9bc 100644 --- a/ds/array/index.html +++ b/ds/array/index.html @@ -314,6 +314,17 @@ + + @@ -324,6 +335,80 @@ + + + + @@ -459,6 +544,69 @@ + + + @@ -475,7 +623,137 @@ -

array

+

Array

+

Structure

+
typedef struct {
+    size_t size;
+    float *arr;
+} Array;
+
+

Array is LinearML way of storing both the C array and the number of elements at the +same time.

+

Examples

+

1. Creating a simple Array

+
#include "ds/array.h"
+
+int main(void) {
+    // create an array with 3 values
+    Array *arr = arr_create(3);
+
+    ARR_AT(arr, 0) = 1;  // set arr[0] = 1
+    ARR_AT(arr, 1) = 4;  // set arr[1] = 4
+    ARR_AT(arr, 2) = 5;  // set arr[2] = 5
+
+    arr_print(arr);
+
+    // free Array crated using arr_crate
+    arr_free(arr);
+
+    return 0;
+}
+
+
[ 1.00 4.00 5.00 ]
+
+

2. Create an Array using existing C array

+
#include "ds/array.h"
+
+int main(void) {
+    float arr_vals[] = {1, 2, 3, 4};
+
+    // use an existing C array with 4 values
+    Array *arr = arr_init(arr_vals, 4);
+
+    ARR_AT(arr, 0) = 5;  // set arr[0] = 5
+    arr_print(arr);
+
+    // free Array crated using arr_init
+    arr_init_free(arr);
+    return 0;
+}
+
+
[ 5.00 2.00 3.00 4.00 ]
+
+

3. Changing the float precision during printing

+
#include "ds/array.h"
+
+int main(void) {
+    // create an array with 3 values
+    Array *arr = arr_create(3);
+
+    ARR_AT(arr, 0) = 1;  // set arr[0] = 1
+    ARR_AT(arr, 1) = 4;  // set arr[1] = 4
+    ARR_AT(arr, 2) = 5;  // set arr[2] = 5
+
+    // use arr_printp instead of arr_print
+    arr_printp(arr, 0);
+
+    // free Array crated using arr_crate
+    arr_free(arr);
+
+    return 0;
+}
+
+
[ 1 4 5 ]
+
+

4. Map a function over the Array

+
#include "ds/array.h"
+
+float add_three(float val) {
+    return val + 3;
+}
+
+int main(void) {
+    // create an array with 3 values
+    Array *arr = arr_create(3);
+
+    ARR_AT(arr, 0) = 1;  // set arr[0] = 1
+    ARR_AT(arr, 1) = 4;  // set arr[1] = 4
+    ARR_AT(arr, 2) = 5;  // set arr[2] = 5
+
+    // the function will return the same array back for
+    // convenience reasons
+    arr_print(arr_map(arr, add_three));
+
+    // free Array crated using arr_crate
+    arr_free(arr);
+
+    return 0;
+}
+
+
[ 4.00 7.00 8.00 ]
+
+

5. Array stats

+
#include <stdio.h>
+
+#define INCLUDE_ARRAY_STATS
+#include "ds/array.h"
+
+
+int main(void) {
+    // create an array with 3 values
+    Array *arr = arr_create(3);
+
+    ARR_AT(arr, 0) = 1;  // set arr[0] = 1
+    ARR_AT(arr, 1) = 4;  // set arr[1] = 4
+    ARR_AT(arr, 2) = 5;  // set arr[2] = 5
+
+    arr_print(arr);
+
+    printf("Mean: %.2f\n", arr_mean(arr));
+    printf("Max: %.2f\n", arr_max(arr));
+    printf("Min: %.2f\n", arr_min(arr));
+
+    // free Array crated using arr_crate
+    arr_free(arr);
+
+    return 0;
+}
+
+
[ 1.00 4.00 5.00 ]
+Mean: 3.33
+Max: 5.00
+Min: 1.00
+
diff --git a/search/search_index.json b/search/search_index.json index b1d8ca2..0216789 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"LinearML","text":"

\\(LinearML\\)

"},{"location":"ds/array/","title":"array","text":""},{"location":"ds/mat/","title":"mat","text":""},{"location":"ds/vec/","title":"vec","text":""},{"location":"ds/vec/#this-is-the-vec-file","title":"this is the vec file","text":""},{"location":"ml/linregress/","title":"Linear Regression","text":"

\\(\\text{Hello World}\\)

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"LinearML","text":"

\\(LinearML\\)

"},{"location":"ds/array/","title":"Array","text":""},{"location":"ds/array/#structure","title":"Structure","text":"
typedef struct {\nsize_t size;\nfloat *arr;\n} Array;\n

Array is LinearML way of storing both the C array and the number of elements at the same time.

"},{"location":"ds/array/#examples","title":"Examples","text":""},{"location":"ds/array/#1-creating-a-simple-array","title":"1. Creating a simple Array","text":"
#include \"ds/array.h\"\n\nint main(void) {\n// create an array with 3 values\nArray *arr = arr_create(3);\n\nARR_AT(arr, 0) = 1;  // set arr[0] = 1\nARR_AT(arr, 1) = 4;  // set arr[1] = 4\nARR_AT(arr, 2) = 5;  // set arr[2] = 5\n\narr_print(arr);\n\n// free Array crated using arr_crate\narr_free(arr);\n\nreturn 0;\n}\n
[ 1.00 4.00 5.00 ]\n
"},{"location":"ds/array/#2-create-an-array-using-existing-c-array","title":"2. Create an Array using existing C array","text":"
#include \"ds/array.h\"\n\nint main(void) {\nfloat arr_vals[] = {1, 2, 3, 4};\n\n// use an existing C array with 4 values\nArray *arr = arr_init(arr_vals, 4);\n\nARR_AT(arr, 0) = 5;  // set arr[0] = 5\narr_print(arr);\n\n// free Array crated using arr_init\narr_init_free(arr);\nreturn 0;\n}\n
[ 5.00 2.00 3.00 4.00 ]\n
"},{"location":"ds/array/#3-changing-the-float-precision-during-printing","title":"3. Changing the float precision during printing","text":"
#include \"ds/array.h\"\n\nint main(void) {\n// create an array with 3 values\nArray *arr = arr_create(3);\n\nARR_AT(arr, 0) = 1;  // set arr[0] = 1\nARR_AT(arr, 1) = 4;  // set arr[1] = 4\nARR_AT(arr, 2) = 5;  // set arr[2] = 5\n\n// use arr_printp instead of arr_print\narr_printp(arr, 0);\n\n// free Array crated using arr_crate\narr_free(arr);\n\nreturn 0;\n}\n
[ 1 4 5 ]\n
"},{"location":"ds/array/#4-map-a-function-over-the-array","title":"4. Map a function over the Array","text":"
#include \"ds/array.h\"\n\nfloat add_three(float val) {\nreturn val + 3;\n}\n\nint main(void) {\n// create an array with 3 values\nArray *arr = arr_create(3);\n\nARR_AT(arr, 0) = 1;  // set arr[0] = 1\nARR_AT(arr, 1) = 4;  // set arr[1] = 4\nARR_AT(arr, 2) = 5;  // set arr[2] = 5\n\n// the function will return the same array back for\n// convenience reasons\narr_print(arr_map(arr, add_three));\n\n// free Array crated using arr_crate\narr_free(arr);\n\nreturn 0;\n}\n
[ 4.00 7.00 8.00 ]\n
"},{"location":"ds/array/#5-array-stats","title":"5. Array stats","text":"
#include <stdio.h>\n\n#define INCLUDE_ARRAY_STATS\n#include \"ds/array.h\"\n\n\nint main(void) {\n// create an array with 3 values\nArray *arr = arr_create(3);\n\nARR_AT(arr, 0) = 1;  // set arr[0] = 1\nARR_AT(arr, 1) = 4;  // set arr[1] = 4\nARR_AT(arr, 2) = 5;  // set arr[2] = 5\n\narr_print(arr);\n\nprintf(\"Mean: %.2f\\n\", arr_mean(arr));\nprintf(\"Max: %.2f\\n\", arr_max(arr));\nprintf(\"Min: %.2f\\n\", arr_min(arr));\n\n// free Array crated using arr_crate\narr_free(arr);\n\nreturn 0;\n}\n
[ 1.00 4.00 5.00 ]\nMean: 3.33\nMax: 5.00\nMin: 1.00\n
"},{"location":"ds/mat/","title":"mat","text":""},{"location":"ds/vec/","title":"vec","text":""},{"location":"ds/vec/#this-is-the-vec-file","title":"this is the vec file","text":""},{"location":"ml/linregress/","title":"Linear Regression","text":"

\\(\\text{Hello World}\\)

"}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 49d94b6..7796599 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ