<commit_before>// library imports
use std::mem;
use std::ptr;
use std::ops;
use std::cmp;
use std::fmt;
use std::num;
use std::num::{One, Zero};
use std::iter::Iterator;
use std::rt::heap::{allocate, deallocate};
use std::raw::Slice as RawSlice;


// srmat imports

use discrete::{mod_n};
use matrix::element::{MatrixElt};
use matrix::error::*;
use matrix::iter::*;
use matrix::view::MatrixView;


// The following is needed for destroying matrix.




#[doc = "
Represents a matrix of numbers.


The numbers are stored in column-major order.
This is the standard in Fortran and MATLAB.


Currently, the stride is same as the number
of rows. May be changed later on.

For a row vector, the stride  = 1.

"]
pub struct Matrix<T:MatrixElt> {
    /// Number of rows in the matrix
    rows : uint,
    /// Number of columns in the matrix
    cols : uint, 
    /// Number of allocated rows 
    xrows : uint, 
    /// Number of allocated columns
    xcols : uint,
    /// The pointer to raw data array of the matrix
    ptr : *mut T
}

/// A matrix of 8-bit signed integers
pub type MatrixI8 = Matrix<i8>;
/// A matrix of 16-bit signed integers
pub type MatrixI16 = Matrix<i16>;
/// A matrix of 32-bit signed integers
pub type MatrixI32 = Matrix<i32>;
/// A matrix of 64-bit signed integers
pub type MatrixI64 = Matrix<i64>;
/// A matrix of 8-bit unsigned integers
pub type MatrixU8 = Matrix<u8>;
/// A matrix of 16-bit unsigned integers
pub type MatrixU16 = Matrix<u16>;
/// A matrix of 32-bit unsigned integers
pub type MatrixU32 = Matrix<u32>;
/// A matrix of 64-bit unsigned integers
pub type MatrixU64 = Matrix<u64>;
/// A matrix of 64-bit floating point numbers.
pub type MatrixF64 = Matrix<f64>;




/// Static functions for creating  a matrix
impl<T:MatrixElt> Matrix<T> {

    /// Constructs a scalar matrix
    pub fn from_scalar (scalar : T) -> Matrix <T>{
        let m : Matrix<T> = Matrix::new(1, 1);
        unsafe {*m.ptr = scalar;}
        m
    }

    pub fn new(rows: uint, cols : uint)-> Matrix<T> {
        debug_assert! (mem::size_of::<T>() != 0);
        let xrows = num::next_power_of_two(rows);
        let xcols = num::next_power_of_two(cols);
        let capacity = xrows *  xcols;

        // Support for empty  matrices
        if capacity == 0{
            // We do not allocate any memory for the buffer.<commit_msg>MatrixF32 type defined and added.<commit_after>// library imports
use std::mem;
use std::ptr;
use std::ops;
use std::cmp;
use std::fmt;
use std::num;
use std::num::{One, Zero};
use std::iter::Iterator;
use std::rt::heap::{allocate, deallocate};
use std::raw::Slice as RawSlice;


// srmat imports

use discrete::{mod_n};
use matrix::element::{MatrixElt};
use matrix::error::*;
use matrix::iter::*;
use matrix::view::MatrixView;


// The following is needed for destroying matrix.




#[doc = "
Represents a matrix of numbers.


The numbers are stored in column-major order.
This is the standard in Fortran and MATLAB.


Currently, the stride is same as the number
of rows. May be changed later on.

For a row vector, the stride  = 1.

"]
pub struct Matrix<T:MatrixElt> {
    /// Number of rows in the matrix
    rows : uint,
    /// Number of columns in the matrix
    cols : uint, 
    /// Number of allocated rows 
    xrows : uint, 
    /// Number of allocated columns
    xcols : uint,
    /// The pointer to raw data array of the matrix
    ptr : *mut T
}

/// A matrix of 8-bit signed integers
pub type MatrixI8 = Matrix<i8>;
/// A matrix of 16-bit signed integers
pub type MatrixI16 = Matrix<i16>;
/// A matrix of 32-bit signed integers
pub type MatrixI32 = Matrix<i32>;
/// A matrix of 64-bit signed integers
pub type MatrixI64 = Matrix<i64>;
/// A matrix of 8-bit unsigned integers
pub type MatrixU8 = Matrix<u8>;
/// A matrix of 16-bit unsigned integers
pub type MatrixU16 = Matrix<u16>;
/// A matrix of 32-bit unsigned integers
pub type MatrixU32 = Matrix<u32>;
/// A matrix of 64-bit unsigned integers
pub type MatrixU64 = Matrix<u64>;
/// A matrix of 32-bit floating point numbers.
pub type MatrixF32 = Matrix<f32>;
/// A matrix of 64-bit floating point numbers.
pub type MatrixF64 = Matrix<f64>;




/// Static functions for creating  a matrix
impl<T:MatrixElt> Matrix<T> {

    /// Constructs a scalar matrix
    pub fn from_scalar (scalar : T) -> Matrix <T>{
        let m : Matrix<T> = Matrix::new(1, 1);
        unsafe {*m.ptr = scalar;}
        m
    }

    pub fn new(rows: uint, cols : uint)-> Matrix<T> {
        debug_assert! (mem::size_of::<T>() != 0);
        let xrows = num::next_power_of_two(rows);
        let xcols = num::next_power_of_two(cols);
        let capacity = xrows *  xcols;

        // Support for empty  matrices
        if capacity == 0{
            // We do not allocate any memory for the buffer.
{'fraction_non_alphanumeric': 0.12251724858875183, 'fraction_numerical': 0.02383441354798244, 'mean_word_length': 2.966832504145937, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '312794', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1471, 'n_words': 588}