Bonjour,

Matlab 2014a, GCC 4.8.2, Ubuntu 14.04

voici un source C++ minimal qui reproduit le plantage de Matlab. Je sauve ce programme sous le nom de copie.cpp. Il se contente de créer en sortie un tableau de même taille et de même contenu que le tableau d'entrée.

Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <math.h>
#include <typeinfo>
#include <limits>
 
#define FALSE 0
#define TRUE 1
#ifndef NULL
#define NULL 0
#endif
#define VERSION "geomorpho, oct 2014"
 
#include "mex.h"
 
/// matlab main function
void mexFunction(int n_outputs, mxArray *p_outputs[], int n_inputs, const mxArray *p_inputs[]) ;
 
/// template version
template<typename IN> void mexFunction1(short n_outputs, mxArray *p_outputs[], short n_inputs, const mxArray *p_inputs[]) ;
 
/// get the MxClassID from the template type
template <typename T> mxClassID mxclassid() ;
 
/// matlab
void mexFunction(int n_outputs, mxArray *p_outputs[], int n_inputs, const mxArray *p_inputs[])
{
/// check for argument consistency
    if (n_inputs<1)  return ;
 
/// appelle une version de mexFunction castée selon les données d'entrée
    switch (mxGetClassID(p_inputs[0]))
    {
    case mxINT8_CLASS:
        mexFunction1<signed char>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxUINT8_CLASS:
        mexFunction1<unsigned char>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxINT16_CLASS:
        mexFunction1<short>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxUINT16_CLASS:
        mexFunction1<unsigned short>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxINT32_CLASS:
        mexFunction1<long>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxUINT32_CLASS:
        mexFunction1<unsigned long>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxINT64_CLASS:
        mexFunction1<long long>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxUINT64_CLASS:
        mexFunction1<unsigned long long>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxSINGLE_CLASS:
        mexFunction1<float>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    case mxDOUBLE_CLASS:
        mexFunction1<double>(n_outputs, p_outputs, n_inputs, p_inputs) ;
        break;
    default:
        std::cout << "first argument must be a numeric array" << std::endl ;
        break;
    }
}
 
template<typename IN> void mexFunction1(short n_outputs, mxArray *p_outputs[], short n_inputs, const mxArray *p_inputs[])
{
 
    /// determine data type of the first parameters
    mxClassID datatype_M = mxGetClassID(p_inputs[0]);
 
    /// determine input matrix size
    short nrows = (short)mxGetM(p_inputs[0]);
    short ncols = (short)mxGetN(p_inputs[0]) ;
 
    /// create output array of the same size and type as input
    p_outputs[0] = mxCreateNumericMatrix(nrows, ncols, mxclassid<IN>(), (mxComplexity)0) ;
 
    /// get the poiter to the actual data
    IN* data_out = (IN*)mxGetData(p_outputs[0]) ;
    IN* data_in = (IN*)mxGetData(p_inputs[0]) ;
    for (int k=0 ; k!= nrows*ncols ; ++k) data_out[k]=data_in[k] ;
 
}
 
 
template <typename T> mxClassID mxclassid()
{
    mxClassID c ;
    if (typeid(T)==typeid(char)) c = mxCHAR_CLASS ;
    else if (typeid(T)==typeid(double)) c = mxDOUBLE_CLASS ;
    else if (typeid(T)==typeid(float)) c = mxSINGLE_CLASS ;
    else if (typeid(T)==typeid(char)) c = mxINT8_CLASS;
    else if (typeid(T)==typeid(unsigned char)) c = mxUINT8_CLASS;
    else if (typeid(T)==typeid(short)) c = mxINT16_CLASS;
    else if (typeid(T)==typeid(unsigned short)) c = mxUINT16_CLASS;
    else if (typeid(T)==typeid(long)) c = mxINT32_CLASS;
    else if (typeid(T)==typeid(unsigned long)) c = mxUINT32_CLASS;
    else if (typeid(T)==typeid(long long)) c = mxINT64_CLASS;
    else if (typeid(T)==typeid(unsigned long long)) c = mxUINT64_CLASS;
    else c = mxUNKNOWN_CLASS ;
    return c ;
}

dans matlab, voici le script qui fait exploser la boutique : out of memory ou carrément plantage de matlab.
Ce qui me chiffonne c'est que le problème n'apparair que pour les types de données int8 et int32. Pour le reste ça roule;
Une explication ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
mex copie.cpp
clear all
C = copie (ones(300,20)) ; 
% A = int8(ones(300, 20)) ; C = copie(A) ; % out od memory
A = single(ones(300, 20)) ; C = copie(A) ; 
A = uint16(ones(300, 20)) ; C = copie(A) ; 
A = uint8(ones(300, 20)) ; C = copie(A) ; 
A = uint64(ones(300, 20)) ; C = copie(A) ; 
A = int16(ones(300, 20)) ; C = copie(A) ; 
A = int64(ones(300, 20)) ; C = copie(A) ; 
 
% A = uint32(ones(300, 20)) ; C = copie(A) ; % Crash Boum !
% A = int32(ones(300, 20)) ; C = copie(A) ; % Crash Boum !