Commit 77a9509f authored by Chris Müller's avatar Chris Müller

lib: remove matrix module.

parent 64798a11
set(SOURCES
matrix.c
unittest.c
structures/single_linked_list.c
structures/double_linked_list.c
......@@ -9,7 +8,6 @@ set(SOURCES
set(HEADER
standard.h
unix_colors.h
matrix.h
unittest.h
structures/array.h
structures/stack.h
......
/*
* Copyright (c) 2012 Christoph Mueller <ruunhb@googlemail.com>
*
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include "matrix.h"
struct CrySingleMatrix
cry_singlematrix_new(unsigned int rows, unsigned int cols, float value)
{
float* p = 0;
float* data = cry_calloc(float, rows * cols);
struct CrySingleMatrix matrix = { .data = data, .rows = rows, .cols = cols };
for(p = data; p < data + rows * cols; ++p)
*p = value;
return matrix;
}
struct CryDoubleMatrix
cry_doublematrix_new(unsigned int rows, unsigned int cols, double value)
{
double* p = 0;
double* data = cry_calloc(double, rows * cols);
struct CryDoubleMatrix matrix = { .data = data, .rows = rows, .cols = cols };
for(p = data; p < data + rows * cols; ++p)
*p = value;
return matrix;
}
void
cry_singlematrix_print(FILE* io, struct CrySingleMatrix matrix)
{
float* p = 0;
for(p = matrix.data; p < matrix.data + matrix.rows * matrix.cols; ++p) {
size_t offset = ((p - matrix.data) / sizeof(float));
fprintf(io, "%#f9.3");
if(offset % matrix.cols >= matrix.cols - 1)
fprintf(io, "\n");
}
}
void
cry_doublematrix_print(FILE* io, struct CryDoubleMatrix matrix)
{
double* p = 0;
for(p = matrix.data; p < matrix.data + matrix.rows * matrix.cols; ++p) {
size_t offset = ((p - matrix.data) / sizeof(double));
fprintf(io, "%#lf9.3");
if(offset % matrix.cols >= matrix.cols - 1)
fprintf(io, "\n");
}
}
/*
CrySingleMatrix
cry_singlematrix_identity_new(unsigned int dim)
{
double* p = 0;
double* data = cry_calloc(float, dim * dim);
CrySingleMatrix matrix = { .data = data, .rows = dim, .cols = dim };
for(p = data; p < data + dim * dim;
}
CryDoubleMatrix
cry_doublematrix_identity_new(unsigned int dim)
{
}
*/
/*
CrySingleMatrix
cry_singlematrix_from_io(FILE* io)
{
}
CryDoubleMatrix
cry_doublematrix_from_io(FILE* io)
{
}
void
cry_singlematrix_free(CrySingleMatrix matrix)
{
}
void
cry_doublematrix_free(CryDoubleMatrix matrix)
{
}
*/
/*
* Copyright (c) 2012 Christoph Mueller <ruunhb@googlemail.com>
*
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYSTAL_MACHINELEARNING_MATRIX_H
#define CRYSTAL_MACHINELEARNING_MATRIX_H
#include "standard.h"
struct CrySingleMatrix {
float* data;
unsigned int rows;
unsigned int cols;
};
struct CryDoubleMatrix {
double* data;
unsigned int rows;
unsigned int cols;
};
crydefine__tuple(struct CrySingleMatrix, tuple_singlematrix);
crydefine__tuple(struct CryDoubleMatrix, tuple_doublematrix);
struct CrySingleMatrix cry_singlematrix_new(unsigned int rows, unsigned int cols, float value);
struct CryDoubleMatrix cry_doublematrix_new(unsigned int rows, unsigned int cols, double value);
void cry_singlematrix_print(FILE* io, struct CrySingleMatrix matrix);
void cry_doublematrix_print(FILE* io, struct CryDoubleMatrix matrix);
/*
CrySingleMatrix cry_singlematrix_identity_new(unsigned int dim);
CryDoubleMatrix cry_doublematrix_identity_new(unsigned int dim);
CrySingleMatrix cry_singlematrix_from_io(FILE* io);
CryDoubleMatrix cry_doublematrix_from_io(FILE* io);
cry_singlematrix_free(CrySingleMatrix matrix);
void cry_doublematrix_free(CryDoubleMatrix matrix);
*/
#endif // CRYSTAL_MACHINELEARNING_MATRIX_H
......@@ -36,6 +36,11 @@ struct CryArray;
* \return the reference pointer to the constructed array, used by other array calls.
*/
struct CryArray* cry_array_new(size_t initialsize, size_t extend);
/**
* Release all allocated memory for a created Array.
* \param array using array that should be freed
*/
void cry_array_free(struct CryArray* array);
size_t cry_array_size(struct CryArray* array);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment